Original address: http://blog.chinaunix.net/uid-20684384-id-1895247.html
1. Setting the remote access authentication mechanism
Edit $POSTGRES/data/pg_hba.conf file,
# TYPE DATABASE USER cidr-ADDRESS method# IPv4 local connections:host All 127.0. 0.1/ md5# IPv6 Local connections: #host all ::1 / MD5
Description
Each row has five fields,
# TYPE DATABASE USER cidr-address METHOD
These are: Connection type, available database name, user, DIDR address, and authentication method.
Below, I'll just cover some of the options that are commonly used for each field.
Field One: TYPE.
You can choose: local or host.
# TYPE DATABASE USER cidr-ADDRESS method# allows IP to be 192. 168.0 192.168. 0.1/ md5# allows users to testuser in 192. 168.0 192.168. 0.1/ MD5
2. Change the Listening address
By default, PostgreSQL only accepts local services, to accept remote services, you need to change the postgresql.conf file listen_address = *
3. If PostgreSQL is on Linux
To open the TCPIP socket for UNIX.
Edit $POSTGRES/data/postgresql.conf file,
Change the Tcpip_socket=off to Tcpip_socket=on.
The former allows only local users to log in to the Postgres database, which can accept remote client logins. So
We should use "host".
Field two: Datwabse.
Connect the database name that the user can use. Can make the Postgres a concrete
Database name, or you can use "all" to allow users to access all databases.
Field three: USER. You can specify a specific user to connect to the Postgres database (and also to combine the following address fields).
You can also use "all" to allow all users to connect to the database.
Field four: Didr-address.
This may be confusing to you and not knowing what it is.
In fact, it is just another way to express the IP address and mask.
Postgres is this field to understand, allowing those IP or IP segments to connect to this server.
It is in the format: IP address/mask.
This mask and subnet mask is a good idea, except that it is represented by a positive number less than or equal to 32.
Represents the height of the subnet mask is 1,
For example, 255.255.255.0 is "24", indicating that the high 24 bits are 1.
192.168.0.1/32 is equivalent to IP 192.168.0.1, subnet mask is 255.255.255.255 network segment,
It is clear that this only shows 192.168.0.1IP itself.
If you do not know the IP address and subnet mask, please check the relevant information.
Field five: METHOD.
This is the validation method. The following options are available:
Reject: Deny user access to this IP;
MD5: password with MD5 as hash code;
Password: password as plaintext transmission (good horror!);
KRB5: Password is encoded with krb5 as hash.
Here's an example to illustrate how to set up:
Postgresql Remote Connection Configuration