Close

PostgreSQL: Allow Remote Connection to Connect Database

When a client machine tried to connect the PostgreSQL Server, it got an error like “psql:could not connect to server:Connection refused”.
If you need to the connect all clients with PostgreSQL server, you should perform the below two actions.

1. Add client IP-Address ranges into pg_hba.conf :
pg_hba.conf is a configuration file which controls the Client Authentication. This file automatically installed when the data directory is initialized.
Below is a default entry in pg_hba.conf file.

# IPv4 local connections:
host      all        all        127.0.0.1/32      md5
# IPv6 local connections:
host      all        all        ::1/128           md5

Example: The client IP-Address is “10.0.0.12”.
For connecting this client to PostgreSQL Server, add below entry in the pghba.conf and after that save the file and restart PostgreSQL Service.

host    all         all         10.0.0.12/24    md5

2. Change listen_addresses parameter in postgresql.conf :
In the PostgreSQL configuration file (postgresql.conf), by default listen address is ‘localhost’.

listen_addresses = 'localhost'

Change this parameter value from ‘localhost’ to ‘*’ for that all clients can connect from different networks.

listen_addresses = '*'
scroll to top