Skip to content
pgbouncer_fdw

pgbouncer_fdw

pgbouncer_fdw : Extension for querying PgBouncer stats from normal SQL views & running pgbouncer commands from normal SQL functions

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
8650
pgbouncer_fdw
pgbouncer_fdw
1.4.0
FDW
PostgreSQL
SQL
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
----d--
No
No
No
Yes
no
no
Relationships
Requires
dblink
See Also
dblink
postgres_fdw
pg_stat_monitor
pg_stat_statements
wrappers
multicorn
odbc_fdw
jdbc_fdw

Requires dblink and PgBouncer >= 1.17; live queries require a configured PgBouncer admin console.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
MIXED
1.4.0
18
17
16
15
14
pgbouncer_fdwdblink
RPM
PGDG
1.4.0
18
17
16
15
14
pgbouncer_fdw_$v-
DEB
PIGSTY
1.4.0
18
17
16
15
14
postgresql-$v-pgbouncer-fdw-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
el8.aarch64
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
el9.x86_64
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
el9.aarch64
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
el10.x86_64
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
el10.aarch64
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
PGDG 1.4.0
d12.x86_64
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
d12.aarch64
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
d13.x86_64
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
d13.aarch64
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
u22.x86_64
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
u22.aarch64
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
u24.x86_64
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
u24.aarch64
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
u26.x86_64
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
u26.aarch64
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PIGSTY 1.4.0
PackageVersionOSORGSIZEFile URL
pgbouncer_fdw_181.4.0el8.x86_64pgdg24.0 KiBpgbouncer_fdw_18-1.4.0-1PGDG.rhel8.x86_64.rpm
pgbouncer_fdw_181.4.0el8.aarch64pgdg23.9 KiBpgbouncer_fdw_18-1.4.0-1PGDG.rhel8.aarch64.rpm
pgbouncer_fdw_181.4.0el9.x86_64pgdg21.9 KiBpgbouncer_fdw_18-1.4.0-1PGDG.rhel9.8.x86_64.rpm
pgbouncer_fdw_181.4.0el9.x86_64pgdg21.9 KiBpgbouncer_fdw_18-1.4.0-1PGDG.rhel9.x86_64.rpm
pgbouncer_fdw_181.4.0el9.aarch64pgdg21.8 KiBpgbouncer_fdw_18-1.4.0-1PGDG.rhel9.8.aarch64.rpm
pgbouncer_fdw_181.4.0el9.aarch64pgdg21.8 KiBpgbouncer_fdw_18-1.4.0-1PGDG.rhel9.aarch64.rpm
pgbouncer_fdw_181.4.0el10.x86_64pgdg22.1 KiBpgbouncer_fdw_18-1.4.0-1PGDG.rhel10.2.x86_64.rpm
pgbouncer_fdw_181.4.0el10.x86_64pgdg22.4 KiBpgbouncer_fdw_18-1.4.0-1PGDG.rhel10.x86_64.rpm
pgbouncer_fdw_181.4.0el10.aarch64pgdg22.0 KiBpgbouncer_fdw_18-1.4.0-1PGDG.rhel10.2.aarch64.rpm
pgbouncer_fdw_181.4.0el10.aarch64pgdg22.4 KiBpgbouncer_fdw_18-1.4.0-1PGDG.rhel10.aarch64.rpm
postgresql-18-pgbouncer-fdw1.4.0d12.x86_64pigsty16.1 KiBpostgresql-18-pgbouncer-fdw_1.4.0-1PIGSTY~bookworm_all.deb
postgresql-18-pgbouncer-fdw1.4.0d12.aarch64pigsty16.1 KiBpostgresql-18-pgbouncer-fdw_1.4.0-1PIGSTY~bookworm_all.deb
postgresql-18-pgbouncer-fdw1.4.0d13.x86_64pigsty16.1 KiBpostgresql-18-pgbouncer-fdw_1.4.0-1PIGSTY~trixie_all.deb
postgresql-18-pgbouncer-fdw1.4.0d13.aarch64pigsty16.1 KiBpostgresql-18-pgbouncer-fdw_1.4.0-1PIGSTY~trixie_all.deb
postgresql-18-pgbouncer-fdw1.4.0u22.x86_64pigsty16.2 KiBpostgresql-18-pgbouncer-fdw_1.4.0-1PIGSTY~jammy_all.deb
postgresql-18-pgbouncer-fdw1.4.0u22.aarch64pigsty16.2 KiBpostgresql-18-pgbouncer-fdw_1.4.0-1PIGSTY~jammy_all.deb
postgresql-18-pgbouncer-fdw1.4.0u24.x86_64pigsty16.2 KiBpostgresql-18-pgbouncer-fdw_1.4.0-1PIGSTY~noble_all.deb
postgresql-18-pgbouncer-fdw1.4.0u24.aarch64pigsty16.2 KiBpostgresql-18-pgbouncer-fdw_1.4.0-1PIGSTY~noble_all.deb
postgresql-18-pgbouncer-fdw1.4.0u26.x86_64pigsty16.2 KiBpostgresql-18-pgbouncer-fdw_1.4.0-1PIGSTY~resolute_all.deb
postgresql-18-pgbouncer-fdw1.4.0u26.aarch64pigsty16.2 KiBpostgresql-18-pgbouncer-fdw_1.4.0-1PIGSTY~resolute_all.deb

