VK Cloud logo

Using the TLS protocol to connect to PostgreSQL

The TLS (Transport Layer Security) protocol is used to protect connections between the client and the PostgreSQL server. It encrypts the transmitted data, preventing interception and unauthorized access.

PgBouncer is used to optimize connections. It manages a connection pool, reusing connections and reducing the number of active connections to PostgreSQL. This reduces the load on the server, speeds up query execution, and prevents resource overload with a large number of clients.

This instruction will help you:

  • configure a secure connection to connect to the PostgreSQL server;
  • run the PgBouncer extension on the PostgreSQL server to optimize connections;
  • adjust the query to the PostgreSQL DB on the client;
  • connect the PgBouncer load balancer extension.

Preparation steps

  1. Create a Postgresql DB instance, if this has not been done earlier.
  2. Make sure the database instance is running.

1. Configure a secure connection on the PostgreSQL server

  1. In the VK Cloud management console, go to the Databases → Database instances section.

  2. Click the instance name.

  3. Go to the Database parameters → Add parameter tab

  4. Select the ssl parameter from the list and set the parameter value to on.

  5. Click Save and confirm the action.

    After that, the database instance will restart.

2. (Optional) Connect the PgBouncer load balancer extension

  1. Go to the Extensions → Add tab.

  2. Select pooler from the drop-down list of extensions.

  3. Set the main parameters of the extension.

    • pool_mode: select a connection management mode or keep the default value.
    • max_client_conn: set a limit on the number of client connections to prevent the load balancer from being overloaded, or keep the default value.
    • listen_port: specify the port for incoming connections or keep the default value.
  4. Click Save.

    Wait for the extension parameter update process to complete.

3. Check the ability to connect to the Postgresql instance via a secure connection

Connect to the Postgresql DB, specifying the value require for the sslmode parameter in the query.

Delete unused resources

If you no longer need the database instance, delete it.

Was this article helpful?