Skip to content

Commit

Permalink
Fix pg_dump error on powa_module_config
Browse files Browse the repository at this point in the history
powa_modules are used for cluster-wide pg_stat datasources and do not support
custom datasources.

powa_modules and powa_module_functions got it right and don't have the usual
"added_manually" column used to distinguish custom rows, but
powa_module_functions had a wrong reference to this column.  Also,
powa_module_config was incorrectly created with an added_manually column, and
dump was configure using it but the extension install script was incorrectly
marking some of the init-time data to be custom.

To fix, get rid of any mention of that column in either the table structure of
the dump config.

Thanks to github user guruguruguru for the report.
  • Loading branch information
rjuju committed Dec 18, 2024
1 parent b6d8d6e commit 51067ad
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
52 changes: 52 additions & 0 deletions powa--5.0.0--5.0.1dev.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION powa" to load this file. \quit

ALTER TABLE @[email protected]_module_config DROP COLUMN added_manually;

SELECT pg_catalog.pg_extension_config_dump('@[email protected]_module_config','');
SELECT pg_catalog.pg_extension_config_dump('@[email protected]_module_functions','');

CREATE FUNCTION @[email protected]_activate_module(_srvid int, _module text) RETURNS boolean
AS $_$
DECLARE
v_res bool;
BEGIN
IF (_srvid IS NULL) THEN
RAISE EXCEPTION 'powa_activate_module: no server id provided';
END IF;

IF (_module IS NULL) THEN
RAISE EXCEPTION 'powa_activate_module: no module provided';
END IF;

-- Check that the module is known.
SELECT COUNT(*) = 1 INTO v_res
FROM @[email protected]_modules
WHERE module = _module;

IF (NOT v_res) THEN
RAISE EXCEPTION 'Module "%" is not known', _module;
END IF;

-- The record may already be present, but the enabled flag could be off.
-- If so simply enable it. Otherwise, add the needed record.
SELECT COUNT(*) > 0 INTO v_res
FROM @[email protected]_module_config
WHERE module = _module
AND srvid = _srvid;

IF (v_res) THEN
UPDATE @[email protected]_module_config
SET enabled = true
WHERE enabled = false
AND srvid = _srvid
AND module = _module;
ELSE
INSERT INTO @[email protected]_module_config
(srvid, module)
VALUES
(_srvid, _module);
END IF;

RETURN true;
END;
$_$ LANGUAGE plpgsql
SET search_path = pg_catalog; /* end of powa_activate_module */
17 changes: 8 additions & 9 deletions powa--5.0.1dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,16 @@ CREATE TABLE @[email protected]_module_config (
srvid integer NOT NULL,
module text NOT NULL,
enabled bool NOT NULL default true,
added_manually boolean NOT NULL default true,
PRIMARY KEY (srvid, module),
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (module) REFERENCES @[email protected]_modules(module)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);

INSERT INTO @[email protected]_module_config (srvid, module, added_manually) VALUES
(0, 'pg_database', false),
(0, 'pg_role', false);
INSERT INTO @[email protected]_module_config (srvid, module) VALUES
(0, 'pg_database'),
(0, 'pg_role');

CREATE TABLE @[email protected]_module_functions (
module text NOT NULL,
Expand Down Expand Up @@ -1255,7 +1254,7 @@ BEGIN

-- declare the module and its configuration
INSERT INTO @[email protected]_modules VALUES (_pg_module, _min_version);
INSERT INTO @[email protected]_module_config VALUES (0, _pg_module, false);
INSERT INTO @[email protected]_module_config VALUES (0, _pg_module);
INSERT INTO @[email protected]_module_functions VALUES
(_pg_module, 'snapshot', v_module || '_snapshot', v_module || '_src'),
(_pg_module, 'aggregate', v_module || '_aggregate', NULL),
Expand Down Expand Up @@ -2296,9 +2295,9 @@ BEGIN
AND module = _module;
ELSE
INSERT INTO @[email protected]_module_config
(srvid, module, added_manually)
(srvid, module)
VALUES
(_srvid, _module, (_srvid != 0));
(_srvid, _module);
END IF;

RETURN true;
Expand Down Expand Up @@ -3166,8 +3165,8 @@ SELECT pg_catalog.pg_extension_config_dump('@[email protected]_all_tables_history_
SELECT pg_catalog.pg_extension_config_dump('@[email protected]_extensions','WHERE added_manually');
SELECT pg_catalog.pg_extension_config_dump('@[email protected]_extension_functions','WHERE added_manually');
SELECT pg_catalog.pg_extension_config_dump('@[email protected]_extension_config','WHERE added_manually');
SELECT pg_catalog.pg_extension_config_dump('@[email protected]_module_functions','WHERE added_manually');
SELECT pg_catalog.pg_extension_config_dump('@[email protected]_module_config','WHERE added_manually');
SELECT pg_catalog.pg_extension_config_dump('@[email protected]_module_functions','');
SELECT pg_catalog.pg_extension_config_dump('@[email protected]_module_config','');
SELECT pg_catalog.pg_extension_config_dump('@[email protected]_catalog_databases','');
SELECT pg_catalog.pg_extension_config_dump('@[email protected]_catalog_roles','');
SELECT pg_catalog.pg_extension_config_dump('@[email protected]_catalog_class','');
Expand Down

0 comments on commit 51067ad

Please sign in to comment.