Source

pig build pkg pgbouncer_fdw;		# build deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pgbouncer_fdw;		# install via package name, for the active PG version

pig install pgbouncer_fdw -v 18;   # install for PG 18
pig install pgbouncer_fdw -v 17;   # install for PG 17
pig install pgbouncer_fdw -v 16;   # install for PG 16
pig install pgbouncer_fdw -v 15;   # install for PG 15
pig install pgbouncer_fdw -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pgbouncer_fdw CASCADE; -- requires dblink

Usage

pgbouncer_fdw: Extension for querying PgBouncer stats from normal SQL views and running PgBouncer commands from normal SQL functions

Create Server

CREATE EXTENSION pgbouncer_fdw;

CREATE SERVER pgbouncer FOREIGN DATA WRAPPER dblink_fdw
  OPTIONS (host 'localhost', port '6432', dbname 'pgbouncer');

For multiple PgBouncer instances:

CREATE SERVER pgbouncer1 FOREIGN DATA WRAPPER dblink_fdw
  OPTIONS (host '192.168.1.10', port '6432', dbname 'pgbouncer');
CREATE SERVER pgbouncer2 FOREIGN DATA WRAPPER dblink_fdw
  OPTIONS (host '192.168.1.11', port '6432', dbname 'pgbouncer');

INSERT INTO pgbouncer_fdw_targets (target_host) VALUES ('pgbouncer1'), ('pgbouncer2');
UPDATE pgbouncer_fdw_targets SET active = false WHERE target_host = 'pgbouncer';

Create User Mapping

CREATE USER MAPPING FOR PUBLIC SERVER pgbouncer
  OPTIONS (user 'ccp_monitoring', password 'mypassword');

Available Views

ViewDescription
pgbouncer_clientsClient connection details
pgbouncer_poolsConnection pool statistics
pgbouncer_serversBackend server status
pgbouncer_statsStatistics summary
pgbouncer_databasesDatabase definitions
pgbouncer_configConfiguration parameters
pgbouncer_listsInternal lists
pgbouncer_dns_hostsDNS host cache
pgbouncer_dns_zonesDNS zone cache
pgbouncer_socketsSocket information
pgbouncer_usersUser configuration
SELECT * FROM pgbouncer_pools;
SELECT * FROM pgbouncer_stats;
SELECT database, cl_active, cl_waiting, sv_active FROM pgbouncer_pools;

When monitoring multiple instances, each row includes a pgbouncer_target_host column identifying the source.

Command Functions

Administrative functions (require explicit GRANT EXECUTE):

SELECT pgbouncer_command_reload();              -- Reload configuration
SELECT pgbouncer_command_pause('mydb');          -- Pause a database
SELECT pgbouncer_command_resume('mydb');         -- Resume a database
SELECT pgbouncer_command_kill('mydb');           -- Kill connections
SELECT pgbouncer_command_disable('mydb');        -- Disable a database
SELECT pgbouncer_command_enable('mydb');         -- Enable a database
SELECT pgbouncer_command_reconnect('mydb');      -- Reconnect to backend
SELECT pgbouncer_command_set('key', 'value');    -- Set a parameter
SELECT pgbouncer_command_shutdown();             -- Shutdown PgBouncer
SELECT pgbouncer_command_suspend();              -- Suspend operations
SELECT pgbouncer_command_wait_close('mydb');     -- Wait for connections to close

Permissions

GRANT USAGE ON FOREIGN SERVER pgbouncer TO monitoring_user;
GRANT SELECT ON pgbouncer_pools TO monitoring_user;
GRANT SELECT ON pgbouncer_stats TO monitoring_user;
GRANT EXECUTE ON FUNCTION pgbouncer_command_reload() TO admin_user;
Last updated on