2011-01-23 137 views
11

我有一臺可愛的PostgreSQL 9.0服務器,通過MacPorts安裝在我的筆記本電腦上。我想啓用hstore module,但我找不到任何安裝這些可選模塊的說明(我也不能在/opt/local/share/postgresql90/contrib/中找到任何與hstore相關的代碼)。如何在PostgreSQL 9.0(MacPorts安裝)上安裝hstore模塊?

發現了一些hstore相關的SQL here,但我不知道它來自哪裏或者是否兼容W/PostgreSQL的9.0。

那麼,如何在MacPorts安裝的Postgres 9.0服務器上啓用hstore模塊?

+0

Checkout @ rpkelly的答案在下面,它是最簡單和最完整的。 – 2012-04-23 03:09:49

回答

20

你可以告訴MacPorts的建立hstore。就是這樣。

如果您已安裝postgresql,則需要先卸載它(這不會觸及您的數據或用戶),因爲install操作不會重新安裝已安裝的端口。強制卸載(-f),因爲postgresql91-server是相關的,並且會阻止卸載。

 
sudo port -f uninstall postgresql91 

編輯Portfile並添加hstore就行列表與set contribs開始:

 
sudo port edit postgresql91 

(再)從源代碼安裝明確(-s)建hstore擴展:

 
sudo port -s install postgresql91 

然後爲您要使用它的每個數據庫加載一次hstore:

在> = 9.1:CREATE EXTENSION hstore;

在9.0:psql -U postgres -f /opt/local/share/postgresql90/contrib/hstore.sql

注意該過程通過只代以 「92」 爲 「91」 適用於postgresql92。

1

我不能說MacOS(或任何MacPorts是),但在Windows上有一個文件「hstore.sql」在共享/ contrib,它引用一個庫「hstore.dll」,這是一部分的常規分配。

這包含在EnterpriseDB的一鍵安裝程序中。我會假設,適用於MacOS的點擊安裝程序包括該模塊以及:

http://www.enterprisedb.com/products-services-training/pgdownload#osx

+0

我可能會嘗試使用EnterpriseDB安裝程序。我似乎無法在MacPorts發行版中找到它。 – 2011-01-23 22:11:13

+0

我不知道MacOS是否與MacPort的二進制兼容,但是有一個「Zip」版本的EnterpriseDB軟件包。它包含一個hstore.so文件和必需的.sql腳本。您可以從這裏獲得:http://www.enterprisedb.com/products-services-training/pgbindownload – 2011-01-23 22:41:20

+0

對不起,MacPorts是MacOS Unixy方面常見的第三方軟件包管理器(與BSD端口項目密切相關, 我相信)。可能是二進制兼容的。我會檢查出來的。 – 2011-01-24 00:59:10

1

喬伊亞當的解決方案是正確的,但已經變得稍微在Postgres 9.1日期:

我做了不同於以下他的職位:

  • 而是使用PostgreSQL服務器-devel的,我跑了 'sudo的港口安裝postgresql91服務器'(前者已取代後者)
  • 在contrib/hstore中的Makefile已更新爲使用PGXS(它看起來基本上就像喬伊上面所述);我不必編輯它。
  • 我做了一個sym連接,並在/ my/path/pg_config>/opt/local/lib/postgresql91/bin/pg_config中創建了一個sym鏈接,以便Makefile成功(它希望在你的路徑中使用pg_config )
  • 9.1有不同的處理擴展名的方法,比如hstore;例如,使hstore,我做psql91 [my_schema],然後>創建擴展hstore(你可以在這裏閱讀更多關於擴展http://developer.postgresql.org/pgdocs/postgres/sql-createextension.html
5

看來,口對PostgreSQL 9.1現在包括hstore,但它仍然需要啓用。正常安裝並啓動數據庫。

sudo port install postgresql91 postgresql91-server 
sudo mkdir -p /opt/local/var/db/postgresql91/defaultdb 
sudo chown postgres:postgres /opt/local/var/db/postgresql91/defaultdb 
sudo su postgres -c '/opt/local/lib/postgresql91/bin/initdb \ 
    -D /opt/local/var/db/postgresql91/defaultdb' 
sudo port load postgresql91-server 

編輯:在另一臺計算機安裝也沒有工作。 hstore沒有安裝基礎(我可能試過其他解決方案)。所以做這個上面負載命令之前:

sudo port unload postgresql91-server # if you did load above 
sudo port build postgresql91 
port work postgresql91 # Gives you base dir for following command 
cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_postgresql91/postgresql91/work/postgresql-9.1.*/contrib/hstore 
sudo make all 
sudo make install clean 
sudo port load postgresql91-server 

要啓用hstore擴展,數據庫中的()你將使用hstore使用新的「創建擴展」 SQL命令。如果將其安裝到template1數據庫中,則後來創建的所有數據庫都將具有hstore擴展名。

psql template1 postgres 
template1=# create extension hstore; 

如果你只需要在一個特定的數據庫擴展:

psql dbname dbuser 
dbname=# create extension hstore; 
create table a (id serial, data hstore); 
NOTICE: CREATE TABLE will create implicit sequence "a_id_seq" for serial column "a.id" 
CREATE TABLE 
dbname=# insert into a(data) values('a=>1, b=>2'); 
INSERT 0 1 
dbname=# SELECT * from a; 
id |  data   
----+-------------------- 
    1 | "a"=>"1", "b"=>"2" 
(1 row)