---
title: "PgBouncer connection pooler in a PostgreSQL PGVector cluster"
sidebar_label: "Connection pooler"
sidebar_position: 7
description: "Pool size, PgBouncer pooling modes, and how to change the mode in a PostgreSQL PGVector cluster"
---

import Formbricks from '@theme/MDXComponents/Formbricks'

# 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`](#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](#pool-size) (the `pool_size` parameter).

PostgreSQL PGVector Cloud Database clusters use the PgBouncer connection pooler. There are [three PgBouncer pooling modes available](#pooling-modes). Learn more about the connection pooler in the [PgBouncer documentation](https://www.pgbouncer.org/).

## Maximum number of connections to the PostgreSQL process (max_connections) \{#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](/managed-databases/pgvector/settings.mdx) 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.

![](https://423.selcdn.ru/kb/dbaas-no-pooler-LANG-THEME.png)

## Pool size (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](/managed-databases/pgvector/create-cluster.mdx) and [change the size](#change-pool-size) in an existing cluster. Available values range from 1 to 500.

## Pooling modes \{#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](https://www.pgbouncer.org/).

PgBouncer supports three modes:

* [transaction mode](#transaction-mode);
* [session mode](#session-mode);
* [statement mode](#statement-mode).

By default, Cloud Databases use transaction mode.

You can select the pooling mode when [creating a cluster](/managed-databases/pgvector/create-cluster.mdx) and [change the mode](#change-pooling-mode) in an existing cluster.

## Transaction mode \{#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.

![](https://423.selcdn.ru/kb/dbaas-transaction-pooling-mode-LANG-THEME.png)

### Transaction mode limitations \{#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:

* [SET/RESET](https://www.postgresql.org/docs/current/sql-reset.html) and [LISTEN/NOTIFY commands](https://www.postgresql.org/docs/current/sql-listen.html);
* [WITH HOLD CURSOR](https://www.postgresql.org/docs/current/sql-declare.html);
* [PRESERVE/DELETE ROWS](https://www.postgresql.org/docs/current/sql-createtable.html) in temporary tables;
* prepared statements: protocol-level prepared plans, [PREPARE](https://www.postgresql.org/docs/current/sql-prepare.html), [DEALLOCATE](https://www.postgresql.org/docs/current/sql-deallocate.html);
* the statement [LOAD](https://www.postgresql.org/docs/14/sql-load.html);
* advisory locks [Session-level advisory locks](https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS).

Learn more about [incompatible options](https://www.pgbouncer.org/features.html#fnref:2) in the PgBouncer documentation.

## Session mode \{#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](#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.

![](https://423.selcdn.ru/kb/dbaas-session-pooling-mode-LANG-THEME.png)

## Statement mode \{#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).

![](https://423.selcdn.ru/kb/dbaas-statement-pooling-mode-LANG-THEME.png)

## Change pooling mode \{#change-pooling-mode}

:::info

If you select transaction mode, see [limitations of this mode](#transaction-mode-limitations).

:::

1. In the [control panel](https://my.selectel.ru/vpc/default/dbaas/), 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 \{#change-pool-size}

1. In the [control panel](https://my.selectel.ru/vpc/default/dbaas/), 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**.

<Formbricks />
