我已通过 MacPorts 安装了 PostgreSQL,但无法访问它

发布于 2024-09-25 21:57:46 字数 1374 浏览 3 评论 0原文

正如我在标题中所说,我已经使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

幸福丶如此 2024-10-02 21:57:46

您是否尝试运行:

which psql

我想 psql 仍在引用 /usr/bin/psql,并且 psql 的 macports 版本带有版本号后缀,在您的情况下为 psql83。您可以将 psql 别名为 psql83 作为简单的解决方法。更好的方法是更改​​默认值:

sudo port select --set postgresql postgresql83

这将进行正确的路由。

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:

sudo port select --set postgresql postgresql83

That will do the proper routing.

够钟 2024-10-02 21:57:46

有一个非常简单的解决方案,但在我看来,它没有得到很好的记录:

MacPorts 鼓励安装其 *_select 端口来管理潜在的多个版本的软件(假设您同时想要 Postgres93 和 Postgres94) )。这是一个很棒的功能,但它增加了一个额外的步骤,由于某种原因在文档中很少提到:

$ sudo port install postgresql94-server

稍后启动服务器的许多失败尝试..

$ sudo port install postgresql_select
$ sudo port select postgresql
Available versions for postgresql:
    none (active)
    postgresql94

好吧,这可不是什么好事!

$ sudo port select postgresql postgresql94
$ sudo port load postgresql94-server

你在开玩笑吧。现在跑起来了?

简单地安装 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:

$ 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.

梦里寻她 2024-10-02 21:57:46

我知道这是一个很晚的答案,并且没有回答您的完整问题,但 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

巡山小妖精 2024-10-02 21:57:46

我在 MacBook Pro 上遇到了完全相同的问题。在我在这里阅读这篇博客文章和所有评论后,我可以解决问题:

http://benscheirman.com/2010/06/installing-postgresql-for-rails-on-mac-os-x

问题是 postgres 并没有真正运行。在对自己的机器进行端口扫描并意识到端口 5432 上没有任何东西运行后,我认识到了这一点。

我创建了一个小脚本“start_pg_server.sh”:

#!/bin/sh
sudo su postgres -c 'pg_ctl start -D /opt/local/var/db/postgresql83/defaultdb/'

执行此脚本后,服务器正在运行,我可以使用 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":

#!/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.

请持续率性 2024-10-02 21:57:46

当我使用 Timemachine 恢复后,我遇到了同样的问题。
原因是权限被破坏,postgres无法写入pid文件。
运行这个为我解决了这个问题:

sudo chown -R postgres:postgres /opt/local/var/db/postgresql91/
sudo port unload postgresql91-server
sudo port load postgresql91-server

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:

sudo chown -R postgres:postgres /opt/local/var/db/postgresql91/
sudo port unload postgresql91-server
sudo port load postgresql91-server
晚雾 2024-10-02 21:57:46

您是否有机会使用 /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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文