Skip to main content

PgBouncer connection pooler in a PostgreSQL PGVector cluster

In PostgreSQL PGVector, a separate process is created to handle each client connection. The greater the number of connections, the more processes consume RAM. The maximum number of connections to the PostgreSQL PGVector process is determined by the parameter max_connections.

To optimize resource consumption, you can use a connection pooler. Clients connect to the connection pooler rather than directly to PostgreSQL PGVector. At the same time, a small number of connections is maintained between the pooler and the PostgreSQL PGVector server — the pooler creates a new connection or reuses an existing one. The number of connections between the pooler and the database on each cluster node is determined by the pool size (the pool_size parameter).

PostgreSQL PGVector Cloud Database clusters use the PgBouncer connection pooler. There are three PgBouncer pooling modes available. Learn more about the connection pooler in the PgBouncer documentation.

Maximum number of connections to the PostgreSQL process (max_connections)

The PostgreSQL PGVector DBMS parameter max_connections determines the maximum number of concurrent connections to the PostgreSQL PGVector process. By default, it is set to 100 connections.

You can change the parameter value in the DBMS settings in the control panel to the maximum number of connections under load. Keep in mind that each connection consumes RAM resources.

Changing the max_connections value causes the PostgreSQL PGVector cluster nodes to restart.

Pool size (pool_size)

The pool size (the pool_size parameter) is the maximum number of connections between the connection pooler and each PostgreSQL PGVector database on each cluster node.

You can select the pool size when creating a cluster and change the size in an existing cluster. Available values range from 1 to 500.

Pooling modes

A pooling mode is a client connection strategy to PostgreSQL PGVector. PostgreSQL PGVector Cloud Database clusters use the PgBouncer connection pooler. Learn more about the connection pooler in the PgBouncer documentation.

PgBouncer supports three modes:

By default, Cloud Databases use transaction mode.

You can select the pooling mode when creating a cluster and change the mode in an existing cluster.

Transaction mode

The connection to PostgreSQL PGVector is maintained until the transaction completes. When the transaction completes, the pooler returns the connection to the pool. Later, this connection can be reused by the same client for other connections or by another client.

The total number of client connections to PgBouncer can reach 10,000, but the number of active transactions is determined by the pool size. For example, if the pool size is 30, there will be 30 active transactions.

The number of connections between the connection pooler and each PostgreSQL PGVector database on each cluster node is also determined by the pool size.

A client can execute multiple transactions concurrently across different connections. At the same time, each connection between the connection pooler and the PostgreSQL PGVector server can execute transactions of different clients during its lifecycle.

Transaction mode reduces the load on DBMS resources when there is a large number of low-load client connections.

Transaction mode limitations

Transaction mode interferes with certain PostgreSQL PGVector mechanisms. Choose a different mode if clients use these options. Some connection flags can be distributed across different clients, which may lead to unpredictable behavior and incorrect results.

In transaction mode, the following do not work:

Learn more about incompatible options in the PgBouncer documentation.

Session mode

In session mode, the client can continue sending queries for as long as the session lasts — the connection between the connection pooler and the PostgreSQL PGVector server will be maintained until the client disconnects from the database.

The number of connections between the connection pooler and the PostgreSQL PGVector server is determined by the pool size. For each client connection, a connection between the pooler and the PostgreSQL PGVector server is used. The connection is returned to the pool and can be reused only after the previous client disconnects from the database.

Unlike transaction mode, this mode is safe, replicates a direct connection to PostgreSQL PGVector, supports all mechanisms, and is suitable for all PostgreSQL PGVector clients. When using this mode, the load on resources is not reduced.

This connection mode is useful for clients with many short-lived database connections because it increases connection speed to the DBMS.

Statement mode

The pooler will return the connection to the pool as soon as the first query is processed — multi-statement transactions will be aborted, and the pooler will return an error.

This mode allows more client connections than transaction mode. The mode is suitable if it is known that each transaction is limited to only one query (AUTOCOMMIT is enabled).

Change pooling mode

For your information

If you select transaction mode, see limitations of this mode.

  1. In the control panel, in the top menu, click Products and select Cloud Databases.
  2. Open the tab Active.
  3. Open the cluster page → tab Settings.
  4. In the Connection pooler block, click Edit and select the pooling mode.
  5. Click Save.

Change pool size

  1. In the control panel, in the top menu, click Products and select Cloud Databases.
  2. Open the tab Active.
  3. Open the cluster page → tab Settings.
  4. In the Connection pooler block, click Edit and change the pool size.
  5. Click Save.