How to set up PostgreSQL remote access in Linux

  
                

The PostgreSQL database is installed in Linux Hill, but it can only be accessed locally. If you want to implement remote access, you need to set it manually. The following small series will introduce you to the method of setting up PostgreSQL remote access in Linux. Let's take a look at it.

After installing PostgreSQL database, the default is to only accept local access connection. If you want to access the PostgreSQL database server on other hosts, you need to configure accordingly.

The steps to configure a remote connection to a PostgreSQL database are as simple as modifying pg_hba.conf and postgresql.conf in the data directory.

pg_hba.conf: Configure access to the database,

postgresql.conf: Configure the corresponding parameters of the PostgreSQL database server.

Steps:

1. Modify the pg_hba.conf file to configure the user's access rights (the line at the beginning of # is the comment content):

# TYPE DATABASE USER CIDR-ADDRESS METHOD

# “local” is for Unix domain socket connections only

local all all trust

# IPv4 local connections:

host all all 127.0 .0.1/32 trust

host all all 192.168.1.0/24 md5

# IPv6 local connections:

host all all ::1/128 trust

Among them, the seventh clause is the newly added content, which means that all hosts on the network segment 192.168.1.0 are allowed to access the database using all valid database user names, and provide encrypted password verification.

Among them, the number 24 is a subnet mask, which means that the computer access of 192.168.1.0--192.168.1.255 is allowed!

2. Modify the postgresql.conf file to modify the listening mode of the database server to listen for connection requests from all hosts.

Navigate to #listen_addresses=’localhost’. After the PostgreSQL installation is complete, the default is to only accept connection requests from the localhost.

Remove the beginning of the line #, modify the line content to listen_addresses=’*‘ to allow the database server to listen for connection requests from any host

The above is the Linux setting PostgreSQL remote access The method is introduced. If you don't set it, PostgreSQL can only be local to the default, and the function is limited.

Copyright © Windows knowledge All Rights Reserved