---
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/libraries/pgb
---

# 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)

[Toggle side navigation](https://charmhub.io/pgbouncer-k8s/libraries/pgb#drawer)

## charms.pgbouncer\_k8s.v0.pgb

* [*Docstrings*Docstrings](https://charmhub.io/pgbouncer-k8s/libraries/pgb)
  [*Code*Source code](https://charmhub.io/pgbouncer-k8s/libraries/pgb/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.pgbouncer_k8s.v0.pgb
    ```

    [Download pgb.py](https://charmhub.io/pgbouncer-k8s/libraries/pgb/download)
  + *Last updated* 30 Apr 2025
  + *Revision* Library version 0.11

PgBouncer Charm Library.

This charm library provides common pgbouncer-specific features for the pgbouncer machine and
Kubernetes charms, including automatic config management using the PgbConfig object, and the
default config for pgbouncer.

---

Index

* [def parse\_kv\_string\_to\_dict(
  string
  )](https://charmhub.io/pgbouncer-k8s/libraries/pgb#parse_kv_string_to_dict)
* [def parse\_dict\_to\_kv\_string(
  dictionary
  )](https://charmhub.io/pgbouncer-k8s/libraries/pgb#parse_dict_to_kv_string)
* [def generate\_password(
  )](https://charmhub.io/pgbouncer-k8s/libraries/pgb#generate_password)
* [def get\_md5\_password(
  username,
  password
  )](https://charmhub.io/pgbouncer-k8s/libraries/pgb#get_md5_password)
* [def get\_scram\_password(
  username,
  password,
  connection
  )](https://charmhub.io/pgbouncer-k8s/libraries/pgb#get_scram_password)

#### def parse\_kv\_string\_to\_dict(string: str)

Parses space-separated key=value pairs into a python dict.

Arguments

string

a string containing a set of key=value pairs, joined with = characters and
separated with spaces

Returns

A dict containing the key-value pairs represented as strings.

Description

TODO this could make use of pgconnstr, but that requires that this charm lib has a dependency.

#### def parse\_dict\_to\_kv\_string(dictionary)

Helper function to encode a python dict into a pgbouncer-readable string.

Arguments

dictionary

A dict containing the key-value pairs represented as strings.

Description

TODO this could make use of pgconnstr, but that requires that this charm lib has a dependency.

#### def generate\_password()

Generates a secure password of alphanumeric characters.

Returns

A random 24-character string of letters and numbers.

Description

Passwords are alphanumeric only, to ensure compatibility with the userlist.txt format -
specifically, spaces and double quotes may interfere with parsing this file.

#### def get\_md5\_password(     username: str,     password: str )

Description

Creates an md5 hashed password for the given user, in the format postgresql expects. None

#### def get\_scram\_password(     username: str,     password: str,     connection )

Description

Creates an SCRAM SHA 256 hashed password for the given user, in the format postgresql expects. None
