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

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.

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

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 md5

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