Using: 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 “192.168.0.6″ and accepting TCP/IP connections on port 5432?
Well, it was running but obviously not accepting connections. Let’s change that.
Get some super user privileges
sudo -s
Find the location of pg_hba.conf (Client Authentication Configuration File)
find / -type f -name “pg_hba.conf”
Mine was located here: /opt/local/var/db/postgresql90/defaultdb/pg_hba.conf
Change directory to where it’s located and edit it:
cd /opt/local/var/db/postgresql90/defaultdb/
vim pg_hba.conf
Add the following line where x.x.x.x is the email 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
…and change the line:
- listen_addresses = ‘localhost’ (note, it might be commented out with a #, remove it if so)
to…
- listen_addresses = ‘*’
Restart PostgreSQL and try connecting again from the client machine.