---
title: "Manage Connection Pools"
description: "Create, update and delete PgBouncer connection pools on Managed PostgreSQL with the Exoscale API, connect through them and tune PgBouncer."
url: https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/manage-connection-pools/
product: "PostgreSQL"
section: product
last_updated: 2026-11-10
---
> For AI agents: the documentation index is at https://community.exoscale.com/llms.txt. Every page is available as markdown at `<page URL>index.md` or with `Accept: text/markdown`.

# Manage Connection Pools

Create, read, update and delete the PgBouncer connection pools of a Managed PostgreSQL service, connect through them, and change the PgBouncer settings. For what the pool modes allow and how pools are sized, see [Connection Pooling](https://community.exoscale.com/product/dbaas/service-specific/postgresql/overview/connection-pooling/index.md).

## Prerequisites

You need:

- A running Managed PostgreSQL service, on any plan.
- The [Exoscale CLI](https://community.exoscale.com/reference/cli/exo/index.md), configured with your API credentials.
- `psql`, to connect through the pool.
- Your client IP address in the service IP filter. The filter applies to the `pgbouncer` port as
  well. See
  [Restrict Connections to a Service](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/restrict-connections/index.md).

Pools are managed with the `exo api` commands, which read the request body from standard input.
There is no `exo dbaas` command to create, change or delete a pool.

## Create a Pool

```bash
echo '{"name":"POOL_NAME","database-name":"DATABASE_NAME","mode":"transaction","size":10}' | \
  exo api create-dbaas-pg-connection-pool SERVICE_NAME -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service, for example `my-postgresql`.
- `ZONE`: zone the service runs in, for example `ch-gva-2`.
- `name`: required. Name of the pool, for example `app-pool`. Clients use it as the database name.
- `database-name`: required. An existing database of the service, for example `defaultdb`. A
  pool serves one database.
- `mode`: optional. `transaction` (default), `session` or `statement`.
- `size`: optional. Maximum number of server connections, from 1 to 10000. Defaults to 10.
- `username`: optional. Restricts the pool to one existing user. See below.

The request fails with HTTP 403 if the database or the user does not exist, and with HTTP 409 if
the total `size` of the pools of the service would exceed the connection budget described in
[Connection Pooling](https://community.exoscale.com/product/dbaas/service-specific/postgresql/overview/connection-pooling/index.md#pool-sizes-and-the-connection-budget).

Several pools can point to the same database, for example a large `transaction` pool for a web
application and a small `session` pool for a worker that needs `LISTEN`.

### Pools With a Username

Without `username`, every user of the service can connect through the pool as itself. With
`username`, only that user can, and the others get `FATAL: login rejected`.

> [!CAUTION]
> When a pool has a `username`, its `connection-uri` contains that user's password, in the
> output of `exo api get-dbaas-service-pg` and of `exo dbaas show -O json`. Treat that output as
> a secret. A pool without `username` has a `connection-uri` without credentials.

## List the Pools

There is no list operation for pools. Read them from the service:

```bash
exo api get-dbaas-service-pg SERVICE_NAME -z ZONE -q '"connection-pools"'
```

Each entry has `name`, `database`, `mode`, `size`, `connection-uri`, and `username` when one is
set. `exo dbaas show SERVICE_NAME -z ZONE` also lists the pools, with their name, database, size
and mode.

## Update a Pool

```bash
echo '{"mode":"session","size":20}' | \
  exo api update-dbaas-pg-connection-pool SERVICE_NAME POOL_NAME -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `POOL_NAME`: name of the pool to update.
- `ZONE`: zone the service runs in.
- The body accepts `database-name`, `mode`, `size` and `username`. Send only the fields to change.

A pool cannot be renamed: a `name` in the body is ignored. To rename, create a new pool, move the
clients, and delete the old one.

## Delete a Pool

```bash
exo api delete-dbaas-pg-connection-pool SERVICE_NAME POOL_NAME -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `POOL_NAME`: name of the pool to delete.
- `ZONE`: zone the service runs in.

Clients connected through the pool are disconnected with `FATAL: database removed`, and new
connections get `FATAL: no such database: POOL_NAME`. Move the applications to another pool or
to the `pg` port first.

## Connect Through a Pool

Read the host and the ports of the service:

```bash
exo api get-dbaas-service-pg SERVICE_NAME -z ZONE -q 'components'
```

The `pgbouncer` entry carries the port of the pooler. The `pg` entry carries the port for direct
connections; both work at the same time. Ports are assigned per service: read them instead of
copying them from an example.

Connect with the pool name as database name:

```bash
psql "host=HOST port=PGBOUNCER_PORT dbname=POOL_NAME user=USERNAME sslmode=verify-full sslrootcert=CA_PATH"
```

Parameters:

- `HOST`: `host` of the `pgbouncer` component.
- `PGBOUNCER_PORT`: `port` of the `pgbouncer` component.
- `POOL_NAME`: name of the pool.
- `USERNAME`: a user of the service, for example `avnadmin`. `psql` reads the password from
  `PGPASSWORD` or `~/.pgpass`.
- `CA_PATH`: path to the CA certificate from `exo dbaas ca-certificate -z ZONE`.

The `pgbouncer` port accepts the same TLS settings as the `pg` port, including `verify-full`.
Once connected, `SELECT current_database();` returns the database behind the pool, not the pool
name.

Application drivers connect the same way: set the database name to the pool name and the port to
the `pgbouncer` port. Keep the client connections open between requests, with the client-side
pool of your driver, so that each request does not pay for a new TLS handshake.

## Prepare an Application for Transaction Mode

Before you move an application to a `transaction` pool:

- Replace `pg_advisory_lock()` with `pg_advisory_xact_lock()`.
- Move session settings such as `statement_timeout` into each transaction with `SET LOCAL`, or
  attach them to the role or the database so that every server connection starts with them:

  ```sql
  ALTER ROLE app_user IN DATABASE defaultdb SET statement_timeout = '30s';
  ```

- Keep `LISTEN` consumers on a `session` pool or on the `pg` port.

The behavior behind each point is described in
[Connection Pooling](https://community.exoscale.com/product/dbaas/service-specific/postgresql/overview/connection-pooling/index.md#pool-modes).

## Change PgBouncer Settings

PgBouncer settings apply to the whole service, not to one pool. Change them with the API:

```bash
echo '{"pgbouncer-settings":{"max_prepared_statements":200}}' | \
  exo api update-dbaas-service-pg SERVICE_NAME -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `ZONE`: zone the service runs in.

The update is merged into the stored settings and applies within seconds, without a restart of
PostgreSQL. Read the stored values with:

```bash
exo api get-dbaas-service-pg SERVICE_NAME -z ZONE -q '"pgbouncer-settings"'
```

`exo dbaas update SERVICE_NAME -z ZONE -f --pg-bouncer-settings='JSON_OBJECT'` sets most of these
settings too, but it silently drops `server_connect_timeout`, `server_login_retry` and any setting
whose value is `0`. Use the API command above for those.

The available settings, with their ranges and defaults, are listed by:

```bash
exo api get-dbaas-settings-pg -q 'settings.pgbouncer.properties'
```

| Setting | Effect |
| --- | --- |
| `max_prepared_statements` | Protocol-level prepared statements PgBouncer tracks per client, 0 to 3000, default 100. `0` breaks driver prepared statements in `transaction` and `statement` modes. |
| `min_pool_size` | Server connections kept open per pool even when idle. |
| `server_idle_timeout` | Seconds before an idle server connection is closed, default 600. |
| `server_lifetime` | Seconds after which an unused server connection is closed, default 3600. |
| `server_reset_query_always` | When `true`, runs `DISCARD ALL` when a server connection returns to the pool in every mode, not only in `session` mode. |
| `server_login_retry` | Seconds PgBouncer waits before retrying after a failed login to PostgreSQL, default 15 in the running configuration. |
| `ignore_startup_parameters` | Startup parameters PgBouncer accepts instead of rejecting the client. Only `extra_float_digits` and `search_path` are allowed. |
| `autodb_pool_mode`, `autodb_pool_size`, `autodb_idle_timeout`, `autodb_max_db_connections` | Settings for pools that PgBouncer creates automatically. |

To read the values PgBouncer is running with, use `SHOW CONFIG;` in the PgBouncer console,
described in
[Troubleshoot Connection Pooling](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/troubleshoot-connection-pooling/index.md#read-the-state-of-the-pooler).

## Related Pages

- [Connection Pooling](https://community.exoscale.com/product/dbaas/service-specific/postgresql/overview/connection-pooling/index.md)
- [Troubleshoot Connection Pooling](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/troubleshoot-connection-pooling/index.md)
- [Connect with psql](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/connect-with-psql/index.md)
- [Restrict Connections to a Service](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/restrict-connections/index.md)
- [Configure PostgreSQL Settings](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/configure-settings/index.md)

