在此先感谢您的帮助。这是我第一次在这里问一个问题,所以请原谅。
详细信息:
我的问题:
我正在为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?
我已经确定这是我的PostgreSQL数据库的问题,但是尽管我已尽力而为,却陷入了僵局。
由于似乎端口有问题,所以我检查了:
$ 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 [::]:*
显然最突出的是这部分-127.0.0.53%lo:53
-但我不知道如何解决。看来这应该改为5432 ...
我的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
我的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
最后,我检查了防火墙并添加了端口5432。
5432/tcp (v6) ALLOW Anywhere (v6)
其他一些可能有用的错误消息:
$ 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)
我尝试按照here的说明进行操作,并显示以下输出:
$ 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.
答案 0 :(得分:0)
今天遇到了同样的问题。
就我而言,我忘记设置WaveFormat
。
在listen_addresses = '*'
中,我监听了端口5432:
ss-nlt
因此,在您的情况下,postgresql没有监听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 *:*
吗? :)
编辑:这个问题已有一个多月了,您很可能可以解决此问题。如果是,请分享您的解决方案。