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

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

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.