Report this

What is the reason for this report?

Cannot connect to PostgreSQL db for local development

Posted on June 9, 2020

I am having trouble connecting to a Digital Ocean managed postgres database for local development, a NodeJS API built with Fastify.

I can connect to the database via psql with the connection string provided by the connection details provided in the Overview tab. When I try and connect my API to the database with the same connection string I get the following error:

no pg_hba.conf entry for host <my ip address>, user <username>, database <defaultdb>, SSL off

Even when I add my computer as a trusted source I still cannot connect.

I’ve downloaded the cert provided in the Overview tab, moved it to ~/.postgresql/postgresql.crt and used chmod 600 on the file. Then I get the following when trying to connect with psql:

psql: certificate present, but not private key file ~/.postgresql.key

And still get the no pg_hba.conf error from above when attempting to connect with the Node API I am attempting to develop.

I’ve tried everything I can think of. Pretty much every solution for this error on StackOverflow mentions changing the pg_hba.conf file, but I don’t think that is possible with a managed database.

Please let me know if I need to provide more detail on the problem I am having.

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.