[英]Connection refused for PostgreSQL, cannot restart from status active(exited)
Thanks in advance for any help. 在此先感谢您的帮助。 This is my first time asking a question here so forgive any blunders.
这是我第一次在这里问一个问题,所以请您原谅。
Details: 细节:
My issue: 我的问题:
I was running migrations for Django 2.1 and encountered this error, despite having run the same command without error for some time now. 我运行了Django 2.1的迁移,但是遇到了此错误,尽管已经运行了相同的命令一段时间了。
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I have established that this is an issue with my PostgreSQL database, but despite my best efforts have hit an impasse. 我已经确定这是我的PostgreSQL数据库的问题,但是尽管我已尽力而为,却陷入了僵局。
Since it seems like an issue with the port, I checked: 由于端口似乎有问题,因此我检查了以下内容:
$ ss -nlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:443 0.0.0.0:*
LISTEN 0 128 127.0.0.1:27017 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
What obviously stands out is this part -- 127.0.0.53%lo:53
-- but I have no idea how to fix it. 显而易见的是这部分
127.0.0.53%lo:53
但我不知道如何解决。 It looks like this is what maybe should read instead 5432... 看起来这是应该改为5432的内容...
My pg_hba.conf file looks like this: 我的pg_hba.conf文件看起来像这样:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
h!
ost replication all ::1/128 md5
My postgresql.conf file looks like this: 我的postgresql.conf文件如下所示:
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
Finally, I have checked my firewall and added port 5432. 最后,我检查了防火墙并添加了端口5432。
5432/tcp (v6) ALLOW Anywhere (v6)
Some other potentially useful error messages: 其他一些可能有用的错误消息:
$ service postgresql status
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Thu 2018-10-11 08:34:35 UTC; 17min ago
Process: 9046 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 9046 (code=exited, status=0/SUCCESS)
I have tried following instructions here , with the following output: 我在这里尝试了以下指示,并具有以下输出:
$ sudo systemctl start postgresql@10-main
Job for postgresql@10-main.service failed because the service did not take the steps required by its unit configuration.
See "systemctl status postgresql@10-main.service" and "journalctl -xe" for details.
$ sudo systemctl status postgresql@10-main.service
● postgresql@10-main.service - PostgreSQL Cluster 10-main
Loaded: loaded (/lib/systemd/system/postgresql@.service; indirect; vendor preset: enabled
Active: failed (Result: protocol) since Thu 2018-10-11 08:42:52 UTC; 25s ago
Process: 9093 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 10-main start (co
Oct 11 08:42:52 billow-droplet-1 postgresql@10-main[9093]: 2018-10-11 08:42:52.396 UTC [9098
Oct 11 08:42:52 billow-droplet-1 postgresql@10-main[9093]: 2018-10-11 08:42:52.396 UTC [9098
Oct 11 08:42:52 billow-droplet-1 postgresql@10-main[9093]: 2018-10-11 08:42:52.396 UTC [9098
Oct 11 08:42:52 billow-droplet-1 postgresql@10-main[9093]: 2018-10-11 08:42:52.396 UTC [9098
Oct 11 08:42:52 billow-droplet-1 postgresql@10-main[9093]: 2018-10-11 08:42:52.398 UTC [9098
Oct 11 08:42:52 billow-droplet-1 postgresql@10-main[9093]: pg_ctl: could not start server
Oct 11 08:42:52 billow-droplet-1 postgresql@10-main[9093]: Examine the log output.
Oct 11 08:42:52 billow-droplet-1 systemd[1]: postgresql@10-main.service: Can't open PID file
Oct 11 08:42:52 billow-droplet-1 systemd[1]: postgresql@10-main.service: Failed with result
Oct 11 08:42:52 billow-droplet-1 systemd[1]: Failed to start PostgreSQL Cluster 10-main.
Ran into the same issue today. 今天遇到同样的问题。 In my case I forgot to set
listen_addresses = '*'
. 就我而言,我忘记设置
listen_addresses = '*'
。
In ss-nlt
I have port 5432 listened: 在
ss-nlt
我监听了端口5432:
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:5432 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 [::]:5432 [::]:*
LISTEN 0 128 *:2377 *:*
LISTEN 0 128 *:7946 *:*
So, in your case, postgresql is not listening 5432. Dumb proposition: have you tried sudo service postgresql restart
? 因此,就您而言,postgresql没有监听5432。愚蠢的主张:您是否尝试过
sudo service postgresql restart
? :) :)
EDIT : question is more than month old, and you, probably, solve this issue. 编辑 :问题已经有一个多月了,您可能可以解决此问题。 If yes, share, pls, your solution.
如果是,请分享您的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.