PostgreSQL gives me "connection refused" even if "listen_addresses = '*'"

Viewed 992

I have a new DigitalOcean Droplet where I set up a Postgres Database that I am trying to access from my local machine (via pd.read_sql_query). I have not been able to establish a connection with the Droplet, and I have no idea where I'm in the wrong. I've changed both my pg_config and pg_hba files and restarted my psql server.

Here is my pg_hba file:

enter image description here

Here is my pg_config:

enter image description here

Here is the output on my Droplet when I run

netstat -nlt

enter image description here

My theory is that for some reason port 5432 is only listening for local connections. For reference here is the output for ls_pgclusters:

enter image description here

Lastly here is the output I get when I try to connect to the server:

C:\WINDOWS\system32>psql -h xxx.xx.xxx.xxx -p 5432 -d dbName -U postgres
psql: error: could not connect to server: Connection refused (0x0000274D/10061)
        Is the server running on host "xxx.xx.xxx.xxx" and accepting
        TCP/IP connections on port 5432?

I don't know what else there is to do to connect to the server. Any help would be greatly appreciated.

1 Answers

You changed listen_addresses to *, but you forgot to remove the comment (#) at the beginning of the line, so the parameter is still at its default value localhost.

Remove the # and restart PostgreSQL.

Related