【问题标题】:How to install PostgreSQL on OSX Yosemite using MacPorts如何使用 MacPorts 在 OSX Yosemite 上安装 PostgreSQL
【发布时间】:2015-04-08 22:39:03
【问题描述】:

我想为我在OSX Yosemite 中开发的节点项目安装PostgreSQL。我使用 MacPorts,所以尝试了这里描述的方法:https://github.com/codeforamerica/ohana-api/wiki/Installing-PostgreSQL-with-MacPorts-on-OS-X

...但在第 2 步中出现错误:

$ sudo gem install pg -- --with-pg-config=/opt/local/lib/postgresql93/bin/pg_config > ruby_error
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-pg-config=/opt/local/lib/postgresql93/bin/pg_config
Using config values from /opt/local/lib/postgresql93/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

...考虑到我可能不需要安装 pg gem,因为我想使用 Node 而不是 Ruby,我继续进行下一步。但是在第 3.3 步中我遇到了一个错误:

$ sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb'
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
The program "postgres" is needed by initdb but was not found in the
same directory as "initdb".
Check your installation.

...检查我的 /opt/local/lib/postgresql93/bin/ 目录,我看到了 initdbpostgres。我看到那些行说Permission denied,我想知道那是什么意思。

不知道如何进行。考虑使用 Postgres.app 如果它真的更容易但不确定使用 MacPorts 安装是否更好,因为我使用 MacPorts 安装大多数其他东西。感谢您提供有关我的任何问题的提示!

【问题讨论】:

  • 你似乎比指南做的更多;有原因吗?编辑:另外,我们可以看到 mkmf.log 吗?
  • 我最终安装了 PostgresApp,但我认为你是对的,我的 sudo-ing 超出了必要的范围。一旦我回到这个项目,我会带着你要求的信息回来。

标签: postgresql osx-yosemite macports


【解决方案1】:

我在尝试运行 initdb 时遇到了同样的问题,即使遵循 Ian Gow 的描述:

$ sudo su postgres -c '/opt/local/lib/postgresql94/bin/initdb -D /opt/local/var/db/postgresql94/defaultdb'
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
The program "postgres" is needed by initdb but was not found in the
same directory as "initdb".
Check your installation.

事实证明,如果您试图让它从您自己的主目录中运行命令,用户 postgres 将无法执行任何操作,因为在那里 postgres 不允许读取自己的位置,因此无法找出任何其他位置路径,要么。所以简单的解决方案是在任何必须以postgresinitdbpg_ctl 等)运行的命令之前运行cd /。之后,您可以使用cd - 快速跳回之前的工作目录。

【讨论】:

  • 对我来说就是这么简单。我试图在重置后设置 Profile Manager 备份。 cd / 是我需要的技巧。谢谢你。我离重建我的整个 Mac 服务器只有很短的时间了。
【解决方案2】:

/defaultdb 之间的目录的权限/所有权可能需要修复。我认为 PostgreSQL 可能对这些的所有权很敏感,尽管在你的情况下 PostgreSQL 似乎根本无法访问这些。这是我为每个目录所拥有的。

$ ls -hlt /opt/local/var/db/
total 0
drwxr-xr-x  7 root  admin   238B Jan 23 16:54 texmf
drwxr-xr-x  3 root  admin   102B Dec 25 07:37 postgresql94

您可以根据需要通过sudo chmod a+rx /opt/local/var/db/ 来修复权限。

对于defaultdb 目录本身,您应该按照您链接到的说明进行操作,这些说明似乎与我的相同:

sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb

以下是改编自我的blog 的说明(尽管我建议使用 PostgreSQL 9.4,我现在这样做)。自 9.1 以来,我一直使用 MacPorts 运行 PostgreSQL,没有出现重大问题。

1。使用 MacPorts 安装 PostgreSQL。

当然,我假设你的系统上已经安装并运行了 MacPorts。

sudo port install postgresql93 +perl +python27
sudo port install postgresql93-server

2。设置 PostgreSQL

我首先需要初始化数据库集群,然后让服务器运行。以下内容直接来自 MacPorts 端口postgresql93-server 提供的屏幕说明。

sudo mkdir -p /opt/local/var/db/postgresql93/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb'

请注意,MacPorts 会创建一个启动守护程序。要立即加载它并确保它在系统启动时启动,请执行以下操作:

sudo defaults write /Library/LaunchDaemons/org.macports.postgresql93-server.plist Disabled -bool false
sudo launchctl load /Library/LaunchDaemons/org.macports.postgresql93-server.plist

然后我使用psql 进行一些设置以使我的 数据库正常运行。

sudo su - postgres
/opt/local/lib/postgresql93/bin/psql -U postgres -d template1

如果你到了这里,那么你的系统上已经运行了 PostgreSQL。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多