在Mac上启动Postgres服务器

24 浏览
0 Comments

在Mac上启动Postgres服务器

我已经遇到了第三或第四次这样的问题:在重启我的Mac(Yosemite及以前的OSX版本都是如此)后,postgres服务器无法启动。我是按照这个链接安装了我的postgres。任何理由能够说明为什么每次重启后都会发生这种情况吗?

输入 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"?

admin 更改状态以发布 2023年5月24日
0
0 Comments

在Mac上启动Postgres服务器:

使用Brew安装Postgres

brew install postgres

确保您对/ usr / local / postgres具有许可权

sudo chown -R `whoami` /usr/local

然后初始化数据库:

initdb / usr / local / var / postgres

使launchd在登录时启动PostgreSQL:

ln -sfv / usr / local / opt / postgresql / * .plist〜/ Library / LaunchAgents

加载postgresql:

launchctl load〜/ Library / LaunchAgents / homebrew.mxcl.postgresql.plist

检查您的版本:

psql --version

访问Postgres

psql -d postgres

0
0 Comments

我在我的mac上解决了这个问题。我使用homebrew安装postgres。以下是我采取的步骤来重新运行程序:

首先检查postgresql服务的状态:

pg_ctl -D /usr/local/var/postgres status

如果看到这个消息pg_ctl: no server running,请卸载启动代理:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

然后移动你现有的postgres数据(移动而不是删除-廉价的保险):

mv /usr/local/var/postgres /usr/local/var/postgres-deletemewhenitsallgood

接着初始化你的postgres数据库:

initdb /usr/local/var/postgres -E utf8

然后载入你的启动代理:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

或启动它:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

现在再次检查状态:

pg_ctl -D /usr/local/var/postgres status

如果看到类似这样的消息,则表示运行正常。

pg_ctl: server is running (PID: 61295)
/usr/local/Cellar/postgresql/bin/postgres "-D" "/usr/local/var/postgres"

然后你就可以进入你的postgres数据库了:

psql -d postgres

此外,在此之后你需要添加postgress Role。请查看解决缺少postgres角色错误问题

0