---
title: Charmhub | Deploy PgBouncer K8s using Charmhub - The Open Operator Collection
description: Deploy the latest version of PgBouncer K8s as a Kubernetes Operator on
  any cloud.
url: https://charmhub.io/pgbouncer-k8s/configurations
---

# PgBouncer K8s

[Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")

* [Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")
* [Databases](https://charmhub.io/?filter=databases)

Platform:

1/stable 593

```
juju deploy pgbouncer-k8s --channel 1/stable --trust
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

* [expose-external](https://charmhub.io/pgbouncer-k8s/configurations#expose-external)
* [listen\_port](https://charmhub.io/pgbouncer-k8s/configurations#listen_port)
* [loadbalancer-extra-annotations](https://charmhub.io/pgbouncer-k8s/configurations#loadbalancer-extra-annotations)
* [max\_db\_connections](https://charmhub.io/pgbouncer-k8s/configurations#max_db_connections)
* [max\_prepared\_statements](https://charmhub.io/pgbouncer-k8s/configurations#max_prepared_statements)
* [pool\_mode](https://charmhub.io/pgbouncer-k8s/configurations#pool_mode)

[Learn about configurations >](https://juju.is/docs/juju/configuration#heading--application-configuration)

* expose-external | string

  Default: false

  String to determine how to expose PgBouncer externally from the
  Kubernetes cluster.
  Possible values: 'false', 'nodeport', 'loadbalancer'
* listen\_port | int

  Default: 6432

  The port on which pgbouncer listens for traffic. Corresponds to
  listen\_port in pgbouncer config.
* loadbalancer-extra-annotations | string

  Default: {}

  A JSON string representing extra annotations for the Kubernetes service
  created and managed by the charm.
* max\_db\_connections | int

  Default: 100

  Do not allow more than this many server connections per database
  (regardless of user). This considers the PgBouncer database that the
  client has connected to, not the PostgreSQL database of the outgoing
  connection.

  Note that when you hit the limit, closing a client connection to one pool
  will not immediately allow a server connection to be established for
  another pool, because the server connection for the first pool is still
  open. Once the server connection closes (due to idle timeout), a new
  server connection will immediately be opened for the waiting pool.

  This is used to calculate the following pgbouncer.ini config options,
  which are documented in the pgbouncer config docs here:
  https://www.pgbouncer.org/config.html.

  + Firstly, the number of pgbouncer instances is calculated from the CPU
    provisioned for the pgbouncer container, clamped to between 2 and 4.
  + effective DB connections = max\_db\_connections / pgbouncer instances
  + default\_pool\_size = effective connections / 2
  + min\_pool\_size = effective connections / 4
  + reserve\_pool\_size = effective connections / 4

  If max\_db\_connections is set to 0, the derivatives are set thusly, based
  on pgbouncer defaults:

  + default\_pool\_size = 20
  + min\_pool\_size = 10
  + reserve\_pool\_size = 10

  0 = unlimited.
* max\_prepared\_statements | int

  Default: 100

  Number of prepared statements kept alive on backend connections. Possible values are between 0 and 1000.
  A value of 0 disables prepared statements.

  Default: 100
* pool\_mode | string

  Default: session

  Specifies when a server connection can be reused by other clients. Can
  be one of the following values:

  session
  Server is released back to pool after client disconnects. Default.

  transaction
  Server is released back to pool after transaction finishes.

  statement
  Server is released back to pool after query finishes. Transactions
  spanning multiple statements are disallowed in this mode.
