Question

I can't connect to the database on my local machine

I’ve been trying for a week without success. I configured CA on my connection and it still doesn’t work. I did not include any reliable source to leave public access.

The error: error: no pg_hba.conf entry for host “**7.15.139.203”, user “xxxx”, database “xxx”, no encryption

Has anyone been through this?

const dataSource = **new** DataSource({
        type: "postgres",
          host: process.env.DATABASE_HOST,
          port: parseInt(process.env.DATABASE_PORT, 10) || 5432,
          username: process.env.DATABASE_USER,
          password: process.env.DATABASE_PASSWORD,
          database: process.env.DATABASE_NAME,
          entities: [xxxx, xxxxx],
          synchronize: false,
          dropSchema: false,
          logging: false,
          ssl: {
              ca: process.env.CA,
              enableTrace: true,
              rejectUnauthorized: true
          }
      });

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.

Bobby Iliev
Site Moderator
Site Moderator badge
August 23, 2024

Hi there,

Are you using a managed Postgres database cluster? If so, you might also want to try setting rejectUnauthorized: false just to test if it’s an SSL-related issue.

https://docs.digitalocean.com/products/databases/postgresql/how-to/connect/

Also, another thing that you could try is to use Pool from pg instead:

export const pool = new Pool({
    user: process.env.DB_USERNAME,
    host: process.env.DB_HOSTNAME,
    database: process.env.DATABASE,
    password: process.env.DB_PASSWORD,
    port: Number(process.env.DB_PORT),
    ssl: {
       rejectUnauthorized: true,
       ca: process.env.CA_CERT,
    },
})

Let me know how it goes.

- Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more