npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pgbouncer-etcd-adapter

v1.0.0

Published

Dynamically configure pgbouncer using etcd.

Downloads

3

Readme

pgbouncer-etcd-adapter

Dynamically configure pgbouncer using etcd.

npm version ISC-licensed minimum Node.js version support me via GitHub Sponsors chat with me on Twitter

pgbouncer-etcd-adapter reads all entries from etcd with a certain prefix (pgbouncer. by default) and generates pgbouncer's configuration files (pgbouncer.ini & userlist.txt) from them.

For example, the following etcd entries

  • pgbouncer.admin_users: postgres
  • pgbouncer.auth_type: md5
  • pgbouncer.unix_socket_dir: /tmp
  • pgbouncer.databases.foo.dbname: bar
  • pgbouncer.databases.foo.host: localhost
  • pgbouncer.databases.foo.port: 12345
  • pgbouncer.userlist.postgres: password

to these pgbouncer config files:

[pgbouncer]

unix_socket_dir = /tmp
admin_users = postgres
auth_type = md5

[databases]

foo = host=localhost port=12345 dbname=bar
"postgres" "password"

Installation

npm install -g pgbouncer-etcd-adapter

or using Docker:

docker pull ghcr.io/derhuerst/pgbouncer-via-etcd:1

Getting Started

Define pgbouncer admin user & password:

export PGBOUNCER_ADMIN_USER=…
export PGBOUNCER_ADMIN_PASSWORD=…

Put some entries into etcd:

etcdtl put pgbouncer.admin_users "$PGBOUNCER_ADMIN_USER"
etcdtl put "pgbouncer.userlist.$PGBOUNCER_ADMIN_USER" "$PGBOUNCER_ADMIN_PASSWORD"
# …

Assuming you have pgbouncer running already, run the adapter:

env \
	PGUSER="$PGBOUNCER_ADMIN_USER" \
	PGPASSWORD="$PGBOUNCER_ADMIN_PASSWORD" \
	configure-pgbouncer-using-etcd

via Docker

First, make sure you have etcd set up. In this guide, we'll asume you'll use plain Docker.

export ETCD_ROOT_PASSWORD=…
docker run -d --name etcd --rm -p 2379:2379 -e ETCD_ROOT_PASSWORD bitnami/etcd:3.5

Then run pgbouncer. Because it contains both pgbouncer and the pgbouncer ↔︎ etcd adapter, the Docker image is not called ghcr.io/derhuerst/pgbouncer-etcd-adapter but ghcr.io/derhuerst/pgbouncer-via-etcd. Configure access to etcd using $ETCD_ADDR.

docker run \
	--name pgbouncer-via-etcd --rm -it \
	--link etcd -e ETCD_ADDR="http://root:$ETCD_ROOT_PASSWORD@etcd:2379" \
	-e PGBOUNCER_ADMIN_USER -e PGBOUNCER_ADMIN_PASSWORD \
	ghcr.io/derhuerst/pgbouncer-with-etcd:1

Note: If you don't set pgbouncer.userlist.$PGBOUNCER_ADMIN_USER to $PGBOUNCER_ADMIN_PASSWORD, the container will immediately regenerate userlist without an entry for $PGBOUNCER_ADMIN_USER, so that the container's health check will fail.

Usage

Usage:
    configure-pgbouncer-using-etcd
Options:
    -w  --watch                     Watch the etcd namespace, and regenerate the pgbouncer
                                      config as soon as any value has changed.
                                      Default: false
    -p  --etcd-prefix               Key prefix in etcd to query/watch.
                                      Default: pgbouncer.
    -c  --path-to-pgbouncer-ini     Where pgbouncer's pgbouncer.ini shall be written to.
                                      Default: $PWD/pgbouncer.ini
    -u  --path-to-userlist-txt      Where pgbouncer's userlist.txt shall be written to.
                                      Default: $PWD/pgbouncer.ini
    -q  --quiet                     Do not print a message to stdout whenever pgbouncer's
                                      config has been modified.
                                      Default: false
        --no-atomic-writes          Instead of writing atomically by
                                       1) writing into a temporary file and
                                       2) moving this temp file to the target path,
                                      *do not* write atomically.
                                      Default: false
    -d  --debounce                  With bursts of changes coming from etcds, the time to
                                      delay regeneration of the config for, at most, in
                                      milliseconds. Pass 0 to regenerate on every change
                                      immediately.
                                      Default: 200
        --listen-for-sigusr1        Reconfigure pgbouncer when the process receives a
                                      SIGUSR1 signal.
                                      Default: false
        --no-pgbouncer-reload       Once the config has been regenerated, *do not* tell
                                      pgbouncer to
                                      1. reload the config (using `RELOAD`)
                                      2. reestablish all connections to DBs & clients
                                         using `SUSPEND; RESUME`
                                      Default: false
Notes:
    Unless --no-pgbouncer-reload is passed, this tool will connect to pgbouncer's
    special `pgbouncer` "admin console" DB that allows controlling it via SQL. [1]
    It will respect up the libpg environment variables [2].
    [1] https://www.pgbouncer.org/usage.html#admin-console
    [2] https://www.postgresql.org/docs/16/libpq-envars.html
Examples:
    configure-pgbouncer-using-etcd -c /etc/pgbouncer/pgbouncer.ini --watch
    configure-pgbouncer-using-etcd --etcd-prefix pgb --no-atomic-writes

Contributing

If you have a question or need support using pgbouncer-etcd-adapter, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use the issues page.