Report this

What is the reason for this report?

Trouble connecting to Postgresql DigitalOcean Managed Database via Node.js app

Posted on April 16, 2021

I am using environment variables to connect to by database through a Node.js webapp. When a submit a request to my database I get a 504 Gateway Time-out error. I checked my pm2 logs, and I am getting the following error "no pg_hba.conf entry for host “<myIP>”, user “<myusername>”, database “<mydatabase>”, SSL off.

Here are my environment variables

PGUSER=<myusername> PGHOST=<myhost> PGPASSWORD=<mypassword> PGDATABASE=<mydatabase> PGPORT=<myport> PGSSLMODE=true NODE_ENV=production

All of those are copied from the connection parameters provided to me by digital ocean. The managed database is SSL = require, but when I change PGSSLMODE to =require, I get the following pm2 log error “self signed certificate in certificate chain”.

I also tried setting the connection string provided to me as the environmental variable connection: to see if that would work, but that gave me the following error “connect ECONNREFUSED 127.0.0.1:5432”. My digital ocean managed database is not 5432, which I know is the default Postgres port, so it makes me think that it isn’t seeing that environment variable.

Any help is appreciated, and please let me know if you need more context!

The developer cloud

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

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.