【问题标题】:How do I install the hstore module on PostgreSQL 9.0 (MacPorts install)?如何在 PostgreSQL 9.0(MacPorts 安装)上安装 hstore 模块?
【发布时间】:2013-08-01 22:13:02
【问题描述】:

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

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

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

【问题讨论】:

  • 在下方查看@rpkelly 的回答,这是最简单最完整的。

标签: postgresql module installation macports


【解决方案1】:

您可以告诉 MacPorts 构建 hstore。方法如下。

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

sudo port -f 卸载 postgresql91

编辑端口文件并将hstore 添加到以set contribs 开头的行的列表中:

sudo 端口编辑 postgresql91

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

sudo 端口 -s 安装 postgresql91

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

在 >= 9.1:CREATE EXTENSION hstore;

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

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

【讨论】:

  • 这些是最好/最简单的说明。 @rpkelly:我将它们编辑为首先包括卸载,这在我的设置中是必需的(并且不添加任何步骤或开销,因此看起来是一个安全的选择)。
  • 注意每个数据库一次
  • 适用于尚未包含的任何扩展,例如 xml2
【解决方案2】:

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)

【讨论】:

    【解决方案3】:

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

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

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

    【讨论】:

    • 我可能会尝试使用 EnterpriseDB 安装程序。我似乎在 MacPorts 发行版中找不到它。
    • 我不知道 MacOS 是否与那个 MacPort 东西二进制兼容,但是 EnterpriseDB 包有一个“zip”版本。它确实包含一个 hstore.so 文件和必要的 .sql 脚本。你可以从这里得到:enterprisedb.com/products-services-training/pgbindownload
    • 抱歉,MacPorts 是 MacOS Unixy 端的通用第 3 方包管理器(我相信是 BSD 端口项目的近亲)。可能是二进制兼容的。我去看看。
    【解决方案4】:

    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

    【讨论】:

    • 谢谢。我没有要测试的 9.1,但这是重要信息。
    • 更新:在 Mac 上,我只是从源代码安装。它很有效,很简单,而且我可以完全控制,不必弄清楚如何推动端口来满足我的需要。
    猜你喜欢
    • 2015-04-08
    • 1970-01-01
    • 2021-11-13
    • 2020-09-28
    • 2016-10-15
    • 2012-03-04
    • 1970-01-01
    • 2012-02-25
    • 2018-04-22
    相关资源
    最近更新 更多