Skip to content

Commit 1bb22dd

Browse files
keithf4pgguru
andauthored
Add support for pgbouncer 1.21 (#18)
* fix: fix pgbouncer_server view missing column * chore: update changelog * fix: fix pgbouncer_dns_zones view missing column * add support for pgbouncer 1.21 * add support for pgbouncer 1.21 * Apply suggestions from code review Co-authored-by: David Christensen <[email protected]> * fix comparison logic for inbetween bouncer versions * fix invalid conditional and order of object dropping --------- Co-authored-by: David Christensen <[email protected]>
1 parent 965a549 commit 1bb22dd

File tree

5 files changed

+924
-4
lines changed

5 files changed

+924
-4
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v1.1.0
2+
-- Add support for PgBouncer 1.21. Adds prepared_statements column to clients, servers and sockets functions and views.
3+
4+
15
v1.0.1
26
-- Fix missing comma that caused missing column "pgbouncer_target_host" in "pgbouncer_servers" and "pgbouncer_dns_zones" views
37

pgbouncer_fdw.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
default_version = '1.0.1'
1+
default_version = '1.1.0'
22
comment = 'Extension for querying PgBouncer stats from normal SQL views & running pgbouncer commands from normal SQL functions'
33
requires = dblink
44
relocatable = false

sql/functions/pgbouncer_fdw_functions.sql

Lines changed: 157 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ CREATE FUNCTION @[email protected]_clients_func() RETURNS TABLE
7979
, remote_pid int
8080
, tls text
8181
, application_name text
82+
, prepared_statements int
8283
)
8384
LANGUAGE plpgsql
8485
AS $$
@@ -100,7 +101,50 @@ LOOP BEGIN
100101
INTO v_version_major, v_version_minor
101102
FROM @[email protected]_version_func(v_row.target_host);
102103

