Configuring the Hive Metastore

The Hive metastore service stores the metadata for Hive tables and partitions in a relational database, and provides clients (including Hive) access to this information using the
metastore service API. This page explains the deployment options and provides instructions for setting up a database in a recommended configuration.

Metastore Deployment Modes

Note:HiveServer in the discussion that follows refers to HiveServer1 or HiveServer2, whichever you are
using.

Embedded Mode

Cloudera recommends using this mode for experimental purposes only.

This is the default metastore deployment mode for CDH. In this mode the metastore uses a Derby database, and both the database and the metastore service run embedded in the main
HiveServer process. Both are started for you when you start the HiveServer process. This mode requires the least amount of effort to configure, but it can support only one active user at a time and
is not certified for production use.

Local Mode

In this mode the Hive metastore service runs in the same process as the main HiveServer process, but the metastore database runs in a separate process, and can be on a separate host. The
embedded metastore service communicates with the metastore database over JDBC.

Remote Mode

Cloudera recommends that you use this mode.

In this mode the Hive metastore service runs in its own JVM process; HiveServer2, HCatalog, Cloudera Impala™, and other processes communicate with it using the Thrift network API
(configured using the hive.metastore.uris property). The metastore service communicates with the metastore database over JDBC (configured using the javax.jdo.option.ConnectionURL property). The database, the HiveServer process, and the metastore service can all be on the same host, but running the HiveServer process on a
separate host provides better availability and scalability.

The main advantage of Remote mode over Local mode is that Remote mode does not require the administrator to share JDBC login information for the metastore database with each Hive user.
HCatalogrequires this mode.

Supported Metastore Databases

See Requirements and Supported Versions for
up-to-date information on supported databases. Cloudera strongly encourages you to use MySQL because it is the most popular with the rest of the Hive user community, and so receives more testing than
the other options.

Metastore Memory Requirements

The memory requirements for the Metastore depend upon the number of nodes in your cluster. The following requirements represent the minimum requirement, and may be increased to suit
your environment.

For clusters of 100 nodes or larger, 24 GB of heap is required.

For clusters of 50 nodes to 99 nodes, 12 GB of heap is required.

For a multi-node cluster with fewer than 50 nodes, 2GB of heap is required.

For a single-node node cluster, 256 MB of heap is required.

Configuring the Metastore Database

This section describes how to configure Hive to use a remote database, with examples for MySQL and
PostgreSQL.

Note: For information about additional configuration that may be needed in a secure cluster, see Hive Authentication.

Configuring a Remote MySQL Database for the Hive Metastore

Cloudera recommends you configure a database for the metastore on one or more remote servers (that is, on a host or hosts separate from the HiveServer1 or HiveServer2 process). MySQL
is the most popular database to use. Proceed as follows.

Install and start MySQL if you have not already done so

To install MySQL on a Red Hat system:

$ sudo yum install mysql-server

To install MySQL on a SLES system:

$ sudo zypper install mysql
$ sudo zypper install libmysqlclient_r15

To install MySQL on a Debian/Ubuntu system:

$ sudo apt-get install mysql-server

After using the command to install MySQL, you may need to respond to prompts to confirm that you do want to complete the installation. After installation completes, start the mysql daemon.

On Red Hat systems

$ sudo service mysqld start

On SLES and Debian/Ubuntu systems

$ sudo service mysql start

Configure the MySQL service and connector

Before you can run the Hive metastore with a remote MySQL database, you must configure a connector to the remote MySQL database, set up the initial database schema, and configure the
MySQL user account for the Hive user.

To install the MySQL connector on a RHEL 6 system:

On the Hive Metastore server host, install mysql-connector-java and symbolically link the file into the /usr/lib/hive/lib/
directory.

Download the MySQL JDBC driver from http://www.mysql.com/downloads/connector/j/5.1.html.
You will need to sign up for an account if you do not already have one, and log in, before you can download it. Then copy it to the /usr/lib/hive/lib/ directory. For
example:

Note: At the time of publication, version was 5.1.31, but the version may have
changed by the time you read this. If you are using MySQL version 5.6, you must use version 5.1.26 or higher of the driver.

