By default, only clients running on the same machine as the PostgreSQL database cluster can connect to it. To allow remote clients to connect to the database cluster, alter the PostgreSQL pg_hba.conf configuration file.
Follow the instructions specific to the operating system where PostgreSQL is installed.
PostgreSQL is installed on a Linux server
- Make a backup copy of the pg_hba.conf file before you alter it.
- If the PostgreSQL postmaster is already running, stop it using the pg_ctl stop command.
- Open the pg_hba.conf file in a text editor.
- Add the IP addresses of connecting client machines and the client authentication methods used for connections.
For example, to allow any user who supplies a valid password to connect to a database named habitat from addresses beginning with 10.2.12 using an md5 connection, add the following line to the pg_hba.conf file:
host habitat all 10.2.12.0/24 md5
If you want to allow all users who supply a valid password to connect to any of the databases on the PostgreSQL instance from addresses beginning with 100, you would add a line similar to the following to the pg_hba.conf file:
host all all 100.0.0.0/8 md5
The preceding examples were for IPV4 addresses. If you need to configure the database cluster to accept connections from machines with an IPV6 address, the format would be as follows:
host all all fe60::61f9:1253:c522:9b92%10/128 md5
To allow any machines with an address beginning with fe60 to connect, you would add this line to the pg_hba.conf file:
host all all fe60::0000:0000:0000:0000%10/8 md5
If your PostgreSQL database cluster is set up on a machine that has an IPV6 address and you want machines with an IPV4 address to connect to it, you need to uncomment the following line in the pg_hba.conf file:
host all all ::1/128 md5
- Save and close the pg_hba.conf file.
- Use pg_ctl to start (or restart) the PostgreSQL postmaster.
PostgreSQL is installed on a Windows server
You can either alter the pg_hba.conf file directly by opening it in a text editor, or you can alter the pg_hba.conf file through PgAdminIII.
- Make a backup copy of the pg_hba.conf file before you alter it.
- Open the pg_hba.conf file by doing one of the following:
- Start PgAdminIII, connect to the PostgreSQL instance as the postgres super user, connect to the database, click Tools, point to Server Configuration, then click pg_hba.conf.
- Start Notepad or another text editor application and open the pg_hba.conf file from the PostgreSQL installation directory.
- Add the IP addresses of connecting client machines and the client authentication methods used for connections.
For example, to allow any user who supplies a valid password to connect to a database named habitat from addresses beginning with 10.2.12 using an md5 connection, add the following line to the pg_hba.conf file:
host habitat all 10.2.12.0/24 md5
If you want to allow all users who supply a valid password to connect to any of the databases on the PostgreSQL instance from addresses beginning with 100, you would add a line similar to the following to the pg_hba.conf file:
host all all 100.0.0.0/8 md5
The preceding examples were for IPV4 addresses. If you need to configure the database cluster to accept connections from machines with an IPV6 address, the format would be as follows:
host all all fe60::61f9:1253:c522:9b92%10/128 md5
To allow any machines with an address beginning with fe60 to connect, you would add this line to the pg_hba.conf file:
host all all fe60::0000:0000:0000:0000%10/8 md5
If your PostgreSQL database cluster is set up on a machine that has an IPV6 address and you want machines with an IPV4 address to connect to it, you need to uncomment the following line in the pg_hba.conf file:
host all all ::1/128 md5
- Save the changes you made to the file and close it.