103-
IF v_version_major >= 1 AND v_version_minor >= 18 THEN
104+
IF v_version_major >= 1 AND v_version_minor >= 21 THEN
105+
RETURN QUERY SELECT
106+
v_row.target_host AS pgbouncer_target_host
107+
, x."type"
108+
, x."user"
109+
, x.database
110+
, x.state
111+
, x.addr
112+
, x.port
113+
, x.local_addr
114+
, x.local_port
115+
, x.connect_time
116+
, x.request_time
117+
, x.wait
118+
, x.wait_us
119+
, x.close_needed
120+
, x.ptr
121+
, x.link
122+
, x.remote_pid
123+
, x.tls
124+
, x.application_name
125+
, x.prepared_statements
126+
FROM dblink(v_row.target_host, 'show clients') AS x
127+
( "type" text
128+
, "user" text
129+
, database text
130+
, state text
131+
, addr text
132+
, port int
133+
, local_addr text
134+
, local_port int
135+
, connect_time timestamp with time zone
136+
, request_time timestamp with time zone
137+
, wait int
138+
, wait_us int
139+
, close_needed int
140+
, ptr text
141+
, link text
142+
, remote_pid int
143+
, tls text
144+
, application_name text
145+
, prepared_statements int
146+
);
147+
ELSIF v_version_major = 1 AND v_version_minor >= 18 AND v_version_minor < 21 THEN
104148
RETURN QUERY SELECT
105149
v_row.target_host AS pgbouncer_target_host
106150
, x."type"
@@ -121,6 +165,7 @@ LOOP BEGIN
121165
, x.remote_pid
122166
, x.tls
123167
, x.application_name
168+
, 0 AS prepared_statements
124169
FROM dblink(v_row.target_host, 'show clients') AS x
125170
( "type" text
126171
, "user" text
@@ -163,6 +208,7 @@ LOOP BEGIN
163208
, x.remote_pid
164209
, x.tls
165210
, '' AS application_name
211+
, 0 AS prepared_statements
166212
FROM dblink(v_row.target_host, 'show clients') AS x
167213
( "type" text
168214
, "user" text
@@ -665,6 +711,7 @@ CREATE FUNCTION @[email protected]_servers_func() RETURNS TABLE
665711
, remote_pid int
666712
, tls text
667713
, application_name text
714+
, prepared_statements int
668715
)
669716
LANGUAGE plpgsql
670717
AS $$
@@ -686,7 +733,7 @@ LOOP BEGIN
686733
INTO v_version_major, v_version_minor
687734
FROM @[email protected]_version_func(v_row.target_host);
688735

689-
IF v_version_major >= 1 AND v_version_minor >= 18 THEN
736+
IF v_version_major >= 1 AND v_version_minor >= 21 THEN
690737
RETURN QUERY SELECT
691738
v_row.target_host AS pgbouncer_target_host
692739
, x."type"
@@ -707,6 +754,51 @@ LOOP BEGIN
707754
, x.remote_pid
708755
, x.tls
709756
, x.application_name
757+
, x.prepared_statements
758+
FROM dblink(v_row.target_host, 'show servers') AS x
759+
(
760+
"type" text
761+
, "user" text
762+
, database text
763+
, state text
764+
, addr text
765+
, port int
766+
, local_addr text
767+
, local_port int
768+
, connect_time timestamp with time zone
769+
, request_time timestamp with time zone
770+
, wait int
771+
, wait_us int
772+
, close_needed int
773+
, ptr text
774+
, link text
775+
, remote_pid int
776+
, tls text
777+
, application_name text
778+
, prepared_statements int
779+
);
780+
ELSIF v_version_major = 1 AND v_version_minor >= 18 and v_version_minor < 21 THEN
781+
RETURN QUERY SELECT
782+
v_row.target_host AS pgbouncer_target_host
783+
, x."type"
784+
, x."user"
785+
, x.database
786+
, x.state
787+
, x.addr
788+
, x.port
789+
, x.local_addr
790+
, x.local_port
791+
, x.connect_time
792+
, x.request_time
793+
, x.wait
794+
, x.wait_us
795+
, x.close_needed
796+
, x.ptr
797+
, x.link
798+
, x.remote_pid
799+
, x.tls
800+
, x.application_name
801+
, 0 AS prepared_statements
710802
FROM dblink(v_row.target_host, 'show servers') AS x
711803
(
712804
"type" text
@@ -750,6 +842,7 @@ LOOP BEGIN
750842
, x.remote_pid
751843
, x.tls
752844
, '' AS application_name
845+
, 0 AS prepared_statements
753846
FROM dblink(v_row.target_host, 'show servers') AS x
754847
(
755848
"type" text
@@ -823,6 +916,7 @@ CREATE FUNCTION @[email protected]_sockets_func() RETURNS TABLE
823916
, send_remain int
824917
, pkt_avail int
825918
, send_avail int
919+
, prepared_statements int
826920
)
827921
LANGUAGE plpgsql
828922
AS $$
@@ -843,7 +937,65 @@ LOOP BEGIN
843937
INTO v_version_major, v_version_minor
844938
FROM @[email protected]_version_func(v_row.target_host);
845939

846-
IF v_version_major >= 1 AND v_version_minor >= 18 THEN
940+
IF v_version_major >= 1 AND v_version_minor >= 21 THEN
941+
RETURN QUERY SELECT
942+
v_row.target_host AS pgbouncer_target_host
943+
, x."type"
944+
, x."user"
945+
, x.database
946+
, x.state
947+
, x.addr
948+
, x.port
949+
, x.local_addr
950+
, x.local_port
951+
, x.connect_time
952+
, x.request_time
953+
, x.wait
954+
, x.wait_us
955+
, x.close_needed
956+
, x.ptr
957+
, x.link
958+
, x.remote_pid
959+
, x.tls
960+
, x.application_name
961+
, x.recv_pos
962+
, x.pkt_pos
963+
, x.pkt_remain
964+
, x.send_pos
965+
, x.send_remain
966+
, x.pkt_avail
967+
, x.send_avail
968+
, x.prepared_statements
969+
FROM dblink(v_row.target_host, 'show sockets') AS x
970+
(
971+
"type" text
972+
, "user" text
973+
, database text
974+
, state text
975+
, addr text
976+
, port int
977+
, local_addr text
978+
, local_port int
979+
, connect_time timestamp with time zone
980+
, request_time timestamp with time zone
981+
, wait int
982+
, wait_us int
983+
, close_needed int
984+
, ptr text
985+
, link text
986+
, remote_pid int
987+
, tls text
988+
, application_name text
989+
, recv_pos int
990+
, pkt_pos int
991+
, pkt_remain int
992+
, send_pos int
993+
, send_remain int
994+
, pkt_avail int
995+
, send_avail int
996+
, prepared_statements int
997+
);
998+
ELSIF v_version_major = 1 AND v_version_minor >= 18 AND v_version_minor < 21 THEN
847999
RETURN QUERY SELECT
8481000
v_row.target_host AS pgbouncer_target_host
8491001
, x."type"
@@ -871,6 +1023,7 @@ LOOP BEGIN
8711023
, x.send_remain
8721024
, x.pkt_avail
8731025
, x.send_avail
1026+
, 0 AS prepared_statements
8741027
FROM dblink(v_row.target_host, 'show sockets') AS x
8751028
(
8761029
"type" text
@@ -928,6 +1081,7 @@ LOOP BEGIN
9281081
, x.send_remain
9291082
, x.pkt_avail
9301083
, x.send_avail
1084+
, 0 AS prepared_statements
9311085
FROM dblink(v_row.target_host, 'show sockets') AS x
9321086
(
9331087
"type" text

sql/views/pgbouncer_fdw_views.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ CREATE VIEW @[email protected]_clients AS
2626
, remote_pid
2727
, tls
2828
, application_name
29+
, prepared_statements
2930
FROM @[email protected]_clients_func();
3031

3132

@@ -120,6 +121,7 @@ CREATE VIEW @[email protected]_servers AS
120121
, remote_pid
121122
, tls
122123
, application_name
124+
, prepared_statements
123125
FROM @[email protected]_servers_func();
124126

125127

@@ -150,6 +152,7 @@ CREATE VIEW @[email protected]_sockets AS
150152
, send_remain
151153
, pkt_avail
152154
, send_avail
155+
, prepared_statements
153156
FROM @[email protected]_sockets_func();
154157

155158

0 commit comments

Comments
 (0)