Report this

What is the reason for this report?

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

Posted on August 20, 2024

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
          }
      });


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!

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,

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

The developer cloud

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

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.