我使用Postgres作为后端数据库来运行Django应用程序。它工作得很好。突然,今天我看到我的数据库连接在生产服务器上被拒绝了。因此,我登录到我的服务器,并尝试:
psql然后它显示了这个错误:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?上面列出的文件似乎不存在。
我使用以下命令检查Postgres是否正在运行:
/etc/init.d/postgresql status它返回了成功消息。
postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Thu 2017-11-16 10:03:41 UTC; 55min ago
Process: 4701 ExecReload=/bin/true (code=exited, status=0/SUCCESS)
Process: 4899 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 4899 (code=exited, status=0/SUCCESS)
Nov 16 10:03:41 median systemd[1]: Starting PostgreSQL RDBMS...
Nov 16 10:03:41 median systemd[1]: Started PostgreSQL RDBMS.尽管如此,我还是停下来重新启动了postgres。
我使用以下命令检查是否有其他postgres任务正在运行:
ps -ef | grep postgres然后它返回了:
root 5210 5117 0 10:21 pts/0 00:00:00 grep --color=auto postgres所以没有其他的Postgres了。
我甚至还检查了我的Postgres是否被意外删除了
dpkg -l | grep postgres然后它又回来了
ii postgresql 9.5+173ubuntu0.1 all object-relational SQL database (supported version)
ii postgresql-9.5 9.5.10-0ubuntu0.16.04 amd64 object-relational SQL database, version 9.5 server
ii postgresql-client-9.5 9.5.10-0ubuntu0.16.04 amd64 front-end programs for PostgreSQL 9.5
ii postgresql-client-common 173ubuntu0.1 all manager for multiple PostgreSQL client versions
ii postgresql-common 173ubuntu0.1 all PostgreSQL database-cluster manager
ii postgresql-contrib-9.5 9.5.10-0ubuntu0.16.04 amd64 additional facilities for PostgreSQL所以没有rc而不是ii,这意味着它还没有被卸载。
除了卸载Postgres之外,我已经尝试了互联网上的所有其他解决方案。对我不起作用。我可能在做一些非常愚蠢的事情。我不想卸载并丢失我的数据。
发布于 2017-11-16 18:47:50
运行以下命令以检查PostgreSQL服务器实际在哪个端口上运行:
[root@server ~]# netstat -a | grep .s.PGSQL
unix 2 [ ACC ] STREAM LISTENING 2534417 /var/run/postgresql/.s.PGSQL.5432从该输出中,我可以看到我的服务器正在监听端口5432,并且该文件是在/var/run/postgresql/.s.PGSQL.5432中创建的
然后,可以更新/etc/init.d/postgresql以包括这些行
PGPORT=5432
export PGPORT并更新位于数据目录中的postgresql.conf文件,并将端口键/值设置为port=5432
然后重新启动您的PostgreSQL服务器
[root@server] service postgresql restarthttps://stackoverflow.com/questions/47327479
复制相似问题