将Hive的默认数据库Derby改成Postgresql

Hive的默认数据库为Derby,这个数据库用于本身调试是能够的,可是要面对大量数据就有些力不从心了,因此接下来我要将Derby换为Postgresql,我会具体说一下在更换过程当中须要注意的地方。html

首先,下载Hive,咱们直接下载稳定的apache-hive-0.14.0-bin.tar.gz,下载地址,java

http://apache.fayea.com/hive/stable/

下载完成后,安装,将Hive添加到环境变量中,编辑bashrc文件linux

vim ~/.bashrc

将下行添加进去sql

export HIVE_HOME=/opt/apache-hive-0.14.0-bin

同时将bin目录添加到PATH中shell

export PATH=$HIVE_HOME/bin:$PATH

配置完成后,执行下面的命令,让修改的环境变量立刻生效数据库

source ~/.bashrc

好了,到这里Hive就安装完了,切换到系统管理员的身份,执行hive,看看效果express

若是执行完成后没有报错,应该来到这个界面apache


执行vim

show tables;

若是返回OK,就说明你的Hive安装成功了。bash

接下来修改默认数据库:

首先,下载postgresql的jdbc驱动包,下载地址

http://jdbc.postgresql.org/download.html

仔细查看页面说明,选择符合本身系统环境的驱动包,我这里下载的是

postgresql-9.3-1102.jdbc41.jar

好了,将这个驱动包上传到Hive的lib目录下面,在Hive的conf目录下面添加

hive-site.xml

文件,对于0.14版本而言这个文件默认是没有的,在文件中添加如下内容

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<configuration>
  <!-- WARNING!!! This file is auto generated for documentation purposes ONLY! -->
  <!-- WARNING!!! Any changes you make to this file will be ignored by Hive.   -->
  <!-- WARNING!!! You must make your changes in hive-site.xml instead.         -->
  <!-- Hive Execution Parameters -->
  
<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>
</configuration>

这个文件中说明了,具体的数据库链接的相关信息,到这里应该就部署完成了,可是还有一些细节须要操做,

$JAVA_HOME/lib/tools.jar

这个jar包拷贝到Hive的lib目录下。

为了防止Postgresql发生死锁须要导入一个sql,在上面的下载的Hive的包中进入到如下目录

apache-hive-0.14.0-bin.tar.gz\apache-hive-0.14.0-bin\scripts\metastore\upgrade\postgres

找到文件

hive-schema-0.14.0.postgres.sql

在linux中执行如下命令进行导入

psql -U db_user -d db_name -h db_ip -f hive-schema-0.14.0.postgres.sql

导入完成后,因此的修改就完成了,赶快去验证一下

create table text_test(str string);
show tables;

若是一切显示正常,那么恭喜你,修改为功!

相关文章
相关标签/搜索