2

I am doing a project using django rest framework. It was working ok, but at the moment I am getting error

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?

I knew that the problem with postgresql. Because I've tried to connect it with pgadmin, and also gives me this error.
I am using Ubuntu OS, when I checked ubuntu not listening port 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)

When I run service postgresql status, it says following.

● 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.

Here is the output of the 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              [::]:* 

Seems something caused blocked 5432 port. How to solve this problem ?

postgresql.log
enter image description here

mirodil
  • 422
  • 2
  • 8
  • 21
  • I'd rather say that postgres isn't running for some reason. Can you find anything in its logfile? – fvu May 17 '22 at 12:12
  • @fvu thanks for answer, I checked logfile and edited question, can you check it out please. – mirodil May 17 '22 at 15:14
  • 1
    @mirodil What the logs said is that the postgres database server is not starting because the ssl key file does not have the correct permission, the error message is it shelf explanatory. – Adelino Silva May 17 '22 at 15:52
  • Does this answer your question? [PostgreSQL won't start: "server.key" has group or world access](https://stackoverflow.com/questions/12087683/postgresql-wont-start-server-key-has-group-or-world-access) – fvu May 21 '22 at 12:17
  • Follow this: https://stackoverflow.com/a/74163070/14591547 – abdulalim Oct 22 '22 at 11:20

2 Answers2

2

The problem is that /etc directory needs to be root user, so I changed it to root user, and opened 5432 port, in my case /etc directory owned by other user, now everything is working.

mirodil
  • 422
  • 2
  • 8
  • 21
1

See this thread discussion: PostgreSQL won't start: "server.key" has group or world access

Adelino Silva
  • 577
  • 3
  • 16