After the PostgreSQL database is installed, the default is to accept only local access connections. If you want to access the PostgreSQL database server on a different host, you need to configure it accordingly.
The steps to configure the remote connection PostgreSQL database are simple and only need to modify the pg_hba.conf and postgresql.conf configuration files in the data directory.
pg_hba.conf : Configure access to the database;
postgresql.conf : configures the appropriate parameters for the PostgreSQL database server.
Here are the steps for a specific configuration:
First, modify the pg_hba.conf file , configure the user's access rights (#开头的行是注释内容):
- # TYPE DATABASE USER cidr-address METHOD
- # "Local" is for Unix domain sockets connections only
- Local all All trust
- # IPV4 Local connections:
- Host All 127.0.0.1/32 Trust
- Host All 192.168.1.0/24 MD5
- # IPV6 Local connections:
- Host all:: 1/128 Trust
7th is the newly added content that allows all hosts on the network segment 192.168.1.0 to access the database using all legitimate database usernames and provide encrypted password authentication.
Where the number 24 is the subnet mask, which means that the 192.168.1.0--192.168.1.255 computer is allowed access!
Modify the postgresql.conf file to modify the listening mode of the database server to listen for connection requests made by all hosts.
Navigate to #listen_addresses = ' localhost '. After the PostgreSQL installation is complete, only connection requests from native localhost are accepted by default .
Remove the line start # and modify the line content to Listen_addresses = ' * ' To allow the database server to listen for connection requests from any host!
In this case, PostgreSQL will allow remote access to the ~
PostgreSQL Allow remote Access setting method