By default, PostgreSQL just allows local connections only. To make PostgreSQL accepts remote connections, we have to do some additional steps as below:
1. Basic Steps.
Step 1. Edit the pg_hba.conf, put 1 more line.
1 |
host all all 0.0.0.0/0 md5 |
Step 2. Edit postgresql.conf
Find the key listen_addresses=’localhost’ and change it to:
1 |
listen_addresses='*' |
Step 3. Restart Postgresql or reload the configuration files
2. Location of configuration files and data directory.
We can find PostgreSQL configuration files on the data directory which can be resided in many different places depended on how PostgreSQL was installed.
Generally, for Windows, we can find the data directory in the:
1 |
C:\Program Files\PostgreSQL\[VERSION]\data |
For example, with PostgreSQL 9.4
1 |
C:\Program Files\PostgreSQL\9.4\data |
For Linux, we can find the data directory at:
1 2 3 4 |
/var/lib/pgsql/[VERSION] OR /var/lib/postgresql/[VERSION]/ OR |
To find exactly the location of Data directory and configuration files as well, we can do as below.
Log in PostgreSQL with admin role and execute below commands:
1 |
show data_directory; |
For example:
- 1st command: “su – postgres” to change to postgres account.
- 2nd command: “psql” to execute command line client.
- 3rd command: show data_directory.
- The data directory is showed at: /var/lib/pgsql/9.4/data.
or
1 |
SHOW config_file; |
For example:
Or
1 |
SHOW hba_file; |
On Windows, we can use PostgreSQL client likes PgAdmin, which is a free client tool to access PostgreSQL server.
Here is an example about locating configuration after login to postgres database:
3. Example of configuration files of PostgreSQL accepts remote connections.
The pg_hba.conf file.
The postgresql.conf file.
4. Notes
After changing the configuration files, you should reload configurations file or restart PostgreSQL.
For ex: To reload configuration files on CentOS 7.
1 |
systemctl reload postgresql-9.4.service |