Sunday, March 3, 2013

PostgreSQL: Listen to remote connection

By default postgres does not allow accessing via ip address, you can only access with localhost. If you try to access with ip address, you will get the error message like this: (assume that = localhost)
$ psql -h dbname
psql: could not connect to server: Connection refused
Is the server running on host "" and accepting
TCP/IP connections on port 5432?
To allow connection via ip address, you need to add that ip address to listen_addresses config. Here's how to do that:
  1. Open file postgresql.conf (the location of the file depend on OS and installed place)
  2. Look for listen_addresses
  3. Uncomment the line
  4. Add ipaddress that you want postgres to listen on inside the same single quote with 'localhost'. Like this listen_addresses = 'localhost,'
  5. Restart postgres server (again depend on your OS on how to restart service)
  6. Now, you should be able to access it with "-h ipaddress". Such as psql -h dbname

No comments:

[PostgreSQL] How to create read-only standby replica (follower)

This link  and this link explain it really well and concise