Connection refused with postgresql using psycopg2
1. Modify two configure files
# vi /var/lib/pgsql/data/postgresql.conf
Replace the line:
listen_addresses = 'localhost' -> listen_addresses = '*'
# vi /var/lib/pgsql/data/pg_hba.conf
Add the line at the very end:
host all all 0.0.0.0/0 trust
(If IPv6:
host all all ::/0 trust)
2. Restart the database service
# service postgresql restart
3. Disable the firewall
# rcSuSEfirewall2 stop
# chkconfig SuSEfirewall2 off
# chkconfig SuSEfirewall2_init off
Your netstat output shows that postgres is listening on 127.0.0.1
, but your error suggests you are trying to connect to 45.32.1XX.2XX
. I am pretty sure you have already diagnosed your problem.
You will need to modify the listen_addresses
setting your postgresql.conf
file (not pg_hba.conf
). The postgresql.conf
file is found in your postgresql data directory, which is often something like /var/lib/postgresql/data
or /var/lib/pgsql/data
.
The listen_addresses
parameter is documented here.