前提:hive已经安装配置完成,机器上已有postgresql。
hive默认的元数据库为derby,用来测试没有问题,但是要使用大量数据就会有点吃力,因此将hive数据库修改为postgresql。
1.首先需要下载postgresql的jdbc驱动包(需要选择与自己系统环境相符的版本):
wegt https://jdbc.postgresql.org/download/postgresql-42.2.2.jar
2.将驱动包移动到hive的lib目录下:
mv postgresql-42.2.2.jar /hive/apache-hive-2.1.1-bin/lib
3.修改hive的conf目录下的hive-site.xml,加入以下内容(这个文件中说明了具体的数据库连接的相关信息):
<property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:postgresql://db_ip:db_port/db_name</value> <description>JDBC connect string for a JDBC metastore</description> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>org.postgresql.Driver</value> <description>Driver class name for a JDBC metastore</description> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>db_user</value> <description>username to use against metastore database</description> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>db_pwd</value> <description>password to use against metastore database</description> </property>
4.将$JAVA_HOME/lib/tools.jar文件copy到hive的lib目录下。
5.为了防止postgresql发生死锁需要导入一个sql:
#进入hive目录 cd /hive/apache-hive-2.1.1-bin/scripts/metastore/upgrade/postgres #找到hive-schema-0.14.0.postgres.sql文件,导入: /postgres$ psql -U postgres -d postgres -h 192.168.19.40 -f hive-schema-0.14.0.postgres.sql
6.测试成功:
hive> create table text_text(str string); OK Time taken: 4.787 seconds hive> show tables; OK text_text Time taken: 0.191 seconds, Fetched: 1 row(s) hive>
浙公网安备 33010602011771号