將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;

若是一切顯示正常,那麼恭喜你,修改爲功!

相關文章
相關標籤/搜索