我正在使用
MacPorts,并且在使用苹果公司的
Migration Assistant迁移至新机器后,db服务器不可用:
psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (::1), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
我尝试过
sudo port load postgresql14-server
但是那并没有起作用。然而查看/Library/LaunchDaemons/org.macports.postgresql14-server.plist
文件,发现了两件事:
<key>Disabled</key><true/>
以及实际的启动命令
<string>--start-cmd</string>
<string>/opt/local/etc/LaunchDaemons/org.macports.postgresql14-server/postgresql14-server.wrapper</string>
因此,手动运行启动命令最终显示了问题:
> sudo /opt/local/etc/LaunchDaemons/org.macports.postgresql14-server/postgresql14-server.wrapper start
pg_ctl: could not open PID file "/opt/local/var/db/postgresql14/defaultdb/postmaster.pid": Permission denied
而且:
> sudo ls -la /opt/local/var/db/postgresql14/defaultdb/
total 60
drwx------ 26 postgres postgres 832 Jan 31 05:13 .
drwxr-xr-x 4 postgres postgres 128 Feb 5 12:31 ..
-rw------- 1 500 postgres 3 Nov 7 2021 PG_VERSION
drwx------ 22 500 postgres 704 Feb 4 10:37 base
drwx------ 60 500 postgres 1920 Feb 4 10:37 global
drwx------ 2 500 postgres 64 Nov 7 2021 pg_commit_ts
...
-rw------- 1 500 postgres 105 Jan 31 05:13 postmaster.pid
用户ID出了问题。修复方法:
sudo chown -hR postgres /opt/local/var/db/postgresql14/defaultdb/
将所有文件的所有者设置为postgres
。
有了这个更改,服务器可以工作:
> sudo /opt/local/etc/LaunchDaemons/org.macports.postgresql14-server/postgresql14-server.wrapper start
pg_ctl: another server might be running
waiting for server to start.... done
server started
> psql -U postgres -W -p 5432 -h localhost
Password:
psql (14.6)
Type "help" for help.
postgres=
\q