"Server doesn't listen" error connecting to my remote database

Avatar richblockspoorblocks 4 months, 2 weeks ago

I have a Postgres database on a remote server. I fill out this info in pgAdmin.

Name: my-server
Host: SERVER.IP.ADDRESS.HERE
Port: 5432
Maintenance DB: postgres
Username: django
password: mysecretpassword

When I hit "OK" I get this error window.

Server doesn't listen

The server doesn't accept connections: the connection library reports 
could not connect to server: Connection refused Is the server running on host "SERVER.IP.ADDRESS.HERE" and accepting TCP/IP connections on port 5432? 

How do I check what port Postgres runs on in my Linode server, which runs Ubuntu 14.04?

6 Replies

I entered psql on my Linode server and executed this SQL statement: SELECT * FROM pg_settings WHERE name = 'port';. The port number is definitely 5432, so why can't I connect?

Did you set up PostgreSQL for remote access?

If not (or you aren't sure), you can check the listen_address setting in postgresql.conf. It should be set to your public or private IP address.

Depending on your setup, you might also need to grant the PostgreSQL user account with access in the pg_hba.conf file.

Have you seen this? Configure PostgreSQL

Thanks, I uncommented the listen_addresses line and added '*' to it.

listen_addresses = 'localhost','*'

Ran nginx restart but still can't connect. Same error.

Did you restart PostgreSQL?

Since the change you made was to PostgreSQL’s config, restarting Nginx most likely wouldn’t help.

Also, consider granting permissions to your user in pg_hba.conf

Running sudo /etc/init.d/postgresql restart got rid of the error. Now I get a "permission denied" error. How do I edit pg_hba.conf to grant permission to pgAdmin on my local machine?

Added these lines to the file.

host    all             all              0.0.0.0/0                       md5
host    all             all              ::/0                            md5

Works now.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct