Skip to content

Commit

Permalink
Merge pull request #8 from keithf4/v0.4
Browse files Browse the repository at this point in the history
v0.4 - Update to support pgbouncer 1.16
  • Loading branch information
sharmay authored Sep 7, 2021
2 parents dfae75f + ee705bf commit a6c2751
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v0.4
-- Updated to support pgBouncer 1.16.0. Note that as of v0.4, this extension requires at least version 1.16.0 of pgBouncer. If you still need to support an older version, v0.3 still works and there are no other changes in this version other than a compatibility update.
-- All views are dropped and recreated as part of this update. Privileges should be preserved, but it is recommended to double-check them.


v0.3
-- Add command functions to allow running pgBouncer commands on the target server. Note that the role defined in the user mapping must be given admin access to the pgBouncer admin console. It is recommended to have separate roles in the PostgreSQL database to allow there to be separate user mappings: one for simple monitoring and another for admin console access.

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ LICENSE AND COPYRIGHT

pgbouncer_fdw is released under the PostgreSQL License, a liberal Open Source license, similar to the BSD or MIT licenses.

Copyright (c) 2019 Crunchy Data Solutions, Inc.
Copyright (c) 2021 Crunchy Data Solutions, Inc.

Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pgbouncer_fdw provides a direct SQL interface to the pgbouncer SHOW commands. It

* PostgreSQL 9.4+ - https://www.postgresql.org
* dblink (contrib module) - https://www.postgresql.org/docs/current/dblink.html
* pgbouncer 1.10+ - https://pgbouncer.github.io
* pgbouncer 1.16+ - https://pgbouncer.github.io

## Setup

Expand Down
2 changes: 1 addition & 1 deletion pgbouncer_fdw.control
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
default_version = '0.3'
default_version = '0.4'
comment = 'Extension for querying pgbouncer stats from normal SQL views & running pgbouncer commands from normal SQL functions'
requires = dblink
relocatable = false
150 changes: 137 additions & 13 deletions sql/views/pgbouncer_fdw_views.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@

CREATE VIEW @[email protected]_clients AS
SELECT * FROM dblink('pgbouncer', 'show clients') AS x
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 dblink('pgbouncer', 'show clients') AS x
( type text
, "user" text
, database text
Expand All @@ -19,50 +35,97 @@ CREATE VIEW @[email protected]_clients AS
, remote_pid int
, tls text);


CREATE VIEW @[email protected]_config AS
SELECT * FROM dblink('pgbouncer', 'show config') AS x
SELECT key
, value
, "default"
, changeable
FROM dblink('pgbouncer', 'show config') AS x
( key text
, value text
, "default" text
, changeable boolean);


CREATE VIEW @[email protected]_databases AS
SELECT * FROM dblink('pgbouncer', 'show databases') AS x
SELECT name
, host
, port
, database
, force_user
, pool_size
, min_pool_size
, reserve_pool
, pool_mode
, max_connections
, current_connections
, paused
, disabled
FROM dblink('pgbouncer', 'show databases') AS x
( name text
, host text
, port int
, database text
, force_user text
, pool_size int
, min_pool_size int
, reserve_pool int
, pool_mode text
, max_connections int
, current_connections int
, paused int
, disabled int);


CREATE VIEW @[email protected]_dns_hosts AS
SELECT * FROM dblink('pgbouncer', 'show dns_hosts') AS x
SELECT hostname
, ttl
, addrs
FROM dblink('pgbouncer', 'show dns_hosts') AS x
( hostname text
, ttl bigint
, addrs text);


CREATE VIEW @[email protected]_dns_zones AS
SELECT * FROM dblink('pgbouncer', 'show dns_zones') AS x
SELECT zonename
, serial
, count
FROM dblink('pgbouncer', 'show dns_zones') AS x
( zonename text
, serial text
, count int);


CREATE VIEW @[email protected]_lists AS
SELECT * FROM dblink('pgbouncer', 'show lists') AS x
SELECT list
, items
FROM dblink('pgbouncer', 'show lists') AS x
( list text
, items int);


CREATE VIEW @[email protected]_pools AS
SELECT * FROM dblink('pgbouncer', 'show pools') AS x
SELECT database
, "user"
, cl_active
, cl_waiting
, cl_cancel_req
, sv_active
, sv_idle
, sv_used
, sv_tested
, sv_login
, maxwait
, maxwait_us
, pool_mode
FROM dblink('pgbouncer', 'show pools') AS x
( database text
, "user" text
, cl_active int
, cl_waiting int
, cl_cancel_req int
, sv_active int
, sv_idle int
, sv_used int
Expand All @@ -72,8 +135,26 @@ CREATE VIEW @[email protected]_pools AS
, maxwait_us int
, pool_mode text);


CREATE VIEW @[email protected]_servers AS
SELECT * FROM dblink('pgbouncer', 'show servers') AS x
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 dblink('pgbouncer', 'show servers') AS x
( type text
, "user" text
, database text
Expand All @@ -92,8 +173,33 @@ CREATE VIEW @[email protected]_servers AS
, remote_pid int
, tls text);


CREATE VIEW @[email protected]_sockets AS
SELECT * FROM dblink('pgbouncer', 'show sockets') AS x
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
, recv_pos
, pkt_pos
, pkt_remain
, send_pos
, send_remain
, pkt_avail
, send_avail
FROM dblink('pgbouncer', 'show sockets') AS x
( type text
, "user" text
, database text
Expand All @@ -119,8 +225,24 @@ CREATE VIEW @[email protected]_sockets AS
, pkt_avail int
, send_avail int);


CREATE VIEW @[email protected]_stats AS
SELECT * FROM dblink('pgbouncer', 'show stats') AS x
SELECT database
, total_xact_count
, total_query_count
, total_received
, total_sent
, total_xact_time
, total_query_time
, total_wait_time
, avg_xact_count
, avg_query_count
, avg_recv
, avg_sent
, avg_xact_time
, avg_query_time
, avg_wait_time
FROM dblink('pgbouncer', 'show stats') AS x
( database text
, total_xact_count bigint
, total_query_count bigint
Expand All @@ -137,8 +259,10 @@ CREATE VIEW @[email protected]_stats AS
, avg_query_time bigint
, avg_wait_time bigint );


CREATE VIEW @[email protected]_users AS
SELECT * FROM dblink('pgbouncer', 'show users') AS x
SELECT name
, pool_mode
FROM dblink('pgbouncer', 'show users') AS x
( name text
, pool_mode text);

Loading

0 comments on commit a6c2751

Please sign in to comment.