# Bitnami Secure Image for PgBouncer

> PgBouncer is a connection pooler for PostgreSQL. It reduces performance overhead by rotating client connections to PostgreSQL databases. It supports PostgreSQL databases located on different hosts.

[Overview of PgBouncer](https://www.pgbouncer.org/)
Trademarks: This software listing is packaged by Bitnami. The respective trademarks mentioned in the offering are owned by the respective companies, and use of them does not imply any affiliation or endorsement.

## TL;DR

```console
docker run --name pgbouncer bitnami/pgbouncer:latest
```

**Warning**: This quick setup is only intended for development environments. You are encouraged to change the insecure default credentials and check out the available configuration options in the [Configuration](#configuration) section for a more secure deployment.

## Why use Bitnami Secure Images?

Those are hardened, minimal CVE images built and maintained by Bitnami. Bitnami Secure Images are based on the cloud-optimized, security-hardened enterprise [OS Photon Linux](https://vmware.github.io/photon/). Why choose BSI images?

- Hardened secure images of popular open source software with Near-Zero Vulnerabilities
- Vulnerability Triage & Prioritization with VEX Statements, KEV and EPSS Scores
- Compliance focus with FIPS, STIG, and air-gap options, including secure bill of materials (SBOM)
- Software supply chain provenance attestation through in-toto
- First class support for the internet’s favorite Helm charts

Each image comes with valuable security metadata. You can view the metadata in [our public catalog here](https://app-catalog.vmware.com/bitnami/apps). Note: Some data is only available with [commercial subscriptions to BSI](https://bitnami.com/).

![Alt text](https://github.com/bitnami/containers/blob/main/BSI%20UI%201.png?raw=true "Application details")
![Alt text](https://github.com/bitnami/containers/blob/main/BSI%20UI%202.png?raw=true "Packaging report")

If you are looking for our previous generation of images based on Debian Linux, please see the [Bitnami Legacy registry](https://hub.docker.com/u/bitnamilegacy).

## Why use a non-root container?

Non-root container images add an extra layer of security and are generally recommended for production environments. However, because they run as a non-root user, privileged tasks are typically off-limits. Learn more about non-root containers [in our docs](https://techdocs.broadcom.com/us/en/vmware-tanzu/application-catalog/tanzu-application-catalog/services/tac-doc/apps-tutorials-work-with-non-root-containers-index.html).

## Supported tags and respective `Dockerfile` links

Learn more about the Bitnami tagging policy and the difference between rolling tags and immutable tags [in our documentation page](https://techdocs.broadcom.com/us/en/vmware-tanzu/application-catalog/tanzu-application-catalog/services/tac-doc/apps-tutorials-understand-rolling-tags-containers-index.html).

## Get this image

The recommended way to get the Bitnami pgbouncer Docker Image is to pull the prebuilt image from the [Docker Hub Registry](https://hub.docker.com/r/bitnami/pgbouncer).

```console
docker pull bitnami/pgbouncer:latest
```

To use a specific version, you can pull a versioned tag. You can view the [list of available versions](https://hub.docker.com/r/bitnami/pgbouncer/tags/) in the Docker Hub Registry.

```console
docker pull bitnami/pgbouncer:[TAG]
```

If you wish, you can also build the image yourself by cloning the repository, changing to the directory containing the Dockerfile and executing the `docker build` command. Remember to replace the `APP`, `VERSION` and `OPERATING-SYSTEM` path placeholders in the example command below with the correct values.

```console
git clone https://github.com/bitnami/containers.git
cd bitnami/APP/VERSION/OPERATING-SYSTEM
docker build -t bitnami/APP:latest .
```

## Using `docker-compose.yaml`

Please be aware this file has not undergone internal testing. Consequently, we advise its use exclusively for development or testing purposes.

## Configuration

The following section describes the supported environment variables

### Environment variables

The following tables list the main variables you can set.

#### Customizable environment variables

| Name                                  | Description                                                                                                                                                                                | Default Value           |
|---------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------|
| `PGBOUNCER_LOG_FILE`                  | If set, log PgBouncer output to log file in addition to stdout.                                                                                                                            | `nil`                   |
| `PGBOUNCER_DATABASE`                  | PgBouncer advertised database.                                                                                                                                                             | `postgres`              |
| `PGBOUNCER_PORT`                      | PgBouncer port                                                                                                                                                                             | `6432`                  |
| `PGBOUNCER_LISTEN_ADDRESS`            | PgBouncer listen address                                                                                                                                                                   | `0.0.0.0`               |
| `PGBOUNCER_AUTH_USER`                 | PgBouncer authentication user                                                                                                                                                              | `nil`                   |
| `PGBOUNCER_AUTH_QUERY`                | PgBouncer authentication query                                                                                                                                                             | `nil`                   |
| `PGBOUNCER_AUTH_TYPE`                 | PgBouncer authentication type                                                                                                                                                              | `scram-sha-256`         |
| `PGBOUNCER_AUTH_HBA_FILE`             | HBA configuration file to use                                                                                                                                                              | `nil`                   |
| `PGBOUNCER_AUTH_IDENT_FILE`           | Ident map file to use                                                                                                                                                                      | `nil`                   |
| `PGBOUNCER_STATS_USERS`               | PgBouncer comma-separated list of database users that are allowed to connect and run read-only queries.                                                                                    | `nil`                   |
| `PGBOUNCER_POOL_MODE`                 | PgBouncer pool mode. Allowed values: session (default), transaction and statement.                                                                                                         | `nil`                   |
| `PGBOUNCER_INIT_SLEEP_TIME`           | PgBouncer initialization sleep time                                                                                                                                                        | `10`                    |
| `PGBOUNCER_SERVER_FAST_CLOSE`         | Disconnect a server in session pooling mode immediately or after the end of the current transaction if it is in `close_needed` mode, rather than waiting for the session end (default: 0). | `0`                     |
| `PGBOUNCER_INIT_MAX_RETRIES`          | PgBouncer initialization maximum retries                                                                                                                                                   | `10`                    |
| `PGBOUNCER_QUERY_WAIT_TIMEOUT`        | PgBouncer maximum time queries are allowed to spend waiting for execution (default: 120).                                                                                                  | `nil`                   |
| `PGBOUNCER_MAX_CLIENT_CONN`           | PgBouncer maximum number of client connections allowed (default: 120).                                                                                                                     | `nil`                   |
| `PGBOUNCER_MAX_DB_CONNECTIONS`        | PgBouncer maximum number of database connections allowed (default: 0).                                                                                                                     | `nil`                   |
| `PGBOUNCER_IDLE_TRANSACTION_TIMEOUT`  | PgBouncer maximum time for a client to be in 'idle in transaction' state (default: 0.0).                                                                                                   | `nil`                   |
| `PGBOUNCER_SERVER_IDLE_TIMEOUT`       | PgBouncer maximum time in seconds a server connection can be idle. If 0 then the timeout is disabled (default: 600).                                                                       | `nil`                   |
| `PGBOUNCER_SERVER_RESET_QUERY`        | PgBouncer query sent to server on connection release before making it available to other clients (default: DISCARD ALL).                                                                   | `nil`                   |
| `PGBOUNCER_DEFAULT_POOL_SIZE`         | PgBouncer maximum server connections to allow per user/database pair (default: 20).                                                                                                        | `nil`                   |
| `PGBOUNCER_MIN_POOL_SIZE`             | PgBouncer has at least this amount of open connections (default: 0).                                                                                                                       | `nil`                   |
| `PGBOUNCER_RESERVE_POOL_SIZE`         | PgBouncer allows this amount of additional connections (default: 0).                                                                                                                       | `nil`                   |
| `PGBOUNCER_RESERVE_POOL_TIMEOUT`      | If a client has not been serviced in this time, use additional connections from the reserve pool. 0 disables. Default: **5.0** [seconds].                                                  | `nil`                   |
| `PGBOUNCER_IGNORE_STARTUP_PARAMETERS` | Ignore startup parameters in PgBouncer                                                                                                                                                     | `extra_float_digits`    |
| `PGBOUNCER_STATS_PERIOD`              | PgBouncer stats period                                                                                                                                                                     | `60`                    |
| `PGBOUNCER_MAX_PREPARED_STATEMENTS`   | PgBouncer maximum number of cached prepared statements (default: 0).                                                                                                                       | `nil`                   |
| `PGBOUNCER_EXTRA_FLAGS`               | Extra flags for PgBouncer initialization                                                                                                                                                   | `nil`                   |
| `PGBOUNCER_FAIL_ON_INVALID_DSN_FILE`  | Whether init process should fail if any DSN_FILE is not found.                                                                                                                             | `false`                 |
| `PGBOUNCER_SERVER_ROUND_ROBIN`        | Defaults to LIFO server connection (0) reuse for performance but recommends uniform usage for systems with round-robin (1) setups to evenly distribute load.                               | `0`                     |
| `PGBOUNCER_APPLICATION_NAME_ADD_HOST` | PgBouncer add the client host address and port to the application name setting set on connection start                                                                                     | `nil`                   |
| `PGBOUNCER_CLIENT_TLS_SSLMODE`        | PgBouncer authentication type                                                                                                                                                              | `disable`               |
| `PGBOUNCER_CLIENT_TLS_CA_FILE`        | PgBouncer TLS authentication CA file                                                                                                                                                       | `nil`                   |
| `PGBOUNCER_CLIENT_TLS_CERT_FILE`      | PgBouncer TLS authentication cert file                                                                                                                                                     | `nil`                   |
| `PGBOUNCER_CLIENT_TLS_KEY_FILE`       | PgBouncer TLS authentication key file                                                                                                                                                      | `nil`                   |
| `PGBOUNCER_CLIENT_TLS_CIPHERS`        | PgBouncer TLS authentication ciphers                                                                                                                                                       | `fast`                  |
| `PGBOUNCER_SERVER_TLS_SSLMODE`        | PgBouncer server authentication type                                                                                                                                                       | `disable`               |
| `PGBOUNCER_SERVER_TLS_CA_FILE`        | PgBouncer server TLS authentication CA file                                                                                                                                                | `nil`                   |
| `PGBOUNCER_SERVER_TLS_CERT_FILE`      | PgBouncer server TLS authentication cert file                                                                                                                                              | `nil`                   |
| `PGBOUNCER_SERVER_TLS_KEY_FILE`       | PgBouncer server TLS authentication key file                                                                                                                                               | `nil`                   |
| `PGBOUNCER_SERVER_TLS_PROTOCOLS`      | PgBouncer server TLS authentication protocol                                                                                                                                               | `secure`                |
| `PGBOUNCER_SERVER_TLS_CIPHERS`        | PgBouncer server TLS authentication ciphers                                                                                                                                                | `fast`                  |
| `PGBOUNCER_LOG_CONNECTIONS`           | PgBouncer log connections                                                                                                                                                                  | `nil`                   |
| `PGBOUNCER_LOG_DISCONNECTIONS`        | PgBouncer log disconnections                                                                                                                                                               | `nil`                   |
| `PGBOUNCER_LOG_POOLER_ERRORS`         | PgBouncer log pooler errors                                                                                                                                                                | `nil`                   |
| `PGBOUNCER_LOG_STATS`                 | PgBouncer log stats                                                                                                                                                                        | `nil`                   |
| `PGBOUNCER_SERVER_LIFETIME`           | PgBouncer server lifetime                                                                                                                                                                  | `nil`                   |
| `PGBOUNCER_SERVER_CONNECT_TIMEOUT`    | PgBouncer server connect timeout                                                                                                                                                           | `nil`                   |
| `PGBOUNCER_SERVER_LOGIN_RETRY`        | PgBouncer server login retry                                                                                                                                                               | `nil`                   |
| `PGBOUNCER_CLIENT_LOGIN_TIMEOUT`      | PgBouncer client login timeout                                                                                                                                                             | `nil`                   |
| `PGBOUNCER_AUTODB_IDLE_TIMEOUT`       | PgBouncer autodb idle timeout                                                                                                                                                              | `nil`                   |
| `PGBOUNCER_QUERY_TIMEOUT`             | PgBouncer query timeout                                                                                                                                                                    | `nil`                   |
| `PGBOUNCER_CLIENT_IDLE_TIMEOUT`       | PgBouncer client idle timeout                                                                                                                                                              | `nil`                   |
| `POSTGRESQL_USERNAME`                 | PostgreSQL backend default username                                                                                                                                                        | `postgres`              |
| `POSTGRESQL_PASSWORD`                 | Password for the PostgreSQL created user                                                                                                                                                   | `nil`                   |
| `POSTGRESQL_DATABASE`                 | Default PostgreSQL database                                                                                                                                                                | `${PGBOUNCER_DATABASE}` |
| `POSTGRESQL_HOST`                     | PostgreSQL backend hostname                                                                                                                                                                | `postgresql`            |
| `POSTGRESQL_PORT`                     | PostgreSQL backend port                                                                                                                                                                    | `5432`                  |
| `PGBOUNCER_SET_DATABASE_USER`         | Whether to include the backend PostgreSQL username in the database string.                                                                                                                 | `no`                    |
| `PGBOUNCER_SET_DATABASE_PASSWORD`     | Whether to include the backend PostgreSQL password in the database string.                                                                                                                 | `no`                    |
| `PGBOUNCER_USERLIST`                  | Additional content for PGBOUNCER_AUTH_FILE file                                                                                                                                            | `nil`                   |
| `PGBOUNCER_CONNECT_QUERY`             | Query which will be executed after a connection is established.                                                                                                                            | `nil`                   |
| `PGBOUNCER_FORCE_INITSCRIPTS`         | Force the init scripts running even if it is not in the first start.                                                                                                                       | `false`                 |
| `PGBOUNCER_SOCKET_DIR`                | PgBouncer socket dir                                                                                                                                                                       | `/tmp/`                 |
| `PGBOUNCER_SOCKET_MODE`               | PgBouncer socket mode                                                                                                                                                                      | `0777`                  |
| `PGBOUNCER_SOCKET_GROUP`              | PgBouncer socket group                                                                                                                                                                     | `nil`                   |
| `PGBOUNCER_DAEMON_USER`               | PostgreSQL daemon user                                                                                                                                                                     | `pgbouncer`             |
| `PGBOUNCER_DAEMON_GROUP`              | PostgreSQL daemon group                                                                                                                                                                    | `pgbouncer`             |

#### Read-only environment variables

| Name                         | Description                                            | Value                                       |
|------------------------------|--------------------------------------------------------|---------------------------------------------|
| `PGBOUNCER_BASE_DIR`         | PgBouncer installation directory.                      | `${BITNAMI_ROOT_DIR}/pgbouncer`             |
| `PGBOUNCER_CONF_DIR`         | PgBouncer configuration directory.                     | `${PGBOUNCER_BASE_DIR}/conf`                |
| `PGBOUNCER_LOG_DIR`          | PgBouncer logs directory.                              | `${PGBOUNCER_BASE_DIR}/logs`                |
| `PGBOUNCER_TMP_DIR`          | PgBouncer temporary directory.                         | `${PGBOUNCER_BASE_DIR}/tmp`                 |
| `PGBOUNCER_PID_FILE`         | PgBouncer pid file.                                    | `${PGBOUNCER_TMP_DIR}/pgbouncer.pid`        |
| `PGBOUNCER_CONF_FILE`        | PgBouncer configuration file.                          | `${PGBOUNCER_CONF_DIR}/pgbouncer.ini`       |
| `PGBOUNCER_AUTH_FILE`        | PgBouncer authentication file.                         | `${PGBOUNCER_CONF_DIR}/userlist.txt`        |
| `PGBOUNCER_VOLUME_DIR`       | PgBouncer volume directory.                            | `${BITNAMI_VOLUME_DIR}/pgbouncer`           |
| `PGBOUNCER_MOUNTED_CONF_DIR` | PgBouncer mounted configuration directory.             | `${PGBOUNCER_VOLUME_DIR}/conf`              |
| `PGBOUNCER_INITSCRIPTS_DIR`  | PgBouncer init scripts directory.                      | `/docker-entrypoint-initdb.d`               |
| `NSS_WRAPPER_LIB`            | Flag for startup (necessary for the postgresql client) | `/opt/bitnami/common/lib/libnss_wrapper.so` |

### Daemon settings

The following parameters can be set for the PgBouncer daemon:

### Authentication

The authentication mode can be set using the `PGBOUNCER_AUTH_TYPE` variable, which can be set to any of the values available [in the official PgBouncer documentation](https://www.pgbouncer.org/config.html). In the case of the `scram-sha-256` authentication type (default value), set the backend PostgreSQL credentials as using the variables described in the [Environment Variables](#environment-variables) table.

### Extra arguments to PgBouncer startup

In case you want to add extra flags to the PgBouncer command, use the `PGBOUNCER_EXTRA_FLAGS` variable. Example:

```console
docker run --name pgbouncer \
  -e PGBOUNCER_EXTRA_FLAGS="--verbose" \
  bitnami/pgbouncer:latest
```

### Exposed database

- `PGBOUNCER_DATABASE`: PgBouncer exposed database. Default: **postgres**.

In case you'd like pgbouncer to expose your database with a different name, you can use the `PGBOUNCER_DATABASE` variable.
To expose the same database name as the backend, set `PGBOUNCER_DATABASE="$POSTGRESQL_DATABASE"`.
To expose a ["fallback database" (wildcard that matches any)](https://www.pgbouncer.org/config.html#section-databases)), set `PGBOUNCER_DATABASE="*"`.

### Initializing a new instance

When the container is launched, it will execute the files with extension `.sh` located at `/docker-entrypoint-initdb.d`. In order to have your custom files inside the docker image you can mount them as a volume.

### Securing PgBouncer traffic

PgBouncer supports the encryption of connections using the SSL/TLS protocol. Should you desire to enable this optional feature, you may use the following environment variables to configure the application:

- `PGBOUNCER_CLIENT_TLS_SSLMODE`: TLS traffic settings. Defaults to `disable`. Check the [official PgBouncer documentation](https://www.pgbouncer.org/config.html) for the available values for `client_tls_sslmode`.
- `PGBOUNCER_CLIENT_TLS_CERT_FILE`: File containing the certificate file for the TLS traffic. No defaults.
- `PGBOUNCER_CLIENT_TLS_KEY_FILE`: File containing the key for certificate. No defaults.
- `PGBOUNCER_CLIENT_TLS_CA_FILE`: File containing the CA of the certificate. If provided, PgBouncer will authenticate TLS/SSL clients by requesting them a certificate . No defaults.
- `PGBOUNCER_CLIENT_TLS_CIPHERS`: TLS ciphers to be used. Defaults to `fast`.Check the [official PgBouncer documentation](https://www.pgbouncer.org/config.html) for the available values for `client_tls_ciphers`.

- `PGBOUNCER_SERVER_TLS_SSLMODE`: Server TLS traffic settings. Defaults to `disable`. Check the [official PgBouncer documentation](https://www.pgbouncer.org/config.html) for the available values for `server_tls_sslmode`.
- `PGBOUNCER_SERVER_TLS_KEY_FILE`: File containing the key to authenticate against PostgreSQL server. No defaults.
- `PGBOUNCER_SERVER_TLS_CERT_FILE`: File containing the certificate associated to previous private key. PostgreSQL server can validate it. No defaults.
- `PGBOUNCER_SERVER_TLS_CA_FILE`: File containing the CA of the server certificate. If provided, PgBouncer will authenticate TLS/SSL clients by requesting them a certificate . No defaults.
- `PGBOUNCER_SERVER_TLS_PROTOCOLS`: TLS protocols to be used in server connection. Defaults to `secure`. Check the [official PgBouncer documentation](https://www.pgbouncer.org/config.html) for the available values for `server_tls_protocols`.
- `PGBOUNCER_SERVER_TLS_CIPHERS`: TLS ciphers to be used in server connection. Defaults to `fast`. Check the [official PgBouncer documentation](https://www.pgbouncer.org/config.html) for the available values for `server_tls_ciphers`.

When enabling TLS, PgBouncer will support both standard and encrypted traffic by default but prefer the latter.

Alternatively, you may also provide this configuration in your [custom](https://github.com/bitnami/containers/blob/main/bitnami/pgbouncer#configuration-file) configuration file.

### Configuration file

The image looks for `pgbouncer.ini` file in `/opt/bitnami/pgbouncer/conf/`. You can mount a volume at `/bitnami/pgbouncer/conf/` and copy/edit the `pgbouncer.ini` file in the `/path/to/pgbouncer-persistence/conf/`. The default configuration will be populated to the `conf/` directory if it's empty.

Refer to the [server configuration](https://www.pgbouncer.org/usage.html) manual for the complete list of configuration options.

### How to connect with multiple PostgreSQL servers

It is possible to connect a single PgBouncer instance with multiple PostgreSQL backends. By using as many `PGBOUNCER_DSN_${i}` environment variables (with `i` starting at zero, `0`) as needed, and the `PGBOUNCER_USERLIST_FILE` variable pointing to a mounted volume with the required credentials for any extra PostgreSQL database in the format `"<postgresql-user>" "<password>"`.

The PgBouncer initialization process requires one PostgreSQL backend to be configured using the different `POSTGRESQL_*` variables listed in the [Environment Variables](#environment-variables) section, but the rest of backends connections can be provided using the method explained in this section.
### FIPS configuration in Bitnami Secure Images

The Bitnami PgBouncer Docker image from the [Bitnami Secure Images](https://go-vmware.broadcom.com/contact-us) catalog includes extra features and settings to configure the container with FIPS capabilities. You can configure the next environment variables:

- `OPENSSL_FIPS`: whether OpenSSL runs in FIPS mode or not. `yes` (default), `no`.

## License

Copyright &copy; 2026 Broadcom. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

<http://www.apache.org/licenses/LICENSE-2.0>

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
