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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4776563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:47:44  来源:igfitidea点击:

How do I install the hstore module on PostgreSQL 9.0 (MacPorts install)?

postgresqlmoduleinstallmacports

提问by David Eyk

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/).

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

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

已经发现了一些hstore相关的SQL这里,但我不知道它从何而来,或者是W / PostgreSQL的9.0兼容。

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

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

回答by rpkelly

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

您可以告诉 MacPorts 构建 hstore。就是这样。

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

如果您已经postgresql安装,则需要先卸载它(这不会影响您的数据或用户),因为该install操作不会重新安装已安装的端口。卸载是强制的 ( -f),因为它postgresql91-server是相关的并且会阻止卸载。

sudo port -f uninstall postgresql91

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

编辑 Portfile 并添加hstore到以以下开头的行的列表中set contribs

sudo port edit postgresql91

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

(重新)从源代码显式安装 ( -s) 以构建 hstore 扩展:

sudo port -s install postgresql91

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

然后为每个要使用它的数据库加载一次 hstore:

In >= 9.1: CREATE EXTENSION hstore;

在 >= 9.1 中: CREATE EXTENSION hstore;

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

在 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".

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

回答by Allen

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.

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

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:

编辑:在另一台计算机上安装也不起作用。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

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.

要启用 hstore 扩展,请在您将使用 hstore 的数据库中使用新的“创建扩展”SQL 命令。如果将其安装到 template1 数据库中,则之后创建的所有数据库都将具有 hstore 扩展名。

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)

回答by a_horse_with_no_name

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.

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

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:

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

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

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

回答by sethcall

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

Joey Adam 的解决方案是正确的,但在 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)
  • 我没有使用 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