Psycopg2 reporting pg_hba.conf error
Typical explanations include:
You are connecting to the wrong server.
Is the DB server running on the same host as Python does?You got the wrong port.
Check the server log if you see a connection attempt. You have to log connections for that, of course. See the config parameterlog_connections
.You did not reload (SIGHUP) the server after changing
pg_hba.conf
- or reloaded the wrong cluster (if you have multiple DB clusters).
Usepg_ctl
orpg_ctlcluser
on Debian and derivatives for that.
I recently got into this same issue and I found the solution for this problem.
System:
- I have an application server (with these packages installed
python
,django
,psycopg2
andpostgres client 9.6.1
(postgresql-9.6.1.tar.gz
)), for instanceip address 10.0.0.1
(a private address). - And AWS postgres RDS server "
aws_rds_host_name
" or any database IP address.
Error:
django.db.utils.OperationalError: FATAL: no pg_hba.conf entry for host
"10.0.0.1", user "your_user", database "your_db", SSL off
Solution:
While installing the postgres client 9.6.1
source package in application server 10.0.0.1
, we have to pass an argument "--with-openssl
". I suggest to remove the existing the postgres client
and install with below steps.
- Download the
postgres client source package 9.6.1
(postgresql-9.6.1.tar.gz
) - Untar the package
postgresql-9.6.1.tar.gz
. ./configure --prefix="your_preferred_postgres_path_if_needed" --with-openssl (this '--with-openssl'
argument is important to get rid of that error)- make
- make install
- After successful installation, that error didn't occur when we ran the django project with
psycopg2
.
I hope this solution helps someone.