Report this

What is the reason for this report?

no pg_hba.conf entry for host \"IP-ADDRESS", user \"username\", database \"database\", SSL off

Posted on August 6, 2020

I am trying to access my managed postgreSQL database from my node.js app which is hosted in Google Cloud. I am getting the above error. I am using pg-promise in my node.js app. How to go about it? Please advise.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello, I believe that you are getting a deny on the connection as the client is not in the pg-hba-conf file, there should be a way to authorize networks/ or a similar thing on from your database provider.

You need to whitelist the IP you are making the request from in /etc/postgresql/9.5/main/pg_hba.conf (be 9.5 the version of you postgresql installation). An example:

host all all 1.2.3.4/32 md5

Where md5 is the trust method, 32 the network mask and 1.2.3.4 the request IP

I am using a Digital Ocean database and while I am not sure what it means, I was able to get around this by using either of two techniques: either disable rejectUnauthorized in ssl, or generate a self-signed certificate (public and private key) and download the CA Certificate from the database and pass those to ssl.

const pool = new Pool({
    host: process.env.PGHOST,
    database: process.env.PGDATABASE,
    user: process.env.PGUSER,
    password: process.env.PGPASSWORD,
    port: process.env.PGPORT,
    ssl: {
	rejectUnauthorized: false
    }
});

I am not sure if either of these is an incorrect solution even though it allowed me to connect and do queries.

https://node-postgres.com/features/ssl https://stackoverflow.com/questions/31861109/tls-what-exactly-does-rejectunauthorized-mean-for-me

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.