Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config table #10

Open
davidfetter opened this issue Dec 3, 2021 · 1 comment
Open

Add config table #10

davidfetter opened this issue Dec 3, 2021 · 1 comment

Comments

@davidfetter
Copy link
Owner

Per conversation with and thanks to @fabriziomello, modify pgbouncer_wrapper as folllows:

  • Add a config table with (bouncer_name TEXT PRIMARY KEY, bouncer_connect_string TEXT, active BOOLEAN NOT NULL DEFAULT true);
  • Instead of creating a server, do a LATERAL JOIN to the config table with the connect string instead of the server that's been dropped. The view needs to include the bouncer_name column at a minimum to disambiguate info from multiple bouncers.
  • This way, it's as easy to monitor N pgbouncers as it is to monitor one.
@fabriziomello
Copy link

Example:

CREATE TABLE pgbouncer.instances (
    bouncer_name TEXT PRIMARY KEY,
    bouncer_connect_string TEXT,
    active BOOLEAN NOT NULL DEFAULT true
);

INSERT INTO pgbouncer.instances VALUES ('pgbouncer1', 'host=/tmp port=6432 dbname=pgbouncer');

CREATE OR REPLACE VIEW
  pgbouncer.clients
AS
SELECT
  _.type, _."user", _.database, _.state, _.addr, _.port, _.local_addr,
  _.local_port, _.connect_time, _.request_time, _.wait, _.wait_us,
  _.close_needed, _.ptr, _.link, _.remote_pid, _.tls 
FROM
  pgbouncer.instances
JOIN LATERAL
  dblink(instances.bouncer_connect_string, 'show clients'::text) 
  AS _(type text, "user" text, database text, state text, addr text, port integer, local_addr text, local_port integer, connect_time timestamp with time zone, request_time timestamp with time zone, wait integer, wait_us integer, close_needed integer, ptr text, link text, remote_pid integer, tls text) ON true
WHERE
  instances.active IS TRUE;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants