Record all the steps to enable remote access by Postgresql

  • 2020-05-06 11:56:42
  • OfStack

Preface to

After installing the PostgreSQL database, the default is to accept only local access connections. If you want to access the PostgreSQL database server on another host, you need to configure it accordingly. The following words do not say much, to see the detailed introduction together.

steps are as follows:

To allow remote access in Postgresql, you need to set up two files :

postgresql.conf pg_hba.conf

However, since the system was installed with Centos 7 and the default Postgresql version was 9.2, a version 9.6 was installed, only to find that it could not be accessed remotely when configured. The default path cannot find the above two files. At this time, you can check the path of their corresponding files in the following way :

dog=# show config_file; 
(1 row) 
dog=# show hba_file; 
(1 row) 

Other configurations can be viewed via show all.

First we configure pg_hba.conf and set the locally accessible IP address range :

host all all  trust 
host all all md5 

Here we run through host access.

Then modify the postgresql.conf file :


Replace localhost with * and remove the comment.

Then restart the server and view the IP:
it is listening to in the following way

dog@debian:~$ sudo netstat -plunt | grep postgres 
tcp  0  0 :5432*    LISTEN  787/postgres  
tcp6  0  0 ::1:5432    :::*     LISTEN  787/postgres 

In the remote case, you will see an asterisk instead of

Reference articles: https: / / www postgresql. org docs / 9.3 / static sql - show. html


Related articles: