Question

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

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!


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.

Hi there,

You would indeed need to set the SSL to required, but in order to fix the self-signed certificate error.

You will have to also download the .crt file for your Managed Cluster from your DigitalOcean control panel and add it to your server.

That way your Node application will use the CA certificate and you will not get the SSL error.

Let me know how it goes. Regards, Bobby