我已通过 MacPorts 安装了 PostgreSQL,但无法访问它
正如我在标题中所说,我已经使用 MacPorts 安装了 PostgreSQL,但无法访问它。
安装过程是
$ 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
我的路径是
/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
我尝试使用 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"?
这里是一些信息
$ 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
As I said in title, I've installed PostgreSQL usind MacPorts, but cannot access it.
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: 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您是否尝试运行:
我想 psql 仍在引用
/usr/bin/psql
,并且 psql 的 macports 版本带有版本号后缀,在您的情况下为 psql83。您可以将 psql 别名为 psql83 作为简单的解决方法。更好的方法是更改默认值:这将进行正确的路由。
Did you try running:
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:That will do the proper routing.
有一个非常简单的解决方案,但在我看来,它没有得到很好的记录:
MacPorts 鼓励安装其
*_select
端口来管理潜在的多个版本的软件(假设您同时想要 Postgres93 和 Postgres94) )。这是一个很棒的功能,但它增加了一个额外的步骤,由于某种原因在文档中很少提到:稍后启动服务器的许多失败尝试..
好吧,这可不是什么好事!
你在开玩笑吧。现在跑起来了?
简单地安装 Postgres 并不能完全设置符号链接以使其轻松运行。安装
postrgresql_select
为MacPorts提供了通过port select
执行此操作所需的信息。一旦您选择了所需的活动版本,通过luanchctl
启动 Posgres 服务器就像port load postgresqlXX-server
一样简单。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:Many failed attempts at starting the server later..
Well that can't be good!
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 viaport select
. Once you've selected the active version of your choice, starting the Posgres server vialuanchctl
is as easy asport load postgresqlXX-server
.我知道这是一个很晚的答案,并且没有回答您的完整问题,但 launchctl 会根据您是否是超级用户显示不同的结果。
尝试执行以下操作:
sudo launchctl list | grep postgres
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.
Try doing:
sudo launchctl list | grep postgres
我在 MacBook Pro 上遇到了完全相同的问题。在我在这里阅读这篇博客文章和所有评论后,我可以解决问题:
http://benscheirman.com/2010/06/installing-postgresql-for-rails-on-mac-os-x
问题是 postgres 并没有真正运行。在对自己的机器进行端口扫描并意识到端口 5432 上没有任何东西运行后,我认识到了这一点。
我创建了一个小脚本“start_pg_server.sh”:
执行此脚本后,服务器正在运行,我可以使用 pgAdmin 连接我。我还可以使用 rake db:create 和 rake db:migrate 运行我的 ruby 东西。
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:
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.
I created a small script "start_pg_server.sh":
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.
当我使用 Timemachine 恢复后,我遇到了同样的问题。
原因是权限被破坏,postgres无法写入pid文件。
运行这个为我解决了这个问题:
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:
您是否有机会使用 /usr/bin/false 的 shell 创建 postgres 用户?如果是这样,启动脚本将无法工作,因为它使用 su 来传递您通过 shell 发送的命令。
如果您确实将其设置为 /usr/bin/false,请尝试将其更改为 /bin/bash,这可能会解决问题。
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.
If you did set it to /usr/bin/false, try changing it to /bin/bash and that might fix things.