在 "localhost" 连接到服务器,端口 5432 失败:连接被拒绝 服务器 运行 在该主机上并接受 TCP/IP 连接吗?

connection to server at "localhost" , port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?

我正在使用 django rest 框架做一个项目。它工作正常,但目前我收到错误

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?

我知道是 postgresql 的问题。因为我试图将它与 pgadmin 连接,并且还给了我这个错误。
我正在使用 Ubuntu OS,当我检查 ubuntu 没有监听端口 5432.

postgresql.conf

# - Connection Settings -

listen_addresses = '*'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for >
                                        # (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 >
                                        # (change requires restart)

当我运行service postgresql status时,它说如下。

● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor pr>
     Active: active (exited) since Tue 2022-05-17 09:22:03 +05; 1h 9min ago
    Process: 6270 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 6270 (code=exited, status=0/SUCCESS)

May 17 09:22:03 mirodil-vivobook systemd[1]: Starting PostgreSQL RDBMS...
May 17 09:22:03 mirodil-vivobook systemd[1]: Finished PostgreSQL RDBMS.

这是 ss -nlt 的输出:

State   Recv-Q   Send-Q     Local Address:Port      Peer Address:Port  Process  
LISTEN  0        511            127.0.0.1:40915          0.0.0.0:*              
LISTEN  0        4096       127.0.0.53%lo:53             0.0.0.0:*              
LISTEN  0        5              127.0.0.1:631            0.0.0.0:*              
LISTEN  0        4096           127.0.0.1:9050           0.0.0.0:*              
LISTEN  0        5              127.0.0.1:39261          0.0.0.0:*              
LISTEN  0        5                0.0.0.0:35587          0.0.0.0:*              
LISTEN  0        128              0.0.0.0:25672          0.0.0.0:*              
LISTEN  0        511            127.0.0.1:6379           0.0.0.0:*              
LISTEN  0        511                    *:80                   *:*              
LISTEN  0        4096                   *:4369                 *:*              
LISTEN  0        5                  [::1]:631               [::]:*              
LISTEN  0        511                    *:35711                *:*              
LISTEN  0        128                    *:5672                 *:*              
LISTEN  0        511                [::1]:6379              [::]:* 

似乎有什么东西导致 5432 端口被阻塞。如何解决这个问题?

postgresql.log

查看此主题讨论: PostgreSQL won't start: "server.key" has group or world access

问题是/etc目录需要是root用户,所以我改成了root用户,并打开了5432端口,我的/etc目录属于其他用户,现在一切正常。