使用Postgresql遇到的一些問題和解決辦法

最近幫QA的同事新建一臺postgresql測試服務器過程中遇到了些許問題,列舉一下以作備份,也爲以後使用做參考。

1. postgresql 默認的系統yum源裏只有版本爲8.4.18-1.el6_4, 而我需要安裝9.2版本的。

到pgsql官網上去查看,它提供了一個安裝9.2版本的的yum源地址:http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-sl92-9.2-8.noarch.rpm

使用如下命令安裝該源

yum install http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-sl92-9.2-8.noarch.rpm

安裝pgsql-9.2的命令爲

yum install postgresql92-server

即可將包文件 postgresql92-server-9.2.9-1PGDG.rhel6.x86_64 安裝到系統

啓動服務命令爲service postgresql-9.2 start


2. 在導入一個數據庫時出現錯誤"ERROR:  type "hstore" does not exist"

按照網上提示的解決辦法,執行一條SQL語句"create extension hstore;", 但是報另一條錯誤信息

"ERROR:  could not open extension control file "/usr/pgsql-9.2/share/extension/hstore.control": No such file or directory"

進入文件路徑/usr/pgsql-9.2/share/extension/, 發現下面的確沒有hstore.control這個文件,於是懷疑是否有些相關的包文件未安裝齊全,那麼採取暴力一點的辦法,把所有有關postgresql92的安裝包全部裝上,

yum install postgresql92*
postgresql92-libs-9.2.9-1PGDG.rhel6.x86_64
postgresql92-pltcl-9.2.9-1PGDG.rhel6.x86_64
postgresql92-debuginfo-9.2.9-1PGDG.rhel6.x86_64
postgresql92-plpython-9.2.9-1PGDG.rhel6.x86_64
postgresql92-9.2.9-1PGDG.rhel6.x86_64
postgresql92-devel-9.2.9-1PGDG.rhel6.x86_64
postgresql92-contrib-9.2.9-1PGDG.rhel6.x86_64
postgresql92-odbc-09.02.0100-1PGDG.rhel6.x86_64
postgresql92-tcl-2.0.0-1.rhel6.x86_64
postgresql92-test-9.2.9-1PGDG.rhel6.x86_64
postgresql92-odbc-debuginfo-09.02.0100-1PGDG.rhel6.x86_64
postgresql92-jdbc-debuginfo-9.2.1002-1PGDG.rhel6.x86_64
postgresql92-tcl-debuginfo-2.0.0-1.rhel6.x86_64
postgresql92-server-9.2.9-1PGDG.rhel6.x86_64
postgresql92-jdbc-9.2.1002-1PGDG.rhel6.x86_64
postgresql92-plperl-9.2.9-1PGDG.rhel6.x86_64
postgresql92-docs-9.2.9-1PGDG.rhel6.x86_64

然後再進入路徑/usr/pgsql-9.2/share/extension/,該有的文件都有了,再嘗試導入數據庫,未出現剛剛的那個錯誤


3. QA同事在測試服務器上啓動程序時不能連接到數據庫服務器

查看pgsql的配置文件/var/lib/pgsql/9.2/data/postgresql.conf,裏面有相關的選項

 - Connection Settings -
listen_addresses = 'localhost'         # what IP address(es) to listen on;
                                        # defaults to 'localhost'; use '*' for all

原來這樣啓動方式只能玩單機版,局域網的其他服務器不能連接到該數據庫服務器,更改爲

listen_addresses = '*'

另外還有一個配置文件/var/lib/pgsql/9.2/data/pg_hba.conf也需要修改,加入以下參數,允許所有網段訪問該數據庫,也可以特別指定一些網段如192.168.1.0/24等等

# IPv4 local connections:
host    all             all             0.0.0.0/0               trust

重啓pgsql後其他服務器可以連接數據庫


這是目前使用postgresql中遇到的一些問題,還需加強其相關知識的學習才能不斷提高。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章