[英]Connection refused for PostgreSQL, cannot restart from status active(exited)
在此先感謝您的幫助。 這是我第一次在這里問一個問題,所以請您原諒。
細節:
我的問題:
我運行了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)
我在這里嘗試了以下指示,並具有以下輸出:
$ 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.
今天遇到同樣的問題。 就我而言,我忘記設置listen_addresses = '*'
。
在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 *:*
因此,就您而言,postgresql沒有監聽5432。愚蠢的主張:您是否嘗試過sudo service postgresql restart
? :)
編輯 :問題已經有一個多月了,您可能可以解決此問題。 如果是,請分享您的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.