Monday, February 8, 2016

How to Enable Remote Connections to a PostgreDB

The following steps can be followed to enable remote connections to Postgres Database.

1. First set a password for 'postgres' in psql, if there's already a password set, move onto next step.

~]# sudo -u postgres psql

postgres=# \password postgres
postgres=# \q

2. Next, enable Postgres service to listen on all ports. As 'root' user, edit the following file and add the line shown below and save the file. An editor like vi/vim maybe used for this task.

~]# vim /var/lib/pgsql/9.3/data/postgresql.conf

listen_addresses = '*'          # what IP address(es) to listen on;

3. Next step is to modify the Postgres configuration to customize the which hosts are allowed to access the Database remotely. Edit the following file, scroll down to the IPv4 section and add the line shown below. This indicates that Postgres may accept connections from any host. Obviously, this can be customized as per the user's needs.

~]# vim /var/lib/pgsql/9.3/data/pg_hba.conf

host    all             all             0.0.0.0/0               md5

4. Finally, restart the postgres service

~]# service postgresql-9.3 restart

Any tool such as TOAD for Postgres or pgAdmin can be used to connect to the Database.

0 comments:

Post a Comment