Configure PostgreSQL to work for only LOCALHOST or specified ip + port
The easiest way is to make PostgreSQL listen only on localhost
for incoming connections. The relevant parameter is listen_addresses
in postgresql.conf
. The doc is here.
The following pg_hba.conf allows local and specified Ip have privilege login, but reject others。
# TYPE DATABASE USER ADDRESS METHOD
local all all trust
host testdb testuser 192.168.1.1/32 md5
host all all 0.0.0.0/0 reject