Skip to content

Commit

Permalink
fix: fix pgbouncer_server view missing column (#16)
Browse files Browse the repository at this point in the history
* fix: fix pgbouncer_server view missing column

* chore: update changelog

* fix: fix pgbouncer_dns_zones view missing column
  • Loading branch information
keithf4 authored Jul 21, 2023
1 parent a39b774 commit 965a549
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v1.0.1
-- Fix missing comma that caused missing column "pgbouncer_target_host" in "pgbouncer_servers" and "pgbouncer_dns_zones" views


v1.0.0
-- IMPORTANT NOTE: All objects in this extension are dropped and recreated as part of this update. Privileges ARE NOT preserved as part of this update, so please ensure privileges you have on these objects are preserved before upgrading so that they can be reapplied. Note that execution by PUBLIC on the admin functions is once again revoked by this update.

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 = '1.0.0'
default_version = '1.0.1'
comment = 'Extension for querying PgBouncer stats from normal SQL views & running pgbouncer commands from normal SQL functions'
requires = dblink
relocatable = false
6 changes: 2 additions & 4 deletions sql/views/pgbouncer_fdw_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ CREATE VIEW @[email protected]_dns_hosts AS

CREATE VIEW @[email protected]_dns_zones AS
SELECT pgbouncer_target_host
zonename
, zonename
, serial
, count
FROM @[email protected]_dns_zones_func();
Expand Down Expand Up @@ -102,7 +102,7 @@ CREATE VIEW @[email protected]_pools AS

CREATE VIEW @[email protected]_servers AS
SELECT pgbouncer_target_host
"type"
, "type"
, "user"
, database
, state
Expand Down Expand Up @@ -178,5 +178,3 @@ CREATE VIEW @[email protected]_users AS
, name
, pool_mode
FROM @[email protected]_users_func();


65 changes: 65 additions & 0 deletions updates/pgbouncer_fdw--1.0.0--1.0.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
-- Fix missing comma that caused missing column "pgbouncer_target_host" in "pgbouncer_servers" and "pgbouncer_dns_zones" views

CREATE TEMP TABLE pgbouncer_fdw_preserve_privs_temp (statement text);

INSERT INTO pgbouncer_fdw_preserve_privs_temp
SELECT 'GRANT '||string_agg(privilege_type, ',')||' ON @[email protected]_servers TO '||grantee::text||';'
FROM information_schema.table_privileges
WHERE table_schema = '@extschema@'
AND table_name = 'pgbouncer_servers'
GROUP BY grantee;

INSERT INTO pgbouncer_fdw_preserve_privs_temp
SELECT 'GRANT '||string_agg(privilege_type, ',')||' ON @[email protected]_dns_zones TO '||grantee::text||';'
FROM information_schema.table_privileges
WHERE table_schema = '@extschema@'
AND table_name = 'pgbouncer_dns_zones'
GROUP BY grantee;

DROP VIEW @[email protected]_servers;
DROP VIEW @[email protected]_dns_zones;

CREATE OR REPLACE VIEW @[email protected]_servers AS
SELECT pgbouncer_target_host
, "type"
, "user"
, database
, state
, addr
, port
, local_addr
, local_port
, connect_time
, request_time
, wait
, wait_us
, close_needed
, ptr
, link
, remote_pid
, tls
, application_name
FROM @[email protected]_servers_func();


CREATE VIEW @[email protected]_dns_zones AS
SELECT pgbouncer_target_host
, zonename
, serial
, count
FROM @[email protected]_dns_zones_func();

-- Restore dropped object privileges
DO $$
DECLARE
v_row record;
BEGIN
FOR v_row IN SELECT statement FROM pgbouncer_fdw_preserve_privs_temp LOOP
IF v_row.statement IS NOT NULL THEN
EXECUTE v_row.statement;
END IF;
END LOOP;
END
$$;

DROP TABLE IF EXISTS pgbouncer_fdw_preserve_privs_temp;

0 comments on commit 965a549

Please sign in to comment.