Giter Site home page Giter Site logo

pgbouncer-operator's Introduction

PgBouncer Operator

Description

The PgBouncer Operator deploys and operates the PgBouncer lightweight connection pooler for PostgreSQL. This charm is only compatible with the data platform postgresql-operator charm.

Usage

To deploy pgbouncer in front of three units of postgres:

juju deploy pgbouncer --channel=edge
juju deploy postgresql --channel=edge -n 3
juju add-relation pgbouncer:backend-database postgresql:database

To deploy and relate your application to the above cluster, using the updated data platform relation (recommended):

juju deploy my-app
juju add-relation pgbouncer:database my-app:pg-backend

To deploy and relate an application to the above cluster, using the legacy pgsql relation (not recommended - this will be deprecated in future):

juju deploy my-app
juju add-relation pgbouncer:db my-app:db

Or, if my-app needs admin permissions:

juju add-relation pgbouncer:db-admin my-app:db

Configuration Options

Set these using the command juju config <option>=<value>.

  • pool_mode:

    • 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.
      • 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.
  • max_db_connections:

    • 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.
    • 0 = unlimited

From these values and the current deployment, the following pgbouncer.ini config values are calculated proportional to max_db_connections:

  • effective_db_connections = max_db_connections / number of pgbouncer instances running in a unit
    • Number of pgbouncer instances is equal to number of cpu cores on unit.
  • default_pool_size = effective_db_connections / 2
    • A larger default_pool_size means each new unit will have plenty of spare space when it comes online, allowing the cluster to be more stable when more traffic is needed.
  • min_pool_size = effective_db_connections / 4
    • Larger min_pool_size and reserve_pool_size (relative to pgbouncer defaults) means that if a unit goes down for whatever reason, the other units in the cluster should be able to easily handle its workload.
  • reserve_pool_size = effective_db_connections / 4

If max_db_connections is set to 0, the derivatives are set as below, based on pgbouncer defaults. It's advised to avoid this and instead set max_db_connections to an amount you're expecting to use, as it will set the following values to better suit your use case.

  • default_pool_size = 20
  • min_pool_size = 10
  • reserve_pool_size = 10

The following config values are set as constants in the charm:

  • max_client_conn = 10000
  • ignore_startup_parameters = extra_float_digits

Relations

  • database
    • Provides a relation to client applications.
    • Importantly, this relation doesn't handle scaling the same way others do. All PgBouncer nodes are read/writes, and they expose the read/write nodes of the backend database through the database name f"{dbname}_readonly".
    • However, the leader node is the only node in the "endpoints" field, and the follower nodes are stored in the "read-only-endpoints" field of the relation databag. This is to preserve interoperability with the postgres charm.
  • backend-database
    • Relates to backend postgresql-operator database charm. Without a backend relation, this charm will enter BlockedStatus - if there's no Postgres backend, this charm has no purpose.

The expected data presented in a relation interface is provided in the docstring at the top of the source files for each relation.

Legacy Relations

The following relations are legacy, and will be deprecated in a future release in favour of relations using the data platform provides library. For future compatibility, build relations with the data platform requires library.

  • db
    • Provides read-write access to backend database
  • db-admin
    • Provides read-write access to backend database
    • The user created by the relation (credentials provided in the relation databag) has admin permissions

License

The Charmed PgBouncer Operator is free software, distributed under the Apache Software License, version 2.0. See LICENSE for more information.

Security

Security issues in the Charmed PgBouncer Operator can be reported through LaunchPad. Please do not file GitHub issues about security issues.

Contributing

Please see the Juju SDK docs for guidelines on enhancements to this charm following best practice guidelines, and CONTRIBUTING.md for developer guidance. For more information, get in touch on the Charmhub Mattermost server.

pgbouncer-operator's People

Contributors

carlcsaposs-canonical avatar dragomirp avatar marceloneppel avatar paulomach avatar renovate[bot] avatar taurus-forever avatar wrfitch avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pgbouncer-operator's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: File contents are invalid JSON but parse using JSON5. Support for this will be removed in a future release so please change to a support .json5 file name or ensure correct JSON syntax.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

  • Update Juju 2 (Juju 2, libjuju 2)
  • Update Python dependencies (black, coverage, jinja2, ops, psycopg, pydantic, pytest, pytest-asyncio, pytest-operator, ruff, typing-extensions, websocket-client)
  • Update GitHub actions (major) (actions/download-artifact, canonical/data-platform-workflows)
  • Click on this checkbox to rebase all open PRs at once

Detected dependencies

github-actions
.github/workflows/ci.yaml
  • actions/checkout v4
  • actions/checkout v4
  • canonical/data-platform-workflows v2
  • actions/checkout v4
  • actions/download-artifact v3
  • ubuntu 22.04
  • ubuntu 22.04
  • ubuntu 22.04
.github/workflows/lib-check.yaml
  • actions/checkout v4
  • canonical/charming-actions 2.4.0
.github/workflows/release.yaml
  • canonical/data-platform-workflows v2
  • canonical/data-platform-workflows v2
.github/workflows/sync_issue_to_jira.yaml
  • canonical/data-platform-workflows v2
pip_requirements
requirements.txt
  • cosl ==0.0.7
  • ops ==2.8.0
  • pgconnstr ==1.0.1
  • poetry-core ==1.8.1
  • pydantic ==1.10.13
  • pyyaml ==6.0.1
  • tenacity ==8.2.3
  • typing-extensions ==4.8.0
  • websocket-client ==1.6.4
poetry
pyproject.toml
  • python ^3.8.10
  • ops 2.8.0
  • pgconnstr 1.0.1
  • tenacity 8.2.3
  • cosl 0.0.7
  • pydantic 1.10.13
  • poetry-core 1.8.1
  • black 23.11.0
  • ruff 0.1.6
  • codespell 2.2.6
  • coverage 7.3.2
  • pytest 7.4.3
  • pytest-asyncio 0.21.1
  • psycopg2 2.9.9
  • jinja2 3.1.2
  • pytest 7.4.3
  • pytest-operator 0.31.0
  • tenacity 8.2.3
  • mailmanclient 3.3.5
  • psycopg2 ^2.9.6
regex
.github/workflows/ci.yaml
  • Juju 2 2.9.45
.github/workflows/ci.yaml
  • Juju 3 3.1.6
pyproject.toml
  • libjuju 3 3.2.0.1
tox.ini
  • libjuju 3 3.2.0.1
pyproject.toml
  • libjuju 2 2.9.45.0
tox.ini
  • libjuju 2 2.9.45.0
charmcraft.yaml
  • psycopg2-binary 2.9.9
  • psycopg 3.1.13

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.