Configure PostgreSQL to accept TCP/IP connections

Stack: MacPorts PostgreSQL 9.x on OS X 10.6 (Snow Leopard)

After switching to a new Mac, I didn't have time to reinstall and setup PostgreSQL. I decided to access PostgreSQL on my old machine over the network. When I tried to connect, I hit the following error:

psql: could not connect to server: Connection refused
Is the server running on host "" and accepting TCP/IP connections on port 5432?

Well, it was running but obviously not accepting connections. Let's change that.

Get some superuser privileges and find the location of pg_hba.conf (Client Authentication Configuration File)

$ sudo -s
$ find / -type f -name "pg_hba.conf"

Change directory to where it's located and edit:

$ cd /opt/local/var/db/postgresql90/defaultdb/
$ vim pg_hba.conf

Add the following line where x.x.x.x is the ip address of the client machine:

host all all x.x.x.x/24 trust

Now edit postgresql.conf (PostgreSQL configuration) that's located in the same directory.

$ vim postgresql.conf

Wildcard the listen address:

listen_addresses = '*'

Restart PostgreSQL and try connecting again from the client machine.

Moz Morris

Moz Morris

Freelance Web Developer