如何在 PostgreSQL 9.0 上安装 hstore 模块(MacPorts 安装)?

发布于 2024-10-13 05:10:03 字数 497 浏览 4 评论 0原文

我通过 MacPorts 在我的笔记本电脑上安装了一个可爱的 PostgreSQL 9.0 服务器。我想启用 hstore 模块,但我找不到任何安装这些模块的说明可选模块(我也无法在 /opt/local/share/postgresql90/contrib/ 中找到任何与 hstore 相关的代码)。

已经在这里找到了一些与hstore相关的SQL ,但我不确定它来自哪里,或者它是否与 PostgreSQL 9.0 兼容。

那么,如何在安装了 MacPorts 的 Postgres 9.0 服务器上启用 hstore 模块?

I have a lovely PostgreSQL 9.0 server installed on my laptop via MacPorts. I would like to enable the hstore module, but I can't find any instructions for installing these optional modules (nor can I find any hstore-related code in /opt/local/share/postgresql90/contrib/).

I have found some hstore-related SQL here, but I'm not sure where it comes from or if it's compatible w/ PostgreSQL 9.0.

So, how do I enable the hstore module on my MacPorts-installed Postgres 9.0 server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

高速公鹿 2024-10-20 05:10:03

您可以告诉 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

请注意,此过程适用于 postgresql92,只需将“92”替换为“91”即可。

You can tell MacPorts to build hstore. Here's how.

If you already have postgresql installed, you will need to uninstall it first (this won't touch your data or users) because the install action will not re-install an already installed port. The uninstall is forced (-f) because postgresql91-server is dependent and will prevent uninstall.

sudo port -f uninstall postgresql91

Edit the Portfile and add hstore to the list on the line which begins with set contribs:

sudo port edit postgresql91

(Re)install from source explicitly (-s) to build the hstore extension:

sudo port -s install postgresql91

Then load hstore, once for each of your databases in which you want to use it:

In >= 9.1: CREATE EXTENSION hstore;

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

Note this process works for postgresql92 by just substituting "92" for "91".

甜是你 2024-10-20 05:10:03

看来 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)

It seems that the port for PostgreSQL 9.1 now includes hstore, but it still needs to be enabled. Install and start the database normally.

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

EDIT: Installing in another computer didn't work as well. The hstore was not installed with the base (I may have made it available trying other solutions). So do this BEFORE the load command above:

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

To enable the hstore extension, use the new "create extension" SQL command in the database(s) you will use hstore. If you install it into the template1 database, all databases created afterwards will have the hstore extension.

psql template1 postgres
template1=# create extension hstore;

If you only need the extension in a particular database:

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)
绝對不後悔。 2024-10-20 05:10:03

我不能说适用于 MacOS(或任何 MacPorts),但在 Windows 上,share/contrib 中有一个文件“hstore.sql”,它引用了一个库“hstore.dll”,它是常规发行版的一部分。

这包含在 EnterpriseDB 的一键安装程序中。我假设 MacOS 的一键安装程序也包含该模块:

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

I can't say for MacOS (or whatever MacPorts is), but on Windows there is a file "hstore.sql" in share/contrib and it references a library "hstore.dll" which is part of the regular distribution.

This was included in the one click installer from EnterpriseDB. I would assume that the one click installer for MacOS includes that module as well:

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

鹊巢 2024-10-20 05:10:03

Joey Adam 的解决方案是正确的,但与 postgres 9.1 有点过时:

我做了与他的帖子不同的以下操作:

  • 我没有使用 postgresql-server-devel,而是运行了“sudo port install postgresql91-server”(前者已被替换为后者)
  • contrib/hstore 中的 Makefile 已更新为使用 PGXS(它看起来基本上就像 Joey 上面发布的那样);我不必编辑它。
  • 我确实继续创建了一个符号链接到 /somewhere/in/my/path/pg_config > /opt/local/lib/postgresql91/bin/pg_config,这样 Makefile 就会成功(它期望 pg_config 在你的路径中)
  • 9.1 有不同的方式来处理扩展,例如 hstore;例如,要启用 hstore,我执行了 psql91 [my_schema],然后 >创建扩展 hstore (您可以在此处阅读有关扩展的更多信息 http://developer.postgresql。 org/pgdocs/postgres/sql-createextension.html)

Joey Adam's solution is correct, but has become slightly dated with postgres 9.1:

I did the following differently from his post:

  • Instead of using postgresql-server-devel, I ran 'sudo port install postgresql91-server' (the former has been replaced by the latter)
  • The Makefile in contrib/hstore has been updated to use PGXS (it looks basically just like Joey posted above); I did not have to edit it.
  • I did go ahead and make a sym link to /somewhere/in/my/path/pg_config > /opt/local/lib/postgresql91/bin/pg_config, so that the Makefile would succeed (it expects pg_config in your path)
  • 9.1 has a different way of handling extension such as hstore; for example, to enable hstore, I did psql91 [my_schema], then > create extension hstore (you can read more here about extensions http://developer.postgresql.org/pgdocs/postgres/sql-createextension.html)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文