{"title": "Hive\u4f7f\u7528Postgresql\u4f5c\u4e3aMetastore\u6570\u636e\u5e93\u7684\u95ee\u9898", "update_time": "2013-02-06 11:17:49", "tags": "hive postgresql", "pid": "217", "icon": "hadoop.png"}
使用postgresql作为Hive的metastore,遇到hive DDL操作时postgresql死锁的问题。 hive刚配置好,然后创建一个table,再drop就出问题了。现象如下: ``` 13557 ? Ss 0:00 \_ postgres: hive hive 127.0.0.1(9190) ALTER TABLE waiting 13562 ? Ss 0:00 \_ postgres: hive hive 127.0.0.1(9195) idle in transaction ``` postgresql 死锁了。之前参考了 http://blog.csdn.net/zhao6014/article/details/6210252 未果。我的问题和他类似,应该是metastore的元数据表结构创建的问题。 最后我找到了方法。通过下载hive-0.8.1的tar包,直接找到postgresql的metastore元数据表结构导入即可。 需要注意的是hive-0.6.0和hive-0.7.0 并不带有metastore的初始化sql,0.8.1版本里是带有metastore的初始化sql的,且带有之前老版本的metastore的初始化sql。 解压hive-0.8.1 之后,可以找到这些metastore初始化sql脚本: ``` ./src/metastore/scripts/upgrade/postgres/hive-schema-0.6.0.postgres.sql ./src/metastore/scripts/upgrade/postgres/hive-schema-0.7.0.postgres.sql ./src/metastore/scripts/upgrade/postgres/hive-schema-0.5.0.postgres.sql ./src/metastore/scripts/upgrade/postgres/hive-schema-0.4.1.postgres.sql ``` 对于相应的hive版本,使用相应的sql即可。对于0.8版本的hive和0.7版本的hive,好像sql是一样的。 所以对于0.8的hive直接使用./src/metastore/scripts/upgrade/postgres/hive-schema-0.7.0.postgres.sql即可 导入sql到postgresql很简单: ``` psql -U hive -d hive -f ./src/metastore/scripts/upgrade/postgres/hive-schema-0.7.0.postgres.sql ``` 然后再进入hive做元数据操作,就再也不死锁了。