我已经通过 MacPorts 安装了 PostgreSQL,但无法访问它
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3831810/
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
I have installed PostgreSQL via MacPorts, but cannot access it
提问by Anton Egorov
As I said in title, I've installed PostgreSQL usind MacPorts, but cannot access it.
正如我在标题中所说,我已经使用 MacPorts 安装了 PostgreSQL,但无法访问它。
The installation process was
安装过程是
$ sudo port install postgresql83-server
$ sudo mkdir -p /opt/local/var/db/postgresql83/webcraft
$ sudo chown postgres:postgres /opt/local/var/db/postgresql83/webcraft
$ sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/webcraft'
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist
My PATH is
我的路径是
/opt/local/lib/postgresql83/bin:/opt/local/lib/mysql5/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
I try to connect the server using psql client
我尝试使用 psql 客户端连接服务器
$ psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Here is some info
这是一些信息
$ ps ax | grep postgres | grep -v grep
52 ?? Ss 0:00.00 /opt/local/bin/daemondo --label=postgresql83-server --start-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql83-server/postgresql83-server.wrapper start ; --stop-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql83-server/postgresql83-server.wrapper stop ; --restart-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql83-server/postgresql83-server.wrapper restart ; --pid=none
回答by Hassan Shahid
Did you try running:
您是否尝试运行:
which psql
I imagine psql is still referencing /usr/bin/psql
, and the macports version of psql is suffixed with the version number, in your case psql83. You can alias psql to psql83 as a simple workaround. Better would be to change the default:
我想 psql 仍在引用/usr/bin/psql
,并且 psql 的 macports 版本后缀为版本号,在您的情况下为 psql83。您可以将 psql 别名为 psql83 作为一种简单的解决方法。更好的是更改默认值:
sudo port select --set postgresql postgresql83
That will do the proper routing.
这将进行正确的路由。
回答by jdolan
There is a very easy solution to this, but it's not well documented in my opinion:
对此有一个非常简单的解决方案,但我认为它没有得到很好的记录:
MacPorts encourages installing their *_select
ports to manage potentially multiple versions of software (say you want Postgres93 and Postgres94 at the same time). It's a great feature, but it adds an extra step that is for some reason rarely mentioned in the docs:
MacPorts 鼓励安装他们的*_select
端口来管理潜在的多个版本的软件(假设您同时需要 Postgres93 和 Postgres94)。这是一个很棒的功能,但它增加了一个额外的步骤,由于某种原因在文档中很少提到:
$ sudo port install postgresql94-server
Many failed attempts at starting the server later..
稍后启动服务器的许多尝试都失败了..
$ sudo port install postgresql_select
$ sudo port select postgresql
Available versions for postgresql:
none (active)
postgresql94
Well that can't be good!
嗯,这不可能是好事!
$ sudo port select postgresql postgresql94
$ sudo port load postgresql94-server
You're kidding me. Now it's running?
你在逗我。现在运行了吗?
Simply installing Postgres doesn't fully setup symlinks to make it easily runnable. Installing postrgresql_select
gives MacPorts the information it needs to do that via port select
. Once you've selected the active version of your choice, starting the Posgres server via luanchctl
is as easy as port load postgresqlXX-server
.
简单地安装 Postgres 并不能完全设置符号链接以使其易于运行。安装postrgresql_select
为 MacPorts 提供了通过port select
. 一旦您选择了您选择的活动版本,启动 Posgres 服务器luanchctl
就像port load postgresqlXX-server
.
回答by rwl4
I know this is a very late answer and doesn't answer your full question, but launchctl will show different results depending on if you are superuser or not.
我知道这是一个很晚的答案,并没有回答您的完整问题,但是 launchctl 会显示不同的结果,具体取决于您是否是超级用户。
Try doing:
尝试做:
sudo launchctl list | grep postgres
sudo launchctl 列表 | grep postgres
回答by Robert Reiz
I had exactly the same problem on my MacBook Pro. I could resolve the problem after I rode this blog post here and all the comments:
我在 MacBook Pro 上遇到了完全相同的问题。在我将这篇博客文章和所有评论发布到此处后,我可以解决问题:
http://benscheirman.com/2010/06/installing-postgresql-for-rails-on-mac-os-x
http://benscheirman.com/2010/06/installing-postgresql-for-rails-on-mac-os-x
The Problem is that postgres is not really running. I recognized this after I did a port scan to my own machine and realized that nothing is running on Port 5432.
问题是 postgres 并没有真正运行。在对自己的机器进行端口扫描后,我意识到了这一点,并意识到端口 5432 上没有任何运行。
I created a small script "start_pg_server.sh":
我创建了一个小脚本“start_pg_server.sh”:
#!/bin/sh
sudo su postgres -c 'pg_ctl start -D /opt/local/var/db/postgresql83/defaultdb/'
after executing this script the server was running and I could connect me with pgAdmin. I was also able to run my ruby stuff with rake db:create and rake db:migrate.
执行此脚本后,服务器正在运行,我可以使用 pgAdmin 连接我。我还可以使用 rake db:create 和 rake db:migrate 运行我的 ruby 东西。
回答by Moritz
After I restored using Timemachine I had the same problem. The reason was that the permissions were mangled and postgres could not write the pid file. Running this solved it for me:
使用 Timemachine 恢复后,我遇到了同样的问题。原因是权限被破坏,postgres 无法写入 pid 文件。运行它为我解决了它:
sudo chown -R postgres:postgres /opt/local/var/db/postgresql91/
sudo port unload postgresql91-server
sudo port load postgresql91-server
回答by rwl4
Did you by any chance create your postgres user with a shell of /usr/bin/false? If so, the startup script won't work because it uses su which passes commands you send it through the shell.
您是否有机会使用 /usr/bin/false 的外壳创建您的 postgres 用户?如果是这样,启动脚本将无法工作,因为它使用 su 传递您通过 shell 发送的命令。
If you did set it to /usr/bin/false, try changing it to /bin/bash and that might fix things.
如果您确实将其设置为 /usr/bin/false,请尝试将其更改为 /bin/bash,这可能会解决问题。