To install the MySQL connector on a SLES system:

On the Hive Metastore server host, install mysql-connector-java and symbolically link the file into the /usr/lib/hive/lib/
directory.

Configure MySQL to use a strong password and to start at boot. Note that in the following procedure, your current root password is blank. Press the Enter
key when you're prompted for the root password.

The instructions in this section assume you are using Remote mode, and that the MySQL database is
installed on a separate host from the metastore service, which is running on a host named metastorehost in the example.

Note:

If the metastore service will run on the host where the database is installed, replace 'metastorehost' in the CREATE USER
example with 'localhost'. Similarly, the value of javax.jdo.option.ConnectionURL in /etc/hive/conf/hive-site.xml (discussed in the next step) must be jdbc:mysql://localhost/metastore. For more information on adding MySQL users, see http://dev.mysql.com/doc/refman/5.5/en/adding-users.html.

Create the initial database schema. Cloudera recommends using the Hive schema tool
to do this.

If for some reason you decide not to use the schema tool, you can use the hive-schema-0.12.0.mysql.sql file instead; that file is located in the
/usr/lib/hive/scripts/metastore/upgrade/mysql directory. Proceed as follows if you decide to use hive-schema-0.12.0.mysql.sql.

You also need a MySQL user account for Hive to use to access the metastore. It is very important to prevent this user account from creating or altering tables in the metastore database
schema.

Important: To prevent users from inadvertently corrupting the metastore schema when they use lower or higher versions of Hive, set the
hive.metastore.schema.verification property to true in /usr/lib/hive/conf/hive-site.xml on the metastore host.

Configure the metastore service to communicate with the MySQL database

This step shows the configuration properties you need to set in hive-site.xml (/usr/lib/hive/conf/hive-site.xml) to
configure the metastore service to communicate with the MySQL database, and provides sample settings. Though you can use the same hive-site.xml on all hosts (client,
metastore, HiveServer), hive.metastore.uris is the only property that must be configured on all of them; the others are used only on the
metastore host.

Given a MySQL database running on myhost and the user account hive with the password mypassword, set the configuration as follows (overwriting any existing values).

Note:

The hive.metastore.local property is no longer supported as of Hive 0.10; setting hive.metastore.uris is sufficient to
indicate that you are using a remote metastore.

Configuring a Remote PostgreSQL Database for the Hive Metastore

Before you can run the Hive metastore with a remote PostgreSQL database, you must configure a connector to the remote PostgreSQL database, set up the initial database schema, and
configure the PostgreSQL user account for the Hive user.

Install and start PostgreSQL if you have not already done so

To install PostgreSQL on a Red Hat system:

$ sudo yum install postgresql-server

To install PostgreSQL on a SLES system:

$ sudo zypper install postgresql-server

To install PostgreSQL on a Debian/Ubuntu system:

$ sudo apt-get install postgresql

After using the command to install PostgreSQL, you may need to respond to prompts to confirm that you do want to complete the installation. To finish installation on RHEL compatible
systems, you need to initialize the database. Please note that this operation is not needed on Ubuntu and SLES systems as it's done automatically on first start:

To initialize database files on Red Hat compatible systems

$ sudo service postgresql initdb

To ensure that your PostgreSQL server will be accessible over the network, you need to do some additional configuration.

First you need to edit the postgresql.conf file. Set the listen_addresses property to *, to
make sure that the PostgreSQL server starts listening on all your network interfaces. Also make sure that the standard_conforming_strings property is set to
off.

You also need to configure authentication for your network in pg_hba.conf. You need to make sure that the PostgreSQL user that you will create later in
this procedure will have access to the server from a remote host. To do this, add a new line into pg_hba.con that has the following information:

host <database> <user> <network address> <mask> md5

The following example allows all users to connect from all hosts to all your databases:

host all all 0.0.0.0 0.0.0.0 md5

Note:

This configuration is applicable only for a network listener. Using this configuration won't open all your databases to the entire world; the user must still supply a password to
authenticate himself, and privilege restrictions configured in PostgreSQL will still be applied.

