Apache Hive Guide
Apache Hive Guide
Apache Hive Guide
Important Notice
© 2010-2018 Cloudera, Inc. All rights reserved.
Cloudera, the Cloudera logo, and any other product or service names or slogans contained
in this document are trademarks of Cloudera and its suppliers or licensors, and may not
be copied, imitated or used, in whole or in part, without the prior written permission
of Cloudera or the applicable trademark holder.
Hadoop and the Hadoop elephant logo are trademarks of the Apache Software
Foundation. All other trademarks, registered trademarks, product names and company
names or logos mentioned in this document are the property of their respective owners.
Reference to any products, services, processes or other information, by trade name,
trademark, manufacturer, supplier or otherwise does not constitute or imply
endorsement, sponsorship or recommendation thereof by us.
Complying with all applicable copyright laws is the responsibility of the user. Without
limiting the rights under copyright, no part of this document may be reproduced, stored
in or introduced into a retrieval system, or transmitted in any form or by any means
(electronic, mechanical, photocopying, recording, or otherwise), or for any purpose,
without the express written permission of Cloudera.
The information in this document is subject to change without notice. Cloudera shall
not be liable for any damages resulting from technical errors or omissions which may
be present in this document, or from use of this document.
Cloudera, Inc.
395 Page Mill Road
Palo Alto, CA 94306
[email protected]
US: 1-888-789-1488
Intl: 1-650-362-0488
www.cloudera.com
Release Information
Hive Installation.....................................................................................................13
About Hive..........................................................................................................................................................13
HiveServer2..........................................................................................................................................................................13
Upgrading Hive...................................................................................................................................................13
Checklist to Help Ensure Smooth Upgrades.........................................................................................................................13
Upgrading Hive from a Lower Version of CDH 5..................................................................................................................14
Installing Hive.....................................................................................................................................................17
Heap Size and Garbage Collection for Hive Components.....................................................................................................17
Configuration for WebHCat.................................................................................................................................................19
Configuring the Hive Metastore.........................................................................................................................19
Metastore Deployment Modes............................................................................................................................................19
Supported Metastore Databases.........................................................................................................................................21
Metastore Memory Requirements.......................................................................................................................................22
Configuring the Metastore Database..................................................................................................................................22
Configuring HiveServer2....................................................................................................................................32
HiveServer2 Memory Requirements....................................................................................................................................32
Table Lock Manager (Required)...........................................................................................................................................32
hive.zookeeper.client.port.....................................................................................................................................33
JDBC driver...........................................................................................................................................................................33
Authentication.....................................................................................................................................................................33
Running HiveServer2 and HiveServer Concurrently.............................................................................................................33
Starting the Metastore.......................................................................................................................................34
File System Permissions.....................................................................................................................................34
Starting, Stopping, and Using HiveServer2.........................................................................................................35
Using the Beeline CLI............................................................................................................................................................35
Starting HiveServer1 and the Hive Console........................................................................................................36
Using Hive with HBase.......................................................................................................................................36
Using the Hive Schema Tool...............................................................................................................................37
Schema Version Verification................................................................................................................................................37
Using schematool................................................................................................................................................................37
Installing the Hive JDBC Driver on Clients..........................................................................................................39
Setting HADOOP_MAPRED_HOME....................................................................................................................40
Configuring the Metastore to Use HDFS High Availability..................................................................................40
Viewing the Hive Documentation......................................................................................................................40
Managing Hive.......................................................................................................41
Hive Roles...........................................................................................................................................................41
Hive Execution Engines......................................................................................................................................41
Managing Hive Using Cloudera Manager...........................................................................................................42
Running Hive on Spark.......................................................................................................................................43
Configuring Hive on Spark...................................................................................................................................................43
Troubleshooting Hive on Spark............................................................................................................................................43
HiveServer2 Web UI...........................................................................................................................................45
Accessing the HiveServer2 Web UI.......................................................................................................................................45
HiveServer2 Web UI Configuration......................................................................................................................................45
Hive Table Statistics............................................................................................................................................46
Managing User-Defined Functions (UDFs) with HiveServer2.............................................................................46
User-Defined Functions (UDFs) with HiveServer2 Using Cloudera Manager.......................................................................46
User-Defined Functions (UDFs) with HiveServer2 Using the Command Line.......................................................................48
Tuning Hive............................................................................................................50
Heap Size and Garbage Collection for Hive Components...................................................................................50
Memory Recommendations.................................................................................................................................................50
Configuring Heap Size and Garbage Collection...................................................................................................................51
HiveServer2 Performance Tuning and Troubleshooting.....................................................................................52
Symptoms Displayed When HiveServer2 Heap Memory is Full............................................................................................52
HiveServer2 Performance Best Practices.............................................................................................................................55
Tuning Hive on Spark..............................................................................................59
YARN Configuration............................................................................................................................................59
Spark Configuration............................................................................................................................................59
Hive Configuration.............................................................................................................................................61
Pre-warming YARN Containers.............................................................................................................................................62
Hive Replication.....................................................................................................67
Network Latency and Replication.......................................................................................................................67
Host Selection for Hive Replication....................................................................................................................67
Hive Tables and DDL Commands........................................................................................................................67
Performance and Scalability Limitations............................................................................................................68
Configuring Replication of Hive Data.................................................................................................................68
Viewing Replication Schedules...........................................................................................................................71
Enabling, Disabling, or Deleting A Replication Schedule......................................................................................................73
Viewing Replication History...............................................................................................................................73
Hive Authentication...............................................................................................76
HiveServer2 Security Configuration...................................................................................................................76
Enabling Kerberos Authentication for HiveServer2..............................................................................................................76
Using LDAP Username/Password Authentication with HiveServer2....................................................................................77
Configuring LDAPS Authentication with HiveServer2..........................................................................................................79
Pluggable Authentication....................................................................................................................................................79
Trusted Delegation with HiveServer2...................................................................................................................................80
HiveServer2 Impersonation..................................................................................................................................................80
Securing the Hive Metastore................................................................................................................................................81
Disabling the Hive Security Configuration...........................................................................................................................81
Hive Metastore Server Security Configuration...................................................................................................82
Using Hive to Run Queries on a Secure HBase Server........................................................................................83
Troubleshooting Hive.............................................................................................93
HiveServer2 Performance Tuning and Troubleshooting.....................................................................................93
Symptoms Displayed When HiveServer2 Heap Memory is Full............................................................................................93
HiveServer2 Performance Best Practices.............................................................................................................................96
Using Apache Hive with CDH
Installation
On a cluster managed by Cloudera Manager, Hive comes along with the base CDH installation and does not need to
be installed separately. With Cloudera Manager, you can enable or disable the Hive service, but the Hive component
always remains present on the cluster.
On an unmanaged cluster, you can install Hive manually, using packages or tarballs with the appropriate command for
your operating system.
Install the appropriate Hive packages using the appropriate command for your distribution.
OS Command
RHEL-compatible $ sudo yum install <pkg1> <pkg2> ...
See Installing Hive on page 17 for details about installing and configuring Hive components.
To access the Hive server with JDBC clients, such as Beeline, install the JDBC driver for HiveServer2 that is defined in
org.apache.hive.jdbc.HiveDriver.
See Installing the Hive JDBC Driver on Clients on page 39 for details about installing the JDBC drivers and the connection
URLs to use to connect to HiveServer2 from Hive clients.
Upgrading
Upgrade Hive on all the hosts on which it is running including both servers and clients.
See Upgrading Hive on page 13 for details about deprecated versions, upgrading best practices, and information about
upgrading the Hive metastore schema.
Configuration
Hive offers a number of configuration settings related to performance, file layout and handling, and options to control
SQL semantics. Depending on your cluster size and workloads, configure HiveServer2 memory, table locking behavior,
and authentication for connections. See Configuring HiveServer2 on page 32 for details about required configuration
changes that you must perform.
The Hive metastore service, which stores the metadata for Hive tables and partitions, must also be configured. See
Configuring the Hive Metastore on page 19 for details about deployment modes, information about supported
metastore databases, and specific configurations for MySQL, PostgreSQL, and Oracle.
The metastore database is shared by other components. For example, the same tables can be inserted into, queried,
altered, and so on by both Hive and Impala. Although you might see references to the “Hive metastore”, be aware
that the metastore database is used broadly across the Hadoop ecosystem, even in cases where you are not using Hive
itself.
The metastore database is relatively compact, with fast-changing data. Backup, replication, and other kinds of
management operations affect this database. See Configuring the Hive Metastore on page 19 for details about
configuring the Hive metastore.
Cloudera recommends that you deploy the Hive metastore, which stores the metadata for Hive tables and partitions,
in “remote mode.” In this mode the metastore service runs in its own JVM process and other services, such as
HiveServer2, HCatalog, and Apache Impala communicate with the metastore using the Thrift network API.
See Starting the Metastore on page 34 for details about starting the Hive metastore service.
HiveServer2
HiveServer2 is a server interface that enables remote clients to submit queries to Hive and retrieve the results. It
replaces HiveServer1, which has been deprecated and will be removed in a future release of CDH. HiveServer2 supports
multi-client concurrency, capacity planning controls, Sentry authorization, Kerberos authentication, LDAP, SSL, and
provides better support for JDBC and ODBC clients.
HiveServer2 is a container for the Hive execution engine. For each client connection, it creates a new execution context
that serves Hive SQL requests from the client. It supports JDBC clients, such as the Beeline CLI, and ODBC clients. Clients
connect to HiveServer2 through the Thrift API-based Hive service.
See Configuring HiveServer2 on page 32 for details on configuring HiveServer2 and see Starting, Stopping, and Using
HiveServer2 on page 35 for details on starting/stopping the HiveServer2 service and information about using the
Beeline CLI to connect to HiveServer2. For details about managing HiveServer2 with its native web user interface (UI),
see HiveServer2 Web UI on page 45.
Hive on Spark
Hive traditionally uses MapReduce behind the scenes to parallelize the work, and perform the low-level steps of
processing a SQL statement such as sorting and filtering. Hive can also use Spark as the underlying computation and
parallelization engine. See Running Hive on Spark on page 43 for details about configuring Hive to use Spark as its
execution engine and see Tuning Hive on Spark on page 59 for details about tuning Hive on Spark.
Managing Hive
Cloudera recommends using Cloudera Manager to manage Hive services, which are called managed deployments. If
yours is not a managed deployment, configure HiveServer2 Web UI to manage Hive services.
Important:
The configuration property serialization.null.format is set in Hive and Impala engines as
SerDes or table properties to specify how to serialize/deserialize NULL values into a storage format.
This configuration option is suitable for text file formats only. If used with binary storage formats such
as RCFile or Parquet, the option causes compatibility, complexity and efficiency issues.
Tuning
Tuning Hive consists of configuring numerous Hive parameters for better performance and scalability. The most
important among these settings is configuring sufficient memory for HiveServer2 and the Hive metastore. This includes
allocating memory for heap size based upon the number of concurrent connections that are typical for your deployment.
Configuring garbage collection limits and keeping the number of table partitions below recommended limits are also
important when tuning Hive performance. See Tuning Hive on page 50 for details about recommended limits and best
practices. If you are using Spark as your execution engine, see Tuning Hive on Spark on page 59.
High Availability
Enable high availability for Hive by configuring a load balancer to manage HiveServer2 and by enabling high availability
for the Hive metastore.
To enable high availability for multiple HiveServer2 hosts, configure a load balancer to manage them. To increase
stability and security, configure the load balancer on a proxy server.
See HiveServer2 High Availability on page 66 for details about configuring a load balancer for HiveServer2.
You can enable Hive metastore high availability (HA) so that your cluster is resilient to failures if a metastore becomes
unavailable. When HA mode is enabled, one of the metastores is designated as the master and the others are slaves.
If a master metastore fails, one of the slave metastores takes over.
See Hive Metastore High Availability on page 63 for details about enabling the metastore for high availability.
Replication
Hive replication enables you to copy (replicate) your Hive metastore and data from one cluster to another and
synchronize the Hive metastore and data set on the destination cluster with the source, based on a specified replication
schedule. The destination cluster must be managed by the Cloudera Manager Server where the replication is being
set up, and the source cluster can be managed by that same server or by a peer Cloudera Manager Server.
See Hive Replication on page 67 for details about using Cloudera Manager to set up data replication for Hive.
Security
Securing Hive involves configuring or enabling:
• Authentication for Hive Metastore, HiveServer2, and all Hive clients with your deployment of LDAP and Kerberos
for your cluster.
See Hive Authentication on page 76, HiveServer2 Security Configuration on page 76, Hive Metastore Server
Security Configuration on page 82, and Using Hive to Run Queries on a Secure HBase Server on page 83 for details.
• Authorization for HiveServer2 using role-based, fine-grained authorization that is implemented with Apache
Sentry policies. You must configure HiveServer2 authentication before you configure authorization because Apache
Sentry depends on an underlying authentication framework to reliably identify the requesting user.
See Sentry Policy File Authorization, User to Group Mapping, and Authorization Privilege Model for Hive and
Impala for details. Configure Sentry permissions using GRANT and REVOKE statements using the HiveServer2 client,
the Beeline CLI. See Hive SQL Syntax for Use with Sentry on page 87 for details.
Important: Cloudera does not support Apache Ranger or Hive's native authorization frameworks
for configuring access control in Hive. Use the Cloudera-supported Apache Sentry instead.
• Encryption to secure the network connection between HiveServer2 and Hive clients.
Starting with CDH 5.5, encryption for HiveServer2 clients has been decoupled from the authentication mechanism.
This means you can use either SASL QOP or TLS/SSL to encrypt traffic between HiveServer2 and its clients,
irrespective of whether Kerberos is being used for authentication. Previously, the JDBC client drivers only supported
SASL QOP encryption on Kerberos-authenticated connections.
SASL QOP encryption is better suited for encrypting RPC communication and may result in performance issues
when dealing with large amounts of data. Move to using TLS/SSL encryption to avoid such issues.
This topic describes how to set up encrypted communication between HiveServer2 and its JDBC/ODBC client
drivers.
See Configuring Encrypted Communication Between HiveServer2 and Client Drivers on page 84 for details.
Troubleshooting
See Troubleshooting Hive on page 93 for partitioning recommendations and troubleshooting failed Hive queries.
Using the native web interface for HiveServer2 provides access to Hive configuration settings, local logs, metrics, and
information about sessions and queries. See HiveServer2 Web UI on page 45 for details about accessing, configuring,
and using HiveServer2 Web UI.
For additional Hive documentation, see the Apache Hive wiki.
Hive Installation
Using Hive data in HBase is a common task. See Importing Data Into HBase.
For information about Hive on Spark, see Running Hive on Spark on page 43.
Use the following sections to install, update, and configure Hive.
About Hive
Apache Hive is a powerful data warehousing application for Hadoop. It enables you to access your data using HiveQL,
a language similar to SQL.
Install Hive on your client machine(s) from which you submit jobs; you do not need to install it on the nodes in your
Hadoop cluster. As of CDH 5, Hive supports HCatalog which must be installed separately.
HiveServer2
HiveServer2 is an improved version of HiveServer that supports a Thrift API tailored for JDBC and ODBC clients, Kerberos
authentication, and multi-client concurrency. The CLI for HiveServer2 is Beeline.
Warning: Because of concurrency and security issues, HiveServer1 and the Hive CLI are deprecated
in CDH 5 and will be removed in a future release. Cloudera recommends you migrate to Beeline and
HiveServer2 as soon as possible. The Hive CLI is not needed if you are using Beeline with HiveServer2.
Upgrading Hive
Upgrade Hive on all the hosts on which it is running including both servers and clients.
Warning: Because of concurrency and security issues, HiveServer1 and the Hive CLI are deprecated
in CDH 5 and will be removed in a future release. Cloudera recommends you migrate to Beeline and
HiveServer2 as soon as possible. The Hive CLI is not needed if you are using Beeline with HiveServer2.
Note: To see which version of Hive is shipping in CDH 5, check the Version and Packaging Information.
For important information on new and changed components, see the CDH 5 Release Notes.
• Make sure datanucleus.autoCreateSchema is set to false (in all types of database) and
datanucleus.fixedDatastore is set to true (for MySQL and Oracle) in all hive-site.xml files. See the
configuration instructions for more information about setting the properties in hive-site.xml.
• Insulate the metastore database from users by running the metastore service in Remote mode. If you do not
follow this recommendation, make sure you remove DROP, ALTER, and CREATE privileges from the Hive user
configured in hive-site.xml. See Configuring the Hive Metastore on page 19 for complete instructions for
each type of supported database.
Warning:
Make sure you have read and understood all incompatible changes and known issues before you
upgrade Hive.
Important:
• If you are currently running Hive under MRv1, check for the following property and value in
/etc/mapred/conf/mapred-site.xml:
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
Remove this property before you proceed; otherwise Hive queries spawned from MapReduce
jobs will fail with a null pointer exception (NPE).
• If you have installed the hive-hcatalog-server package in the past, you must remove it
before you proceed; otherwise the upgrade will fail.
• If you are upgrading Hive from CDH 5.0.5 to CDH 5.4, 5.3 or 5.2 on Debian 7.0, and a Sentry version
higher than 5.0.4 and lower than 5.1.0 is installed, you must upgrade Sentry before upgrading
Hive; otherwise the upgrade will fail. See Apache Hive Known Issues for more details.
• CDH 5.2 and higher clients cannot communicate with CDH 5.1 and lower servers. This means that
you must upgrade the server before the clients.
Warning:
You must make sure no Hive processes are running. If Hive processes are running during the upgrade,
the new version will not work correctly.
Step 2: Install the new Hive version on all hosts (Hive servers and clients)
SeeInstalling Hive on page 17
Important:
• Cloudera recommends that you make a backup copy of your metastore database before running
the schematool or the upgrade scripts. You might need this backup copy if there are problems
during the upgrade or if you need to downgrade to a previous version.
• You must upgrade the metastore schema to the version corresponding to the new version of
Hive before starting Hive after the upgrade. Failure to do so may result in metastore corruption.
To upgrade the Hive metastore schema, you can use either the Hive schematool or use the schema upgrade scripts
that are provided with the Hive package. Cloudera recommends that you use the schematool.
Using Hive schematool (Recommended):
The Hive distribution includes a command-line tool for Hive metastore schema manipulation called schematool. This
tool can be used to initialize the metastore schema for the current Hive version. It can also upgrade the schema from
an older version to the current one. You must add properties to the hive-site.xml before you can use it. See Using
the Hive Schema Tool on page 37 for information about how to set the tool up and for usage examples. To upgrade
the schema, use the upgradeSchemaFrom option to specify the version of the schema you are currently using. For
example, if you are upgrading a MySQL metastore schema from Hive 0.13.1, use the following syntax:
Note: The upgradeSchemaFrom option requires the Hive version and not the CDH version. See CDH
5 Packaging and Tarball Information for information about which Hive version ships with each CDH
release.
• If you installed CDH with parcels, the scripts are in the following location:
/opt/cloudera/parcels/CDH/lib/hive/scripts/metastore/upgrade/<database_name>
• If you installed CDH with packages, the scripts are in the following location:
/usr/lib/hive/scripts/metastore/upgrade/<database_name>
For example, if your Hive metastore is MySQL and you installed CDH with packages, navigate to
/usr/lib/hive/scripts/metastore/upgrade/mysql.
Run the appropriate schema upgrade scripts in order. Start with the script for your database type and Hive version,
and run all subsequent scripts.
For example, if you are currently running Hive 0.13.1 with MySQL and upgrading to Hive 1.1.0, start with the script for
0.13.0 to 0.14.0 for MySQL, and then run the script for Hive 0.14.0 to 1.1.0.
For more information about using the scripts to upgrade the schema, see the README in the directory with the scripts.
Hive Schema version 0.13.0 does not match metastore's schema version 0.12.0 Metastore
is not upgraded or corrupt.
Hive Schema version 0.13.0 does not match metastore's schema version 0.12.0 Metastore
is not upgraded or corrupt.
Installing Hive
Install the appropriate Hive packages using the appropriate command for your distribution.
OS Command
RHEL-compatible $ sudo yum install <pkg1> <pkg2> ...
Important: After installing Hive, see HiveServer2 Performance Best Practices on page 55 for
information about optimizing your Hive deployment and your Hive workloads for best performance
results.
Memory Recommendations
HiveServer2 and the Hive metastore require sufficient memory to run correctly. The default heap size of 256 MB for
each component is inadequate for production workloads. Consider the following guidelines for sizing the heap for each
component, based on your cluster size.
Number of Concurrent Connections HiveServer2 Heap Size Recommended Hive Metastore Heap Size
Range Recommended Range
Up to 40 concurrent connections 12 - 16 GB 12 - 16 GB
Cloudera recommends splitting
HiveServer2 into multiple instances
and load-balancing once you start
allocating over 16 GB to HiveServer2.
This reduces the impact of Java
garbage collection on active processing
by the service.
Up to 20 concurrent connections 6 - 12 GB 10 - 12 GB
Up to 10 concurrent connections 4 - 6 GB 4 - 10 GB
One connection 4 GB 4 GB
Important: These numbers are general guidance only, and can be affected by factors such as number
of columns, partitions, complex joins, and client activity. Based on your anticipated deployment, refine
through testing to arrive at the best values for your environment.
In addition, the Beeline CLI should use a heap size of at least 2 GB.
Set the PermGen space for Java garbage collection to 512 MB for all.
5. From the Actions drop-down menu, select Restart to restart the HiveServer2 service.
To configure heap size and garbage collection for the Hive metastore:
1. To set heap size, go to Home > Hive > Configuration > Hive Metastore > Resource Management.
2. Set Java Heap Size of Hive Metastore Server in Bytes to the desired value, and click Save Changes.
3. To set garbage collection, go to Home > Hive > Configuration > Hive Metastore Server > Advanced.
4. Set the PermGen space for Java garbage collection to 512M, the type of garbage collector used (ConcMarkSweepGC
or ParNewGC), and enable or disable the garbage collection overhead limit in Java Configuration Options for Hive
Metastore Server. For an example of this setting, see step 4 above for configuring garbage collection for HiveServer2.
5. From the Actions drop-down menu, select Restart to restart the Hive Metastore service.
To configure heap size and garbage collection for the Beeline CLI:
1. To set heap size, go to Home > Hive > Configuration > Gateway > Resource Management.
2. Set Client Java Heap Size in Bytes to at least 2 GiB and click Save Changes.
3. To set garbage collection, go to Home > Hive > Configuration > Gateway > Advanced.
4. Set the PermGen space for Java garbage collection to 512M in Client Java Configuration Options.
The following example sets the PermGen space to 512M and specifies IPv4:
-XX:MaxPermSize=512M -Djava.net.preferIPv4Stack=true
5. From the Actions drop-down menu, select Restart to restart the client service.
Using the Command Line
To configure the heap size for HiveServer2 and Hive metastore, set the -Xmx parameter in the HADOOP_OPTS variable
to the desired maximum heap size in /etc/hive/hive-env.sh.
To configure the heap size for the Beeline CLI, set the HADOOP_HEAPSIZE environment variable in
/etc/hive/hive-env.sh before starting the Beeline CLI.
export HADOOP_HEAPSIZE=2048
You can use either the Concurrent Collector or the new Parallel Collector for garbage collection by passing
-XX:+useConcMarkSweepGC or -XX:+useParNewGC in the HADOOP_OPTS lines above. To enable the garbage
collection overhead limit, remove the -XX:-UseGCOverheadLimit setting or change it to
-XX:+UseGCOverheadLimit.
Set the PermGen space for Java garbage collection to 512M for all in the JAVA-OPTS environment variable. For example:
export PYTHON_CMD=/usr/bin/python
Note: On this page, HiveServer, refers to HiveServer1 or HiveServer2, whichever you are using.
Embedded Mode
Cloudera recommends using this mode for experimental purposes only.
Embedded mode 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 are 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 Local 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 Remote mode, the Hive metastore service runs in its own JVM process. HiveServer2, HCatalog, 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. HCatalog requires this mode.
Up to 20 concurrent connections 6 - 12 GB 10 - 12 GB
Up to 10 concurrent connections 4 - 6 GB 4 - 10 GB
One connection 4 GB 4 GB
Important: These numbers are general guidance only, and can be affected by factors such as number
of columns, partitions, complex joins, and client activity. Based on your anticipated deployment, refine
through testing to arrive at the best values for your environment.
For information on configuring heap for Hive MetaStore, as well as HiveServer2 and Hive clients, see Heap Size and
Garbage Collection for Hive Components on page 17.
Note: For information about additional configuration that may be needed in a secure cluster, see
Hive Authentication on page 76.
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 RHEL systems
$ sudo cp mysql-connector-java-version/mysql-connector-java-version-bin.jar
/usr/lib/hive/lib/
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.
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.
$ sudo /usr/bin/mysql_secure_installation
[...]
Enter current password for root (enter for none):
OK, successfully used password, moving on...
[...]
Set root password? [Y/n] y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
[...]
Disallow root login remotely? [Y/n] N
[...]
Remove test database and access to it [Y/n] Y
[...]
Reload privilege tables now? [Y/n] Y
All done!
• On SLES systems:
• On Debian/Ubuntu systems:
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-n.n.n.mysql.sql
file instead; that file is located in the /usr/lib/hive/scripts/metastore/upgrade/mysql/ directory. (n.n.n
is the current Hive version, for example 1.1.0.) Proceed as follows if you decide to use
hive-schema-n.n.n.mysql.sql.
Note:
Do this only if you are not using the Hive schema tool.
$ mysql -u root -p
Enter password:
mysql> CREATE DATABASE metastore;
mysql> USE metastore;
mysql> SOURCE /usr/lib/hive/scripts/metastore/upgrade/mysql/hive-schema-n.n.n.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.
Example
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.
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://myhost/metastore</value>
<description>the URL of the MySQL database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>mypassword</value>
</property>
<property>
<name>datanucleus.autoCreateSchema</name>
<value>false</value>
</property>
<property>
<name>datanucleus.fixedDatastore</name>
<value>true</value>
</property>
<property>
<name>datanucleus.autoStartMechanism</name>
<value>SchemaTable</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://<n.n.n.n>:9083</value>
<description>IP address (or fully-qualified domain name) and port of the metastore
host</description>
</property>
<property>
<name>hive.metastore.schema.verification</name>
<value>true</value>
</property>
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 RHEL compatible systems
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 can check that you have the correct values as follows:
On Red-Hat-compatible systems:
On SLES systems:
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:
The following example allows all users to connect from all hosts to all your databases:
Note:
This configuration is applicable only for a network listener. Using this configuration does not 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
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:
On the Hive Metastore server host, install postgresql-jdbc package and create symbolic link to the
/usr/lib/hive/lib/ directory. For example:
$ wget http://jdbc.postgresql.org/download/postgresql-9.2-1002.jdbc4.jar
$ mv postgresql-9.2-1002.jdbc4.jar /usr/lib/hive/lib/
Note:
You may need to use a different version if you have a different version of Postgres. You can check
the version as follows:
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:
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.
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:postgresql://myhost/metastore</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>org.postgresql.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hiveuser</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>mypassword</value>
</property>
<property>
<name>datanucleus.autoCreateSchema</name>
<value>false</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://<n.n.n.n>:9083</value>
<description>IP address (or fully-qualified domain name) and port of the metastore
host</description>
</property>
<property>
<name>hive.metastore.schema.verification</name>
<value>true</value>
</property>
Note: These URLs were correct at the time of publication, but the Oracle site is restructured
frequently.
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 (for example hive-schema-1.1.0.oracle.sql) in
/usr/lib/hive/scripts/metastore/upgrade/oracle/ :
$ sqlplus hiveuser
SQL> @/usr/lib/hive/scripts/metastore/upgrade/oracle/hive-schema-n.n.n.oracle.sql
Connect back as an administrator and remove the power privileges from user hiveuser. Then grant limited access
to all the tables:
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:oracle:thin:@//myhost/xe</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>oracle.jdbc.OracleDriver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hiveuser</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>mypassword</value>
</property>
<property>
<name>datanucleus.autoCreateSchema</name>
<value>false</value>
</property>
<property>
<name>datanucleus.fixedDatastore</name>
<value>true</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://<n.n.n.n>:9083</value>
<description>IP address (or fully-qualified domain name) and port of the metastore
host</description>
</property>
<property>
<name>hive.metastore.schema.verification</name>
<value>true</value>
</property>
Configuring HiveServer2
You must make the following configuration changes before using HiveServer2. Failure to do so may result in unpredictable
behavior.
Warning: HiveServer1 is deprecated in CDH 5.3, and will be removed in a future release of CDH. Users
of HiveServer1 should upgrade to HiveServer2 as soon as possible.
Up to 20 concurrent connections 6 - 12 GB 10 - 12 GB
Up to 10 concurrent connections 4 - 6 GB 4 - 10 GB
One connection 4 GB 4 GB
Important: These numbers are general guidance only, and can be affected by factors such as number
of columns, partitions, complex joins, and client activity. Based on your anticipated deployment, refine
through testing to arrive at the best values for your environment.
For information on configuring heap for HiveServer2, as well as Hive metastore and Hive clients, see Heap Size and
Garbage Collection for Hive Components on page 17 and the following video:
After you start the video, click YouTube in the lower right corner of the player window to watch it on YouTube where
you can resize it for clearer viewing.
Figure 1: Troubleshooting HiveServer2 Service Crashes
Important: Failure to do this will prevent HiveServer2 from handling concurrent query requests and
may result in data corruption.
Enable the lock manager by setting properties in /etc/hive/conf/hive-site.xml as follows (substitute your
actual ZooKeeper node names for those in the example):
<property>
<name>hive.support.concurrency</name>
<description>Enable Hive's Table Lock Manager Service</description>
<value>true</value>
</property>
<property>
<name>hive.zookeeper.quorum</name>
<description>Zookeeper quorum used by Hive's Table Lock Manager</description>
<value>zk1.myco.com,zk2.myco.com,zk3.myco.com</value>
</property>
Important: Enabling the Table Lock Manager without specifying a list of valid Zookeeper quorum
nodes will result in unpredictable behavior. Make sure that both properties are properly configured.
(The above settings are also needed if you are still using HiveServer1. HiveServer1 is deprecated; migrate to HiveServer2
as soon as possible.)
hive.zookeeper.client.port
If ZooKeeper is not using the default value for ClientPort, you need to set hive.zookeeper.client.port in
/etc/hive/conf/hive-site.xml to the same value that ZooKeeper is using. Check
/etc/zookeeper/conf/zoo.cfg to find the value for ClientPort. If ClientPort is set to any value other than
2181 (the default), sethive.zookeeper.client.port to the same value. For example, if ClientPort is set to
2222, set hive.zookeeper.client.port to 2222 as well:
<property>
<name>hive.zookeeper.client.port</name>
<value>2222</value>
<description>
The port at which the clients will connect.
</description>
</property>
JDBC driver
The connection URL format and the driver class are different for HiveServer2 and HiveServer1:
Authentication
HiveServer2 can be configured to authenticate all connections; by default, it allows any client to connect. HiveServer2
supports either Kerberos or LDAP authentication; configure this in the hive.server2.authentication property
in the hive-site.xml file. You can also configure Pluggable Authentication on page 79, which allows you to use a
custom authentication provider for HiveServer2; and HiveServer2 Impersonation on page 80, which allows users to
execute queries and access HDFS files as the connected user rather than the super user who started the HiveServer2
daemon. For more information, see Hive Security Configuration.
Warning: Because of concurrency and security issues, HiveServer1 and the Hive CLI are deprecated
in CDH 5 and will be removed in a future release. Cloudera recommends you migrate to Beeline and
HiveServer2 as soon as possible. The Hive CLI is not needed if you are using Beeline with HiveServer2.
HiveServer2 and HiveServer1 can be run concurrently on the same system, sharing the same data sets. This allows you
to run HiveServer1 to support, for example, Perl or Python scripts that use the native HiveServer1 Thrift bindings.
Both HiveServer2 and HiveServer1 bind to port 10000 by default, so at least one of them must be configured to use a
different port. You can set the port for HiveServer2 in hive-site.xml by means of the hive.server2.thrift.port
property. For example:
<property>
<name>hive.server2.thrift.port</name>
<value>10001</value>
<description>TCP port number to listen on, default 10000</description>
</property>
You can also specify the port (and the host IP address in the case of HiveServer2) by setting these environment variables:
Important:
If you are running the metastore in Remote mode, you must start the metastore before starting
HiveServer2.
Important:
Cloudera recommends setting permissions on the Hive warehouse directory to 1777, making it
accessible to all users, with the sticky bit set. This allows users to create and access their tables, but
prevents them from deleting tables they do not own.
In addition, each user submitting queries must have an HDFS home directory. /tmp (on the local file system) must be
world-writable, as Hive makes extensive use of it.
HiveServer2 Impersonation on page 80 allows users to execute queries and access HDFS files as the connected user.
If you do not enable impersonation, HiveServer2 by default executes all Hive tasks as the user ID that starts the Hive
server; for clusters that use Kerberos authentication, this is the ID that maps to the Kerberos principal used with
HiveServer2. Setting permissions to 1777, as recommended above, allows this user access to the Hive warehouse
directory.
You can change this default behavior by setting hive.metastore.execute.setugi to true on both the server and
client. This setting causes the metastore server to use the client's user and group permissions.
Warning:
If you are running the metastore in Remote mode, you must start the Hive metastore before you start
HiveServer2. HiveServer2 tries to communicate with the metastore as part of its initialization bootstrap.
If it is unable to do this, it fails with an error.
To start HiveServer2:
To stop HiveServer2:
To confirm that HiveServer2 is working, start the beeline CLI and use it to execute a SHOW TABLES query on the
HiveServer2 process:
$ /usr/lib/hive/bin/beeline
beeline> !connect jdbc:hive2://localhost:10000 username password
org.apache.hive.jdbc.HiveDriver
0: jdbc:hive2://localhost:10000> SHOW TABLES;
show tables;
+-----------+
| tab_name |
+-----------+
+-----------+
No rows selected (0.238 seconds)
0: jdbc:hive2://localhost:10000>
Note:
Cloudera does not currently support using the Thrift HTTP protocol to connect Beeline to HiveServer2
(meaning that you cannot set hive.server2.transport.mode=http). Use the Thrift TCP protocol.
Use the following commands to start beeline and connect to a running HiveServer2 process. In this example the
HiveServer2 process is running on localhost at port 10000:
$ beeline
beeline> !connect jdbc:hive2://localhost:10000 username password
org.apache.hive.jdbc.HiveDriver
0: jdbc:hive2://localhost:10000>
Note:
If you are using HiveServer2 on a cluster that does not have Kerberos security enabled, then the
password is arbitrary in the command for starting Beeline.
If you are using HiveServer2 on a cluster that does have Kerberos security enabled, see HiveServer2
Security Configuration on page 76.
As of CDH 5.2, there are still some Hive CLI features that are not available with Beeline. For example:
• Beeline does not show query logs like the Hive CLI
• When adding JARs to HiveServer2 with Beeline, the JARs must be on the HiveServer2 host.
At present the best source for documentation on Beeline is the original SQLLine documentation.
To start HiveServer1:
$ hive
hive>
To confirm that Hive is working, issue the show tables; command to list the Hive tables; be sure to use a semi-colon
after the command:
...
Caused by: MetaException(message:Version information not found in metastore. )
at org.apache.hadoop.hive.metastore.ObjectStore.checkSchema(ObjectStore.java:5638)
...
To suppress the schema check and allow the metastore to implicitly modify the schema, you need to set the
hive.metastore.schema.verification configuration property to false in hive-site.xml.
Using schematool
Use the Hive schematool to initialize the metastore schema for the current Hive version or to upgrade the schema
from an older version. The tool tries to find the current schema from the metastore if it is available there.
The schematool determines the SQL scripts that are required to initialize or upgrade the schema and then executes
those scripts against the backend database. The metastore database connection information such as JDBC URL, JDBC
driver and database credentials are extracted from the Hive configuration. You can provide alternate database credentials
if needed.
The following options are available as part of the schematool package.
$ schematool -help
usage: schemaTool
-dbType <databaseType> Metastore database type
-dryRun List SQL scripts (no execute)
The dbType option should always be specified and can be one of the following:
derby|mysql|postgres|oracle
Usage Examples
• Initialize your metastore to the current schema for a new Hive setup using the initSchema option.
• If you attempt to get schema information from older metastores that did not store version information, the tool
will report an error as follows.
• You can upgrade schema from a CDH 4 release by specifying the upgradeSchemaFrom option.
• If you want to find out all the required scripts for a schema upgrade, use the dryRun option.
If you want to install only the JDBC on your Hive clients, proceed as follows.
Note:
The CDH 5.2 Hive JDBC driver is not wire-compatible with the CDH 5.1 version of HiveServer2. Make
sure you upgrade Hive clients and all other Hive hosts in tandem: the server first, and then the clients.
1. Install the package (it is included in CDH packaging). Use one of the following commands, depending on the target
operating system:
• On Red-Hat-compatible systems:
• On SLES systems:
Connection URLs
The HiveServer2 connection URL has the following format:
jdbc:hive2://<host1>:<port1>,<host2>:<port2>/dbName;sess_var_list?hive_conf_list#hive_var_list
where:
• <host1>:<port1>,<host2>:<port2> is a server instance or a comma separated list of server instances to
connect to (if dynamic service discovery is enabled). If no server is mentioned here, the embedded server will be
used.
• dbName is the name of the initial database.
• sess_var_list is a semicolon separated list of key=value pairs of session variables. For example,
user=foo;password=bar.
• hive_conf_list is a semicolon separated list of key=value pairs of Hive configuration variables for this session.
For example, hive.server2.transport.mode=http;hive.server2.thrift.http.path=hs2.
• hive_var_list is a semicolon separated list of key=value pairs of Hive variables for this session.
Connection URLs for Remote or Embedded Mode: For remote or embedded access, the JDBC Driver class is
org.apache.hive.jdbc.HiveDriver.
• For a remote server, the URL format is jdbc:hive2://<host>:<port>/<db>. The default HiveServer2 port is
10000).
• For an embedded server, the URL format is jdbc:hive2:// (no host or port).
Connection URLs in HTTP Mode:
jdbc:hive2://<host>:<port>/<db>?hive.server2.transport.mode=http;hive.server2.thrift.http.path=<http_endpoint>
where <http_endpoint> is the corresponding HTTP endpoint configured in hive-site.xml. The default value for
the endpoint is cliservice. The default port for HTTP transport mode is 10001.
Connection URLs with SSL Enabled:
jdbc:hive2://<host>:<port>/<db>;ssl=true;sslTrustStore=<trust_store_path>;trustStorePassword=<trust_store_password>
where:
• <trust_store_path> is the path where client's truststore file is located.
• <trust_store_password> is the password to access the truststore.
In HTTP mode with SSL enabled, the URL is of the format:
jdbc:hive2://<host>:<port>/<db>;ssl=true;sslTrustStore=<trust_store_path>;trustStorePassword=<trust_store_password>?hive.server2.transport.mode=http;hive.server2.thrift.http.path=<http_endpoint>
Setting HADOOP_MAPRED_HOME
• For each user who will be submitting MapReduce jobs using MapReduce v2 (YARN), or running Pig, Hive, or Sqoop
in a YARN installation, make sure that the HADOOP_MAPRED_HOME environment variable is set correctly, as follows:
$ export HADOOP_MAPRED_HOME=/usr/lib/hadoop-mapreduce
• For each user who will be submitting MapReduce jobs using MapReduce v1 (MRv1), or running Pig, Hive, or Sqoop
in an MRv1 installation, set the HADOOP_MAPRED_HOME environment variable as follows:
$ export HADOOP_MAPRED_HOME=/usr/lib/hadoop-0.20-mapreduce
Managing Hive
Apache Hive is a powerful data warehousing application for Hadoop. It enables you to access your data using HiveQL,
a language similar to SQL.
Hive Roles
Hive is implemented in three roles:
• Hive metastore - Provides metastore services when Hive is configured with a remote metastore.
Cloudera recommends using a remote Hive metastore, especially for CDH 4.2 or higher. Because the remote
metastore is recommended, Cloudera Manager treats the Hive Metastore Server as a required role for all Hive
services. A remote metastore provides the following benefits:
– The Hive metastore database password and JDBC drivers do not need to be shared with every Hive client;
only the Hive Metastore Server does. Sharing passwords with many hosts is a security issue.
– You can control activity on the Hive metastore database. To stop all activity on the database, stop the Hive
Metastore Server. This makes it easy to back up and upgrade, which require all Hive activity to stop.
See Configuring the Hive Metastore (CDH 4) or Configuring the Hive Metastore (CDH 5).
For information about configuring a remote Hive metastore database with Cloudera Manager, see Cloudera
Manager and Managed Service Datastores. To configure high availability for the Hive metastore, see Hive Metastore
High Availability on page 63.
• HiveServer2 - Enables remote clients to run Hive queries, and supports a Thrift API tailored for JDBC and ODBC
clients, Kerberos authentication, and multi-client concurrency. A CLI named Beeline is also included. See HiveServer2
documentation (CDH 4) or HiveServer2 documentation (CDH 5) for more information.
• WebHCat - HCatalog is a table and storage management layer for Hadoop that makes the same table information
available to Hive, Pig, MapReduce, and Sqoop. Table definitions are maintained in the Hive metastore, which
HCatalog requires. WebHCat allows you to access HCatalog using an HTTP (REST style) interface.
set hive.execution.engine=spark;
set hive.execution.engine;
Symptom
The first query after starting a new Hive on Spark session might be delayed due to the start-up time for the Spark on
YARN cluster.
Cause
The query waits for YARN containers to initialize.
Solution
No action required. Subsequent queries will be faster.
Symptom
In the HiveServer2 log you see the following exception: Error:
org.apache.thrift.transport.TTransportException (state=08S01,code=0)
Cause
HiveServer2 memory is set too small. For more information, see stdout for HiveServer2.
Solution
1. Go to the Hive service.
2. Click the Configuration tab.
3. Search for Java Heap Size of HiveServer2 in Bytes, and increase the value. Cloudera recommends a minimum value
of 2 GB.
4. Click Save Changes to commit the changes.
5. Restart HiveServer2.
Out-of-memory error
Symptom
In the log you see an out-of-memory error similar to the following:
Cause
The Spark driver does not have enough off-heap memory.
Solution
Increase the driver memory spark.driver.memory and ensure that spark.yarn.driver.memoryOverhead is
at least 20% that of the driver memory.
Symptom
Cluster resources are consumed by Spark applications.
Cause
This can occur if you run multiple Hive on Spark sessions concurrently.
Solution
Manually terminate the Hive on Spark applications:
1. Go to the YARN service.
2. Click the Applications tab.
3. In the row containing the Hive on Spark application, select > Kill.
HiveServer2 Web UI
The HiveServer2 web UI provides access to Hive configuration settings, local logs, metrics, and information about active
sessions and queries. The HiveServer2 web UI is enabled in newly created clusters running CDH 5.7 and higher, and
those using Kerberos are configured for SPNEGO. Clusters upgraded from a previous CDH version must be configured
to enable the web UI; see HiveServer2 Web UI Configuration on page 45.
Configurable Properties
HiveServer2 web UI properties, with their default values in Cloudera Hadoop, are:
hive.server2.webui.max.threads=50
hive.server2.webui.host=0.0.0.0
hive.server2.webui.port=10002
hive.server2.webui.use.ssl=false
hive.server2.webui.keystore.path=""
hive.server2.webui.keystore.password=""
hive.server2.webui.max.historic.queries=25
hive.server2.webui.use.spnego=false
hive.server2.webui.spnego.keytab=""
hive.server2.webui.spnego.principal=<dynamically sets special string, _HOST, as
hive.server2.webui.host or host name>
Tip: To disable the HiveServer2 web UI, set the port to 0 or a negative number
Note: By default, newly created CDH 5.7 (and higher) clusters have the HiveServer2 web UI enabled,
and if using Kerberos, are configured for SPNEGO. Clusters upgraded from an earlier CDH version must
have the UI enabled with the port property; other default values can be preserved in most cases.
Configure the HiveServer2 web UI properties in Cloudera Manager on the Configuration tab.
1. Go to the Hive service.
2. Click the Configuration tab.
3. Select Scope > HiveServer2.
Perform one of the following procedures depending on whether you want to create permanent or temporary functions.
hive.server2.builtin.udf.blacklist A comma separated list of built-in UDFs that are not allowed to be executed.
A UDF that is included in the list will return an error if invoked from a query.
Default value: Empty
Note: If the Hive Metastore is running on a different host, create the same directory there that
you created on the HiveServer2 host. You do not need to copy the JAR file onto the Hive Metastore
host, but the same directory must be there. For example, if you copied the JAR file to
/opt/local/hive/lib/ on the HiveServer2 host, you must create the same directory on the
Hive Metastore host. If the same directory is not present on the Hive Metastore host, Hive
Metastore service will not start.
12. Run the CREATE FUNCTION command to create the UDF from the JAR file and point to the JAR file location in
HDFS. For example:
Note: If the Hive Metastore is running on a different host, create the same directory there that
you created on the HiveServer2 host. You do not need to copy the JAR file onto the Hive Metastore
host, but the same directory must be there. For example, if you copied the JAR file to
/opt/local/hive/lib/ on the HiveServer2 host, you must create the same directory on the
Hive Metastore host. If the same directory is not present on the Hive Metastore host, Hive
Metastore service will not start.
hive.aux.jars.path=file:///opt/local/hive/lib/my.jar
3. Copy the JAR file (and its dependent libraries) to the host running HiveServer2/Impala. Make sure the hive user
has read, write, and execute access to these files on the HiveServer2/Impala host.
4. On the HiveServer2/Impala host, open /etc/default/hive-server2 and set the AUX_CLASSPATH variable
to a comma-separated list of the fully qualified paths to the JAR file and any dependent libraries.
AUX_CLASSPATH=/opt/local/hive/lib/my.jar
5. Restart HiveServer2.
6. If Sentry is enabled - Grant privileges on the JAR files to the roles that require access. Login to Beeline as user
hive and use the Hive SQL GRANT statement to do so. For example:
If you are using Sentry policy files, you can grant the URI privilege as follows:
udf_r = server=server1->uri=file:///opt/local/hive/lib
udf_r = server=server1->uri=hdfs:///path/to/jar
7. Run the CREATE FUNCTION command and point to the JAR from Hive:
hive.aux.jars.path=file:///opt/local/hive/lib/my.jar
2. Copy the JAR file (and its dependent libraries) to the host running HiveServer2/Impala. Make sure the hive user
has read, write, and execute access to these files on the HiveServer2/Impala host.
3. On the HiveServer2/Impala host, open /etc/default/hive-server2 and set the AUX_CLASSPATH variable
to a comma-separated list of the fully qualified paths to the JAR file and any dependent libraries.
AUX_CLASSPATH=/opt/local/hive/lib/my.jar
4. If Sentry is enabled - Grant privileges on the local JAR files to the roles that require access. Login to Beeline as
user hive and use the Hive SQL GRANT statement to do so. For example:
If you are using Sentry policy files, you can grant the URI privilege as follows:
udf_r = server=server1->uri=file:///opt/local/hive/lib
5. Restart HiveServer2.
6. Run the CREATE TEMPORARY FUNCTION command and point to the JAR from Hive:
Tuning Hive
To maximize performance of your Apache Hive query workloads, you need to optimize cluster configurations, queries,
and underlying Hive table design. This includes the following:
• Configure CDH clusters for the maximum allowed heap memory size, load-balance concurrent connections across
your CDH Hive components, and allocate adequate memory to support HiveServer2 and Hive metastore operations.
• Review your Hive query workloads to make sure queries are not overly complex, that they do not access large
numbers of Hive table partitions, or that they force the system to materialize all columns of accessed Hive tables
when only a subset is necessary.
• Review the underlying Hive table design, which is crucial to maximizing the throughput of Hive query workloads.
Do not create thousands of table partitions that might cause queries containing JOINs to overtax HiveServer2 and
the Hive metastore. Limit column width, and keep the number of columns under 1,000.
The following sections provide details on implementing these best practices to maximize performance for deployments
of HiveServer2 and the Hive metastore.
Memory Recommendations
HiveServer2 and the Hive metastore require sufficient memory to run correctly. The default heap size of 256 MB for
each component is inadequate for production workloads. Consider the following guidelines for sizing the heap for each
component, based on your cluster size.
Number of Concurrent Connections HiveServer2 Heap Size Recommended Hive Metastore Heap Size
Range Recommended Range
Up to 40 concurrent connections 12 - 16 GB 12 - 16 GB
Cloudera recommends splitting
HiveServer2 into multiple instances
and load-balancing once you start
allocating over 16 GB to HiveServer2.
This reduces the impact of Java
garbage collection on active processing
by the service.
Up to 20 concurrent connections 6 - 12 GB 10 - 12 GB
Up to 10 concurrent connections 4 - 6 GB 4 - 10 GB
One connection 4 GB 4 GB
Important: These numbers are general guidance only, and can be affected by factors such as number
of columns, partitions, complex joins, and client activity. Based on your anticipated deployment, refine
through testing to arrive at the best values for your environment.
In addition, the Beeline CLI should use a heap size of at least 2 GB.
Set the PermGen space for Java garbage collection to 512 MB for all.
5. From the Actions drop-down menu, select Restart to restart the HiveServer2 service.
To configure heap size and garbage collection for the Hive metastore:
1. To set heap size, go to Home > Hive > Configuration > Hive Metastore > Resource Management.
2. Set Java Heap Size of Hive Metastore Server in Bytes to the desired value, and click Save Changes.
3. To set garbage collection, go to Home > Hive > Configuration > Hive Metastore Server > Advanced.
4. Set the PermGen space for Java garbage collection to 512M, the type of garbage collector used (ConcMarkSweepGC
or ParNewGC), and enable or disable the garbage collection overhead limit in Java Configuration Options for Hive
Metastore Server. For an example of this setting, see step 4 above for configuring garbage collection for HiveServer2.
5. From the Actions drop-down menu, select Restart to restart the Hive Metastore service.
To configure heap size and garbage collection for the Beeline CLI:
1. To set heap size, go to Home > Hive > Configuration > Gateway > Resource Management.
2. Set Client Java Heap Size in Bytes to at least 2 GiB and click Save Changes.
3. To set garbage collection, go to Home > Hive > Configuration > Gateway > Advanced.
4. Set the PermGen space for Java garbage collection to 512M in Client Java Configuration Options.
The following example sets the PermGen space to 512M and specifies IPv4:
-XX:MaxPermSize=512M -Djava.net.preferIPv4Stack=true
5. From the Actions drop-down menu, select Restart to restart the client service.
The settings to change are in bold. All of these lines are commented out (prefixed with a # character) by default.
export HADOOP_HEAPSIZE=2048
You can use either the Concurrent Collector or the new Parallel Collector for garbage collection by passing
-XX:+useConcMarkSweepGC or -XX:+useParNewGC in the HADOOP_OPTS lines above. To enable the garbage
collection overhead limit, remove the -XX:-UseGCOverheadLimit setting or change it to
-XX:+UseGCOverheadLimit.
Set the PermGen space for Java garbage collection to 512M for all in the JAVA-OPTS environment variable. For example:
Troubleshooting
HiveServer2 Service Crashes
If the HS2 service crashes frequently, confirm that the problem relates to HS2 heap exhaustion by inspecting the HS2
instance stdout log.
1. In Cloudera Manager, from the home page, go to Hive > Instances.
2. In the Instances page, click the link of the HS2 node that is down:
Figure 3: Link to the Stdout Log on the Cloudera Manager Processes Page
– Reduce the size of the result set returned by adding filters to queries. This minimizes memory pressure caused
by "dangling" sessions.
– Look for queries that load all table partitions in memory to execute. This can substantially add to memory
pressure. For example, a query that accesses a partitioned table with the following SELECT statement loads
all partitions of the target table to execute:
How to resolve:
– Add partition filters to queries to reduce the total number of partitions that are accessed. To view all of
the partitions processed by a query, run the EXPLAIN DEPENDENCY clause, which is explained in the
Apache Hive Language Manual.
– Set the hive.metastore.limit.partition.request parameter to 1000 to limit the maximum
number of partitions accessed from a single table in a query. See the Apache wiki for information about
setting this parameter. If this parameter is set, queries that access more than 1000 partitions fail with
the following error:
MetaException: Number of partitions scanned (=%d) on table '%s' exceeds limit (=%d)
Setting this parameter protects against bad workloads and identifies queries that need to be optimized.
To resolve the failed queries:
– Apply the appropriate partition filters.
– Override the limit on a per-query basis.
– Increase the cluster-wide limit beyond 1000, if needed, but note that this adds memory pressure
to HiveServer2 and the Hive metastore.
– If the accessed table is not partitioned, see this Cloudera Engineering Blog post, which explains how to
partition Hive tables to improve query performance. Choose columns or dimensions for partitioning
based upon usage patterns. Partitioning tables too much causes data fragmentation, but partitioning
too little causes queries to read too much data. Either extreme makes querying inefficient. Typically, a
few thousand table partitions is fine.
– Whenever possible, break queries into multiple smaller queries with intermediate temporary tables.
• Improperly written user-defined functions (UDFs)
Improperly written UDFs can exert significant memory pressure on HS2.
How to resolve:
– Understand the memory implications of the UDF and test it before using it in production environments.
YARN Configuration
The YARN properties yarn.nodemanager.resource.cpu-vcores and yarn.nodemanager.resource.memory-mb
determine how cluster resources can be used by Hive on Spark (and other YARN applications). The values for the two
properties are determined by the capacity of your host and the number of other non-YARN applications that coexist
on the same host. Most commonly, only YARN NodeManager and HDFS DataNode services are running on worker
hosts.
Configuring Cores
Allocate 1 core for each of the services and 2 additional cores for OS usage, leaving 28 cores available for YARN. To do
so, set yarn.nodemanager.resource.cpu-vcores=28.
Configuring Memory
Allocate 20 GB memory for these services and processes. To do so, set
yarn.nodemanager.resource.memory-mb=100 GB.
Spark Configuration
After allocating resources to YARN, you define how Spark uses the resources: executor and driver memory, executor
allocation, and parallelism.
With these configurations, each host can run up to 7 executors at a time. Each executor can run up to 4 tasks (one per
core). So, each task has on average 3.5 GB (14 / 4) memory. All tasks running in an executor share the same heap space.
Make sure the sum of spark.executor.memoryOverhead and spark.executor.memory is less than
yarn.scheduler.maximum-allocation-mb.
Parallelism
For available executors to be fully utilized you must run enough tasks concurrently (in parallel). In most cases, Hive
determines parallelism automatically for you, but you may have some control in tuning concurrency. On the input side,
the number of map tasks is equal to the number of splits generated by the input format. For Hive on Spark, the input
format is CombineHiveInputFormat, which can group the splits generated by the underlying input formats as
required. You have more control over parallelism at the stage boundary. Adjust
hive.exec.reducers.bytes.per.reducer to control how much data each reducer processes, and Hive determines
an optimal number of partitions, based on the available executors, executor memory settings, the value you set for
the property, and other factors. Experiments show that Spark is less sensitive than MapReduce to the value you specify
for hive.exec.reducers.bytes.per.reducer, as long as enough tasks are generated to keep all available executors
busy. For optimal performance, pick a value for the property so that Hive generates enough tasks to fully use all available
executors.
For more information on tuning Spark applications, see Tuning Spark Applications.
Hive Configuration
Hive on Spark shares most if not all Hive performance-related configurations. You can tune those parameters much
as you would for MapReduce. However, hive.auto.convert.join.noconditionaltask.size, which is the
threshold for converting common join to map join based on statistics, can have a significant performance impact.
Although this configuration is used for both Hive on MapReduce and Hive on Spark, it is interpreted differently by each.
The size of data is described by two statistics:
• totalSize—Approximate size of data on disk
• rawDataSize—Approximate size of data in memory
Hive on MapReduce uses totalSize. When both are available, Hive on Spark uses rawDataSize. Because of
compression and serialization, a large difference between totalSize and rawDataSize can occur for the same
dataset. For Hive on Spark, you might need to specify a larger value for
hive.auto.convert.join.noconditionaltask.size to convert the same join to a map join. You can increase
the value for this parameter to make map join conversion more aggressive. Converting common joins to map joins can
improve performance. Alternatively, if this value is set too high, too much memory is used by data from small tables,
and tasks may fail because they run out of memory. Adjust this value according to your cluster environment.
You can control whether rawDataSize statistics should be collected, using the property
hive.stats.collect.rawdatasize. Cloudera recommends setting this to true in Hive (the default).
Cloudera also recommends setting two additional configuration properties, using a Cloudera Manager advanced
configuration snippet for HiveServer2:
• hive.stats.fetch.column.stats=true
• hive.optimize.index.filter=true
The following properties are generally recommended for Hive performance tuning, although they are not specific to
Hive on Spark:
hive.optimize.reducededuplication.min.reducer=4
hive.optimize.reducededuplication=true
hive.merge.mapfiles=true
hive.merge.mapredfiles=false
hive.merge.smallfiles.avgsize=16000000
hive.merge.size.per.task=256000000
hive.merge.sparkfiles=true
hive.auto.convert.join=true
hive.auto.convert.join.noconditionaltask=true
hive.auto.convert.join.noconditionaltask.size=20M(might need to increase for Spark,
200M)
hive.optimize.bucketmapjoin.sortedmerge=false
hive.map.aggr.hash.percentmemory=0.5
hive.map.aggr=true
hive.optimize.sort.dynamic.partition=false
hive.stats.autogather=true
hive.stats.fetch.column.stats=true
hive.compute.query.using.stats=true
hive.limit.pushdown.memory.usage=0.4 (MR and Spark)
hive.optimize.index.filter=true
hive.exec.reducers.bytes.per.reducer=67108864
hive.smbjoin.cache.rows=10000
hive.fetch.task.conversion=more
hive.fetch.task.conversion.threshold=1073741824
hive.optimize.ppd=true
Note: Pre-warming takes a few seconds and is a good practice for short-lived sessions, especially if
the query involves reduce stages. However, if the value of hive.prewarm.numcontainers is higher
than what is available in the cluster, the process can take a maximum of 30 seconds. Use pre-warming
with caution.
Prerequisites
• Cloudera recommends that each instance of the metastore runs on a separate cluster host, to maximize high
availability.
• Hive metastore HA requires a database that is also highly available, such as MySQL with replication in active-active
mode. Refer to the documentation for your database of choice to configure it correctly.
Limitations
Sentry HDFS synchronization does not support Hive metastore HA.
Important:
• If you use Cloudera Manager, do not use these command-line instructions.
• This information applies specifically to CDH 5.8.x. If you use a lower version of CDH, see the
documentation for that version located at Cloudera Documentation.
1. Configure Hive on each of the cluster hosts where you want to run a metastore, following the instructions at
Configuring the Hive Metastore on page 19.
2. On the server where the master metastore instance runs, edit the /etc/hive/conf.server/hive-site.xml
file, setting the hive.metastore.uris property's value to a list of URIs where a Hive metastore is available for
failover.
<property>
<name>hive.metastore.uris</name>
<value>thrift://metastore1.example.com,thrift://metastore2.example.com,thrift://metastore3.example.com</value>
3. If you use a secure cluster, enable the Hive token store by configuring the value of the
hive.cluster.delegation.token.store.class property to
org.apache.hadoop.hive.thrift.DBTokenStore. Non-secure clusters can skip this step.
<property>
<name>hive.cluster.delegation.token.store.class</name>
<value>org.apache.hadoop.hive.thrift.DBTokenStore</value>
</property>
6. Test your configuration by stopping your main metastore instance, and then attempting to connect to one of the
other metastores from a client. The following is an example of doing this on a RHEL or Fedora system. The example
first stops the local metastore, then connects to the metastore on the host metastore2.example.com and runs
the SHOW TABLES command.
Warning:
HiveServer2 high availability does not automatically fail and retry long-running Hive queries. If any of
the HiveServer2 instances fail, all queries running on that instance fail and are not retried. Instead,
the client application must re-submit the queries.
After you enable HiveServer2 high availability, existing Oozie jobs must be changed to reflect the
HiveServer2 address.
Note: When you set the HiveServer2 Load Balancer property, Cloudera Manager regenerates
the keytabs for HiveServer2 roles. The principal in these keytabs contains the load balancer
hostname. If there is a Hue service that depends on this Hive service, it also uses the load balancer
to communicate with Hive.
Hive Replication
Minimum Required Role: BDR Administrator (also provided by Full Administrator)
Hive replication enables you to copy (replicate) your Hive metastore and data from one cluster to another and
synchronize the Hive metastore and data set on the destination cluster with the source, based on a specified replication
schedule. The destination cluster must be managed by the Cloudera Manager Server where the replication is being
set up, and the source cluster can be managed by that same server or by a peer Cloudera Manager Server.
Configuration notes:
• If the hadoop.proxyuser.hive.groups configuration has been changed to restrict access to the Hive Metastore
Server to certain users or groups, the hdfs group or a group containing the hdfs user must also be included in
the list of groups specified for Hive replication to work. This configuration can be specified either on the Hive
service as an override, or in the core-site HDFS configuration. This applies to configuration settings on both the
source and destination clusters.
• If you configured Synchronizing HDFS ACLs and Sentry Permissions on the target cluster for the directory where
HDFS data is copied during Hive replication, the permissions that were copied during replication, are overwritten
by the HDFS ACL synchronization and are not preserved
HOST_WHITELIST=host-1.mycompany.com,host-2.mycompany.com
• If you drop a table partition or index on the source cluster, the replication job also drops them on the destination
cluster.
• If you truncate a table, and the Delete Policy for the replication job is set to Delete to Trash or Delete Permanently,
the corresponding data files are deleted on the destination during a replication.
1. Verify that your cluster conforms to one of the Supported Replication Scenarios.
2. If the source cluster is managed by a different Cloudera Manager server than the destination cluster, configure a
peer relationship.
3. Do one of the following:
• From the Backup tab, select Replications.
• From the Clusters tab, go to the Hive service and select Quick Links > Replication.
The Schedules tab of the Replications page displays.
4. Select Create New Schedule > Hive Replication.
5. Use the Source drop-down list to select the cluster with the Hive service you want to replicate.
6. Use the Destination drop-down list to select the destination for the replication. If there is only one Hive service
managed by Cloudera Manager available as a destination, this is specified as the destination. If more than one
Hive service is managed by this Cloudera Manager, select from among them.
7. Select a Schedule:
• Immediate - Run the schedule Immediately.
• Once - Run the schedule one time in the future. Set the date and time.
• Recurring - Run the schedule periodically in the future. Set the date, time, and interval between runs.
8. Leave Replicate All checked to replicate all the Hive metastore databases from the source. To replicate only
selected databases, uncheck this option and enter the database name(s) and tables you want to replicate.
• You can specify multiple databases and tables using the plus symbol to add more rows to the specification.
• You can specify multiple databases on a single line by separating their names with the pipe (|) character. For
example: mydbname1|mydbname2|mydbname3.
• Regular expressions can be used in either database or table fields, as described in the following table:
9. Use the Advanced Options section to specify an export location, modify the parameters of the MapReduce job
that will perform the replication, and set other options. You can select a MapReduce service (if there is more than
one in your cluster) and change the following parameters:
• Uncheck the Replicate HDFS Files checkbox to skip replicating the associated data files.
• Uncheck the Replicate Impala Metadata checkbox to skip replicating Impala metadata. (This option is checked
by default.) See Impala Metadata Replication.
• The Force Overwrite option, if checked, forces overwriting data in the destination metastore if incompatible
changes are detected. For example, if the destination metastore was modified, and a new partition was added
to a table, this option forces deletion of that partition, overwriting the table with the version found on the
source.
Important: If the Force Overwrite option is not set, and the Hive replication process detects
incompatible changes on the source cluster, Hive replication fails. This sometimes occurs
with recurring replications, where the metadata associated with an existing database or table
on the source cluster changes over time.
Note: In a Kerberized cluster, the HDFS principal on the source cluster must have read,
write, and execute access to the Export Path directory on the destination cluster.
• By default, Hive HDFS data files (for example, /user/hive/warehouse/db1/t1) are replicated to a location
relative to "/" (in this example, to /user/hive/warehouse/db1/t1). To override the default, enter a path
in the HDFS Destination Path field. For example, if you enter /ReplicatedData, the data files would be
replicated to /ReplicatedData/user/hive/warehouse/db1/t1.
• Select the MapReduce Service to use for this replication (if there is more than one in your cluster).
• To specify the user that should run the MapReduce job, use the Run As Username option. By default,
MapReduce jobs run as hdfs. To run the MapReduce job as a different user, enter the user name. If you are
using Kerberos, you must provide a user name here, and it must have an ID greater than 1000.
Note: The user running the MapReduce job should have read and execute permissions
on the Hive warehouse directory on the source cluster. If you configure the replication job
to preserve permissions, superuser privileges are required on the destination cluster.
• Scheduler Pool - The name of a resource pool. The value you enter is used by the MapReduce Service you
specified when Cloudera Manager executes the MapReduce job for the replication. The job specifies the
value using one of these properties:
Note: You must be running as a superuser to preserve permissions. Use the "Run As
Username" option to ensure that is the case.
• Alerts - Whether to generate alerts for various state changes in the replication workflow. You can alert On
Failure, On Start, On Success, or On Abort (when the replication workflow is aborted).
10. Click Save Schedule.
The replication task appears as a row in the Replications Schedule table. See Viewing Replication Schedules on
page 71.
Note: If your replication job takes a long time to complete, and tables change before the replication
finishes, the replication may fail. Consider making the Hive Warehouse Directory and the directories
of any external tables snapshottable, so that the replication job creates snapshots of the directories
before copying the files. See Using Snapshots with Replication.
Only one job corresponding to a replication schedule can occur at a time; if another job associated with that same
replication schedule starts before the previous one has finished, the second one is canceled.
You can limit the replication jobs that are displayed by selecting filters on the left. If you do not see an expected
schedule, adjust or clear the filters. Use the search box to search the list of schedules for path, database, or table
names.
The Replication Schedules columns are described in the following table.
Column Description
ID An internally generated ID number that identifies the schedule. Provides a convenient way to
identify a schedule.
Click the ID column label to sort the replication schedule table by ID.
Column Description
Last Run The date and time when the replication last ran. Displays None if the scheduled replication has
not yet been run. Click the date and time link to view the Replication History page for the
replication.
Displays one of the following icons:
• - Successful. Displays the date and time of the last run replication.
• - Failed. Displays the date and time of a failed replication.
• - None. This scheduled replication has not yet run.
•
- Running. Displays a spinner and bar showing the progress of the replication.
Click the Last Run column label to sort the Replication Schedules table by the last run date.
Next Run The date and time when the next replication is scheduled, based on the schedule parameters
specified for the schedule. Hover over the date to view additional details about the scheduled
replication.
Click the Next Run column label to sort the Replication Schedules table by the next run date.
Actions The following items are available from the Action button:
• Show History - Opens the Replication History page for a replication. See Viewing Replication
History.
• Edit Configuration - Opens the Edit Replication Schedule page.
• Dry Run - Simulates a run of the replication task but does not actually copy any files or
tables. After a Dry Run, you can select Show History, which opens the Replication History
page where you can view any error messages and the number and size of files or tables
that would be copied in an actual replication.
• Click Collect Diagnostic Data to open the Send Diagnostic Data screen, which allows you
to collect replication-specific diagnostic data for the last 10 runs of the schedule:
1. Select Send Diagnostic Data to Cloudera to automatically send the bundle to Cloudera
Support. You can also enter a ticket number and comments when sending the bundle.
2. Click Collect and Send Diagnostic Data to generate the bundle and open the
Replications Diagnostics Command screen.
3. When the command finishes, click Download Result Data to download a zip file
containing the bundle.
• Run Now - Runs the replication task immediately.
• Disable | Enable - Disables or enables the replication schedule. No further replications are
scheduled for disabled replication schedules.
• Delete - Deletes the schedule. Deleting a replication schedule does not delete copied files
or tables.
• While a job is in progress, the Last Run column displays a spinner and progress bar, and each stage of the replication
task is indicated in the message beneath the job's row. Click the Command Details link to view details about the
execution of the command.
• If the job is successful, the number of files copied is indicated. If there have been no changes to a file at the source
since the previous job, then that file is not copied. As a result, after the initial job, only a subset of the files may
actually be copied, and this is indicated in the success message.
• If the job fails, the icon displays.
• To view more information about a completed job, select Actions > Show History. See Viewing Replication History.
The Replication History page displays a table of previously run replication jobs with the following columns:
Column Description
Start Time Time when the replication job started.
Click to expand the display and show details of the replication. In this screen, you can:
• Click the View link to open the Command Details page, which displays details and
messages about each step in the execution of the command. Click to expand the display
for a Step to:
– View the actual command string.
– View the Start time and duration of the command.
– Click the Context link to view the service status page relevant to the command.
– Select one of the tabs to view the Role Log, stdout, and stderr for the command.
See Viewing Running and Recent Commands.
• Click Collect Diagnostic Data to open the Send Diagnostic Data screen, which allows
you to collect replication-specific diagnostic data for this run of the schedule:
1. Select Send Diagnostic Data to Cloudera to automatically send the bundle to
Cloudera Support. You can also enter a ticket number and comments when sending
the bundle.
2. Click Collect and Send Diagnostic Data to generate the bundle and open the
Replications Diagnostics Command screen.
3. When the command finishes, click Download Result Data to download a zip file
containing the bundle.
• (HDFS only) Link to view details on the MapReduce Job used for the replication. See
Viewing and Filtering MapReduce Activities.
• (Dry Run only) View the number of Replicable Files. Displays the number of files that
would be replicated during an actual replication.
• (Dry Run only) View the number of Replicable Bytes. Displays the number of bytes that
would be replicated during an actual replication.
• Link to download a CSV file containing a Replication Report. This file lists the databases
and tables that were replicated.
• View the number of Errors that occurred during the replication.
• View the number of Impala UDFs replicated. (Displays only for Hive replications where
Replicate Impala Metadata is selected.)
• Click the link to download a CSV file containing a Download Listing. This file lists the files
and directories that were replicated.
• Click the link to download a CSV file containing Download Status.
• If a user was specified in the Run As Username field when creating the replication job,
the selected user displays.
• View messages returned from the replication job.
Column Description
Files Skipped Number of files skipped during the replication. The replication process skips files that already
exist in the destination and have not changed.
Hive Authentication
Here is a summary of the status of Hive authentication in CDH 5:
• HiveServer2 supports authentication of the Thrift client using Kerberos or user/password validation backed by
LDAP. For configuration instructions, see HiveServer2 Security Configuration.
• Earlier versions of HiveServer do not support Kerberos authentication for clients. However, the Hive MetaStoreServer
does support Kerberos authentication for Thrift clients. For configuration instructions, see Hive MetaStoreServer
Security Configuration.
See also: Using Hive to Run Queries on a Secure HBase Server on page 83
For authorization, Hive uses Apache Sentry to enable role-based, fine-grained authorization for HiveServer2. See Apache
Sentry Overview.
Important: Cloudera does not support Apache Ranger or Hive's native authorization frameworks for
configuring access control in Hive. Use the Cloudera-supported Apache Sentry instead.
Kerberos authentication is supported between the Thrift client and HiveServer2, and between HiveServer2 and secure
HDFS. LDAP authentication is supported only between the Thrift client and HiveServer2.
<property>
<name>hive.server2.authentication</name>
<value>KERBEROS</value>
</property>
<property>
<name>hive.server2.authentication.kerberos.principal</name>
<value>hive/[email protected]</value>
</property>
<property>
<name>hive.server2.authentication.kerberos.keytab</name>
<value>/etc/hive/conf/hive.keytab</value>
</property>
where:
• hive.server2.authentication is a client-facing property that controls the type of authentication HiveServer2
uses for connections to clients. In this case, HiveServer2 uses Kerberos to authenticate incoming clients.
• The [email protected] value in the example above is the Kerberos principal for the host where HiveServer2
is running. The string _HOST in the properties is replaced at run time by the fully qualified domain name (FQDN)
of the host machine where the daemon is running. Reverse DNS must be working on all the hosts configured this
way. Replace YOUR-REALM.COM with the name of the Kerberos realm your Hadoop cluster is in.
• The /etc/hive/conf/hive.keytab value in the example above is a keytab file for that principal.
If you configure HiveServer2 to use both Kerberos authentication and secure impersonation, JDBC clients and Beeline
can specify an alternate session user. If these clients have proxy user privileges, HiveServer2 impersonates the alternate
user instead of the one connecting. The alternate user can be specified by the JDBC connection string
proxyUser=userName
Configuring JDBC Clients for Kerberos Authentication with HiveServer2 (Using the Apache Hive Driver in Beeline)
JDBC-based clients must include principal=<hive.server2.authentication.principal> in the JDBC connection
string. For example:
String url =
"jdbc:hive2://node1:10000/default;principal=hive/[email protected]"
Connection con = DriverManager.getConnection(url);
where hive is the principal configured in hive-site.xml and HiveServer2Host is the host where HiveServer2 is
running.
For JDBC clients using the Cloudera JDBC driver, see Cloudera JDBC Driver for Hive. For ODBC clients, see Cloudera
ODBC Driver for Apache Hive.
$ /usr/lib/hive/bin/beeline
beeline> !connect
jdbc:hive2://localhost:10000/default;principal=hive/[email protected]
0: jdbc:hive2://localhost:10000/default>
For more information about the Beeline CLI, see Using the Beeline CLI.
For instructions on encrypting communication with the ODBC/JDBC drivers, see Configuring Encrypted Communication
Between HiveServer2 and Client Drivers on page 84.
Important: When using LDAP username/password authentication with HiveServer2, you must enable
encrypted communication between HiveServer2 and its client drivers to avoid sending cleartext
passwords. For instructions, see Configuring Encrypted Communication Between HiveServer2 and
Client Drivers on page 84. To avoid sending LDAP credentials over a network in cleartext, see
Configuring LDAPS Authentication with HiveServer2 on page 79.
<property>
<name>hive.server2.authentication</name>
<value>LDAP</value>
</property>
<property>
<name>hive.server2.authentication.ldap.url</name>
<value>LDAP_URLL</value>
</property>
<property>
<name>hive.server2.authentication.ldap.Domain</name>
<value>AD_DOMAIN_ADDRESS</value>
</property>
Where:
The LDAP_URL value is the access URL for your LDAP server. For example, ldap[s]://<host>:<port>
<property>
<name>hive.server2.authentication</name>
<value>LDAP</value>
</property>
<property>
<name>hive.server2.authentication.ldap.url</name>
<value>LDAP_URL</value>
</property>
<property>
<name>hive.server2.authentication.ldap.baseDN</name>
<value>LDAP_BaseDN</value>
</property>
where:
• The LDAP_URL value is the access URL for your LDAP server.
• The LDAP_BaseDN value is the base LDAP DN for your LDAP server; for example,
ou=People,dc=example,dc=com.
where the LDAP_Userid value is the user ID and LDAP_Password is the password of the client user.
For ODBC Clients, see Cloudera ODBC Driver for Apache Hive.
Hive uses these login details to authenticate to LDAP. The Hive service trusts that Hue has validated the user being
impersonated.
4. If this is a managed cluster, in Cloudera Manager, go to the Hive service and select Configuration. Under Category,
select Security. In the right panel, search for HiveServer2 TLS/SSL Certificate Trust Store File, and add the path
to the truststore file that you created in step 1.
If you are using an unmanaged cluster, set the environment variable HADOOP_OPTS as follows:
HADOOP_OPTS="-Djavax.net.ssl.trustStore=<trustStore-file-path>
-Djavax.net.ssl.trustStorePassword=<trustStore-password>"
5. Restart HiveServer2.
Pluggable Authentication
Pluggable authentication allows you to provide a custom authentication provider for HiveServer2.
To enable pluggable authentication:
<property>
<name>hive.server2.authentication</name>
<value>CUSTOM</value>
<description>Client authentication types.
NONE: no authentication check
LDAP: LDAP/AD based authentication
KERBEROS: Kerberos/GSSAPI authentication
CUSTOM: Custom authentication provider
(Use with property hive.server2.custom.authentication.class)
</description>
</property>
<property>
<name>hive.server2.custom.authentication.class</name>
<value>pluggable-auth-class-name</value>
<description>
Custom authentication class. Used when property
'hive.server2.authentication' is set to 'CUSTOM'. Provided class
must be a proper implementation of the interface
org.apache.hive.service.auth.PasswdAuthenticationProvider. HiveServer2
will call its Authenticate(user, passed) method to authenticate requests.
The implementation may optionally extend the Hadoop's
org.apache.hadoop.conf.Configured class to grab Hive's Configuration object.
</description>
</property>
HiveServer2 Impersonation
Note: This is not the recommended method to implement HiveServer2 impersonation. Cloudera
recommends you use Sentry to implement this instead.
Impersonation support in HiveServer2 allows users to execute queries and access HDFS files as the connected user
rather than the super user who started the HiveServer2 daemon. Impersonation allows admins to enforce an access
policy at the file level using HDFS file and directory permissions.
<property>
<name>hive.server2.enable.impersonation</name>
<description>Enable user impersonation for HiveServer2</description>
<value>true</value>
</property>
2. In HDFS or MapReduce configurations, add the following property to the core-site.xml file:
<property>
<name>hadoop.proxyuser.hive.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.hive.groups</name>
<value>*</value>
</property>
Note: This is not the recommended method to protect the Hive Metastore. Cloudera recommends
you use Sentry to implement this instead.
To prevent users from accessing the Hive metastore and the Hive metastore database using any method other than
through HiveServer2, the following actions are recommended:
• Add a firewall rule on the metastore service host to allow access to the metastore port only from the HiveServer2
host. You can do this using iptables.
• Grant access to the metastore database only from the metastore service host. This is specified for MySQL as:
<property>
<name>hive.server2.authentication</name>
<value>NONE</value>
<description>
Client authentication types.
NONE: no authentication check
LDAP: LDAP/AD based authentication
KERBEROS: Kerberos/GSSAPI authentication
CUSTOM: Custom authentication provider
(Use with property hive.server2.custom.authentication.class)
</description>
</property>
• hive.server2.authentication.kerberos.keytab
• hive.server2.authentication.kerberos.principal
<property>
<name>hive.metastore.sasl.enabled</name>
<value>true</value>
<description>If true, the metastore thrift interface will be secured with SASL. Clients
must authenticate with Kerberos.</description>
</property>
<property>
<name>hive.metastore.kerberos.keytab.file</name>
<value>/etc/hive/conf/hive.keytab</value>
<description>The path to the Kerberos Keytab file containing the metastore thrift
server's service principal.</description>
</property>
<property>
<name>hive.metastore.kerberos.principal</name>
<value>hive/[email protected]</value>
<description>The service principal for the metastore thrift server. The special string
_HOST will be replaced automatically with the correct host name.</description>
</property>
Note:
The values shown above for the hive.metastore.kerberos.keytab.file and
hive.metastore.kerberos.principal properties are examples which you will need to
replace with the appropriate values for your cluster. Also note that the Hive keytab file should
have its access permissions set to 600 and be owned by the same account that is used to run the
Metastore server, which is the hive user by default.
• Requests to access the metadata are fulfilled by the Hive metastore impersonating the requesting user. This
includes read access to the list of databases, tables, properties of each table such as their HDFS location and file
type. You can restrict access to the Hive metastore service by allowing it to impersonate only a subset of Kerberos
users. This can be done by setting the hadoop.proxyuser.hive.groups property in core-site.xml on the
Hive metastore host.
For example, if you want to give the hive user permission to impersonate members of groups hive and user1:
<property>
<name>hadoop.proxyuser.hive.groups</name>
<value>hive,user1</value>
</property>
In this example, the Hive metastore can impersonate users belonging to only the hive and user1 groups.
Connection requests from users not belonging to these groups will be rejected.
where:
• You replace YOUR-REALM with the name of your Kerberos realm
• You replace zookeeper1,zookeeper2,zookeeper3 with the names of your ZooKeeper servers. The
hbase.zookeeper.quorum property is configured in the hbase-site.xml file.
• The special string _HOST is replaced at run-time by the fully qualified domain name of the host machine where
the HBase Master or RegionServer is running. This requires that reverse DNS is properly working on all the hosts
configured this way.
In the following, _HOST is the name of the host where the HBase Master is running:
-hiveconf hbase.master.kerberos.principal=hbase/[email protected]
In the following, _HOST is the hostname of the HBase RegionServer that the application is connecting to:
-hiveconf hbase.regionserver.kerberos.principal=hbase/[email protected]
Note:
You can also set the HIVE_OPTS environment variable in your shell profile.
Note: Cloudera Manager and CDH components support either TLS 1.0, TLS 1.1, or TLS 1.2, but not
SSL 3.0. References to SSL continue only because of its widespread use in technical jargon.
Property Description
Enable TLS/SSL for Enable support for encrypted client-server communication using Transport Layer
HiveServer2 Security (TLS) for HiveServer2 connections.
HiveServer2 TLS/SSL Server Path to the TLS keystore.
JKS Keystore File Location
HiveServer2 TLS/SSL Server Password for the TLS keystore.
JKS Keystore File Password
<property>
<name>hive.server2.use.SSL</name>
<value>true</value>
<description>enable/disable SSL </description>
</property>
<property>
<name>hive.server2.keystore.path</name>
<value>keystore-file-path</value>
<description>path to keystore file</description>
</property>
<property>
<name>hive.server2.keystore.password</name>
<value>keystore-file-password</value>
<description>keystore password</description>
</property>
;ssl=true[;sslTrustStore=<Trust-Store-Path>;trustStorePassword=<Trust-Store-password>]
jdbc:hive2://localhost:10000/default;ssl=true;\
sslTrustStore=/home/usr1/ssl/trust_store.jks;trustStorePassword=xyz
• or: the Trust Store arguments are set using the Java system properties javax.net.ssl.trustStore and
javax.net.ssl.trustStorePassword; for example:
java -Djavax.net.ssl.trustStore=/home/usr1/ssl/trust_store.jks
-Djavax.net.ssl.trustStorePassword=xyz \
MyClass jdbc:hive2://localhost:10000/default;ssl=true
For more information on using self-signed certificates and the Trust Store, see the Oracle Java SE keytool page.
<property>
<name>hive.server2.thrift.sasl.qop</name>
<value>auth-conf</value>
<description>Sasl QOP value; one of 'auth', 'auth-int' and 'auth-conf'</description>
</property>
!connect jdbc:hive2://ip-10-5-15-197.us-west-2.compute.internal:10000/default; \
principal=hive/[email protected];sasl.qop=auth-conf
Important:
• When Sentry is enabled, you must use Beeline to execute Hive queries. Hive CLI is not supported
with Sentry and must be disabled. See Disabling Hive CLI.
• There are some differences in syntax between Hive and the corresponding Impala SQL statements.
For the Impala syntax, see SQL Statements.
Column-level Authorization
CDH 5.5 introduces column-level access control for tables in Hive and Impala. Previously, Sentry supported privilege
granularity only down to a table. Hence, if you wanted to restrict access to a column of sensitive data, the workaround
would be to first create view for a subset of columns, and then grant privileges on that view. To reduce the administrative
overhead associated with such an approach, Sentry now allows you to assign the SELECT privilege on a subset of
columns in a table.
The following command grants a role the SELECT privilege on a column:
The following command can be used to revoke the SELECT privilege on a column:
Any new columns added to a table will be inaccessible by default, until explicitly granted access.
Actions allowed for users with SELECT privilege on a column:
Users whose roles have been granted the SELECT privilege on columns only, can perform operations which explicitly
refer to those columns. Some examples are:
•
SELECT column_name FROM TABLE table_name;
In this case, Sentry will first check to see if the user has the required privileges to access the table. It will then
further check to see whether the user has the SELECT privilege to access the column(s).
•
SELECT COUNT(column_name) FROM TABLE table_name;
Users are also allowed to use the COUNT function to return the number of values in the column.
•
SELECT column_name FROM TABLE table_name WHERE column_name <operator> GROUP BY
column_name;
The above command will work as long as you refer only to columns to which you already have access.
• To list the column(s) to which the current user has SELECT access:
SHOW COLUMNS;
Exceptions:
• If a user has SELECT access to all columns in a table, the following command will work. Note that this is an
exception, not the norm. In all other cases, SELECT on all columns does not allow you to perform table-level
operations.
• The DESCRIBE table command differs from the others, in that it does not filter out columns for which the user
does not have SELECT access.
DESCRIBE (table_name);
Limitations:
• Column-level privileges can only be applied to tables and partitions, not views.
• HDFS-Sentry Sync: With HDFS-Sentry sync enabled, even if a user has been granted access to all columns of a
table, they will not have access to the corresponding HDFS data files. This is because Sentry does not consider
SELECT on all columns equivalent to explicitly being granted SELECT on the table.
• Column-level access control for access from Spark SQL is not supported by the HDFS-Sentry plug-in.
Note: Sentry by default does not allow grants for groups with non-alphanumeric names. To work
around this, use backticks around the affected group names. For example:
GRANT
<PRIVILEGE> [, <PRIVILEGE> ]
ON <OBJECT> <object_name>
TO ROLE <roleName> [,ROLE <roleName>]
Starting with CDH 5.5, you can grant the SELECT privilege on specific columns of a table. For example:
Similarly, the following CREATE EXTERNAL TABLE statement works even though it is missing scheme and authority
components.
Since Sentry supports both HDFS and Amazon S3, starting in CDH 5.8, Cloudera recommends that you specify the fully
qualified URI in GRANT statements to avoid confusion. If the underlying storage is a mix of S3 and HDFS, the risk of
granting the wrong privileges increases. The following are examples of fully qualified URIs:
• HDFS: hdfs://host:port/path/to/hdfs/table
• S3: s3a://host:port/path/to/s3/table
REVOKE
<PRIVILEGE> [, <PRIVILEGE> ]
ON <OBJECT> <object_name>
FROM ROLE <roleName> [,ROLE <roleName>]
For example, you can revoke previously-granted SELECT privileges on specific columns of a table with the following
statement:
GRANT
<PRIVILEGE>
ON <OBJECT> <object_name>
TO ROLE <roleName>
WITH GRANT OPTION
Only a role with GRANT option on a specific privilege or its parent privilege can revoke that privilege from other roles.
Once the following statement is executed, all privileges with and without grant option are revoked.
REVOKE
<PRIVILEGE>
ON <OBJECT> <object_name>
FROM ROLE <roleName>
Hive does not currently support revoking only the WITH GRANT OPTION from a privilege previously granted to a role.
To remove the WITH GRANT OPTION, revoke the privilege and grant it again without the WITH GRANT OPTION flag.
SHOW Statement
• To list the database(s) for which the current user has database, table, or column-level access:
SHOW DATABASES;
• To list the table(s) for which the current user has table or column-level access:
SHOW TABLES;
• To list the column(s) to which the current user has SELECT access:
SHOW COLUMNS;
• To list all the roles in the system (only for sentry admin users):
SHOW ROLES;
• To list all the roles in effect for the current user session:
• To list all the roles assigned to the given <groupName> (only allowed for Sentry admin users and others users
that are part of the group specified by <groupName>):
• The SHOW statement can also be used to list the privileges that have been granted to a role or all the grants given
to a role for a particular object.
To list all the grants for the given <roleName> (only allowed for Sentry admin users and other users that have
been granted the role specified by <roleName>). The following command will also list any column-level privileges:
• To list all the grants for a role on the given <objectName> (only allowed for Sentry admin users and other users
that have been granted the role specified by <roleName>). The following command will also list any column-level
privileges:
[groups]
# Assigns each Hadoop group to its set of roles
manager = analyst_role, junior_analyst_role
analyst = analyst_role
jranalyst = junior_analyst_role
customers_admin = customers_admin_role
admin = admin_role
analyst_role = server=server1->db=analyst1, \
server=server1->db=jranalyst1->table=*->action=select
server=server1->uri=hdfs://ha-nn-uri/landing/analyst1
junior_analyst_role = server=server1->db=jranalyst1, \
server=server1->uri=hdfs://ha-nn-uri/landing/jranalyst1
The following sections show how you can use the new GRANT statements to assign privileges to roles (and assign roles
to groups) to match the sample policy file above.
Grant privileges to analyst_role:
Troubleshooting Hive
This section provides guidance on problems you may encounter while installing, upgrading, or running Hive.
With Hive, the most common troubleshooting aspects involve performance issues and managing disk space. Because
Hive uses an underlying compute mechanism such as MapReduce or Spark, sometimes troubleshooting requires
diagnosing and changing configuration in those lower layers.
Troubleshooting
HiveServer2 Service Crashes
If the HS2 service crashes frequently, confirm that the problem relates to HS2 heap exhaustion by inspecting the HS2
instance stdout log.
1. In Cloudera Manager, from the home page, go to Hive > Instances.
2. In the Instances page, click the link of the HS2 node that is down:
Figure 9: Link to the Stdout Log on the Cloudera Manager Processes Page
Figure 10: Cloudera Manager Chart Library Page for Process Resources
– Reduce the size of the result set returned by adding filters to queries. This minimizes memory pressure caused
by "dangling" sessions.
– Look for queries that load all table partitions in memory to execute. This can substantially add to memory
pressure. For example, a query that accesses a partitioned table with the following SELECT statement loads
all partitions of the target table to execute:
How to resolve:
– Add partition filters to queries to reduce the total number of partitions that are accessed. To view all of
the partitions processed by a query, run the EXPLAIN DEPENDENCY clause, which is explained in the
Apache Hive Language Manual.
– Set the hive.metastore.limit.partition.request parameter to 1000 to limit the maximum
number of partitions accessed from a single table in a query. See the Apache wiki for information about
setting this parameter. If this parameter is set, queries that access more than 1000 partitions fail with
the following error:
MetaException: Number of partitions scanned (=%d) on table '%s' exceeds limit (=%d)
Setting this parameter protects against bad workloads and identifies queries that need to be optimized.
To resolve the failed queries:
– Apply the appropriate partition filters.
– Override the limit on a per-query basis.
– Increase the cluster-wide limit beyond 1000, if needed, but note that this adds memory pressure
to HiveServer2 and the Hive metastore.
– If the accessed table is not partitioned, see this Cloudera Engineering Blog post, which explains how to
partition Hive tables to improve query performance. Choose columns or dimensions for partitioning
based upon usage patterns. Partitioning tables too much causes data fragmentation, but partitioning
too little causes queries to read too much data. Either extreme makes querying inefficient. Typically, a
few thousand table partitions is fine.
– Whenever possible, break queries into multiple smaller queries with intermediate temporary tables.
• Improperly written user-defined functions (UDFs)
Improperly written UDFs can exert significant memory pressure on HS2.
How to resolve:
– Understand the memory implications of the UDF and test it before using it in production environments.