1. 程式人生 > >psql could not connect to server

psql could not connect to server

Question: psql connection refused

psql -h 100.80.193.91 -U user -d database -p 5432
#Tips:
psql: could not connect to server: connection refused
   Is the server running on host "100.80.193.91" and accepting
   TCP/IP connections on port 5432?

Answer

ubunutu 18.04 postgresql-server 10
1. Turn on listen_address option in postgresql.conf

cd /etc/postgresql/10/main
sudo vim postgresql.conf
#turn on listen_address  = '*' or add listen_address
listen_addresses = '*'   

2. Add IP address denied access to pg_hba.conf

host    all             all             100.80.193.56/32        md5

3. Don’t forget to restart PostgreSQL

 /etc/init.d/postgresql restart
 #or
 sudo service postgresql restart
 #maybe 
/etc/init.d/postgresql reload