pg-native error, certificate could not be obtained, no SSL error reported

Hi, We have our ubuntu server in Digital Ocean and our postgresql database is AWS RDS. Our app is nodejs based and we are using pg-native module for postgres interface from nodejs. When we try connecting using psql, it is working fine, but when we try using pg-native connectSync api, the error is “port 5432 failed: certificate could not be obtained: no SSL error reported”. We are using pg-native and sync variants of api as we need synchronous execution. Request the community help in resolving this. Thanks.

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 20, 2023

Hi there,

There are a few things that I could suggest here:

  1. Make sure your connection string is properly configured to use SSL. You might want to include sslmode and other related options:

    const conString = "postgres://username:password@host:5432/dbname?sslmode=require";
    const client = new pg.native.Client(conString); client.connectSync();
  2. Sometimes, the issue might be related to an outdated version of pg-native or the underlying libpq library. Update them to the latest stable version if they’re not already updated.

  3. You may need to include the AWS RDS SSL root certificate in your connection configuration. You can download the RDS root certificate from the Amazon documentation.

    Here is an example of how you might include it in your connection:

    const conString = "postgres://username:password@host:5432/dbname?ssl=true&sslmode=require&sslrootcert=path/to/rds-combined-ca-bundle.pem";
    const client = new pg.native.Client(conString);

If this still does not work, can you share the Node.js code snippet that you are using to establish the connection?

Alternatively, I could suggest using a Managed Postgres Database with DigitalOcean instead of an AWS RDS instance. This would also benefit the speed of your application as it will reduce the network latency for every single database connection that your application will make.



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
DigitalOcean Cloud Control Panel