Postgress connection with ssl enabled

How can I connect to postgresSQL with SSL enabled? I want to pass a certificate.

To connect to PostgreSQL with SSL enabled and pass a certificate in Node.js using the pg package:

Install the pg package: npm install pg

Import the pg module: const { Client } = require(‘pg’);

Set up the connection configuration object with the necessary details and SSL configuration, including the paths to the certificate files.

Create a new PostgreSQL client using the connection configuration: const client = new Client(connectionConfig);

Connect to the PostgreSQL server using client.connect().

Perform your desired database operations using the client.

Disconnect from the PostgreSQL server using client.end().

Ensure that the PostgreSQL server is configured to accept SSL connections and provide the correct paths to the certificate files in the connectionConfig object.

Regards,
Rachel Gomez

1 Like

ERRO[0000] GoError: Module specifier “pg” was tried to be loaded as remote module by prepending “https://” to it, which didn’t work. If you are trying to import a nodejs module, this is not supported as k6 is not nodejs based. Please read Modules for more information. Remote resolution error: “Get “https://pg”: dial tcp: lookup pg: no such host”

Any thoughts?