After completing the installation and configuration, you can start the database server:

Start PostgreSQL Server

$ sudo service postgresql start

Use chkconfig utility to ensure that your PostgreSQL server will start at a boot time. For example:

chkconfig postgresql on

You can use the chkconfig utility to verify that PostgreSQL server will be started at boot time, for example:

chkconfig --list postgresql

Install the PostgreSQL JDBC driver

Before you can run the Hive metastore with a remote PostgreSQL database, you must configure a JDBC driver to the remote PostgreSQL database, set up the initial database schema, and
configure the PostgreSQL user account for the Hive user.

To install the PostgreSQL JDBC Driver on a Red Hat 6 system:

On the Hive Metastore server host, install postgresql-jdbc package and create symbolic link to the /usr/lib/hive/lib/
directory. For example:

Now you need to grant permission for all metastore tables to user hiveuser. PostgreSQL does not have statements to grant the permissions for all tables
at once; you'll need to grant the permissions one table at a time. You could automate the task with the following SQL script:
Note:

If you are running these commands interactively and are still in the Postgres session initiated at the beginning of this step, you do not need to repeat sudo -u
postgres psql.

You can verify the connection from the machine where you'll be running the metastore service as follows:

psql -h myhost -U hiveuser -d metastore
metastore=#

Configure the metastore service to communicate with the PostgreSQL database

This step shows the configuration properties you need to set in hive-site.xml (/usr/lib/hive/conf/hive-site.xml) to
configure the metastore service to communicate with the PostgreSQL database. Though you can use the same hive-site.xml on all hosts (client, metastore, HiveServer),
hive.metastore.uris is the only property that must be configured on all of them; the others are used only on the metastore host.

Given a PostgreSQL database running on host myhost under the user account hive with the password mypassword, you would set configuration properties as follows.

Note:

The instructions in this section assume you are using Remote mode, and that the PostgreSQL
database is installed on a separate host from the metastore server.

The hive.metastore.local property is no longer supported as of Hive 0.10; setting hive.metastore.uris is sufficient to
indicate that you are using a remote metastore.

Configuring a Remote Oracle Database for the Hive Metastore

Before you can run the Hive metastore with a remote Oracle database, you must configure a connector to the remote Oracle database, set up the initial database schema, and configure the
Oracle user account for the Hive user.

Install and start Oracle

The Oracle database is not part of any Linux distribution and must be purchased, downloaded and installed separately. You can use the Express edition, which can be downloaded free from Oracle website.

Install the Oracle JDBC Driver

You must download the Oracle JDBC Driver from the Oracle website and put the JDBC JAR file into the /usr/lib/hive/lib/ directory. For example, the
version 6 JAR file is named ojdbc6.jar. The driver is available for download here. For information about which Oracle Java versions are supported, see CDH and Cloudera Manager Supported JDK Versions.
Note: These URLs were correct at the time of publication, but the Oracle site is restructured frequently.

$ sudo mv ojdbc<version_number>.jar /usr/lib/hive/lib/

Create the Metastore database and user account

Connect to your Oracle database as an administrator and create the user that will use the Hive metastore.

Connect as the newly created hiveuser user and load the initial schema, as in the following example (use the appropriate script for the current release in
/usr/lib/hive/scripts/metastore/upgrade/oracle/ :

Configure the Metastore Service to Communicate with the Oracle Database

This step shows the configuration properties you need to set in hive-site.xml (/usr/lib/hive/conf/hive-site.xml) to
configure the metastore service to communicate with the Oracle database, and provides sample settings. Though you can use the same hive-site.xml on all hosts (client,
metastore, HiveServer), hive.metastore.uris is the only property that must be configured on all of them; the others are used only on the metastore host.

Example

Given an Oracle database running on myhost and the user account hiveuser with the password mypassword, set the configuration as follows (overwriting any existing values):

If this documentation includes code, including but not limited to, code examples, Cloudera makes this available to you under the terms of the Apache License, Version 2.0, including any required
notices. A copy of the Apache License Version 2.0 can be found here.