Skip to content

Commit

Permalink
Fix previous commit compatibility with pg16-
Browse files Browse the repository at this point in the history
Older versions of postgres don't support a STORAGE clause in a CREATE TABLE
statements, so split it in CREATE TABLE / ALTER TABLE statements.

While at it add a regression test to make sure that we don't forget it when
adding a new history table.
  • Loading branch information
rjuju committed Jul 8, 2024
1 parent 46b5bf9 commit edfbc9e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 28 deletions.
21 changes: 21 additions & 0 deletions expected/01_general.out
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ ORDER BY descr COLLATE "C";
event trigger powa_check_dropped_extensions
(2 rows)

-- check (mins|maxs)_in_range columns not marked as STORAGE MAIN
WITH ext AS (
SELECT c.oid, c.relname
FROM pg_depend d
JOIN pg_extension e ON d.refclassid = 'pg_extension'::regclass
AND e.oid = d.refobjid
AND e.extname = 'powa'
JOIN pg_class c ON d.classid = 'pg_class'::regclass
AND c.oid = d.objid
WHERE c.relkind != 'v'
)
SELECT ext.relname, a.attname
FROM ext
JOIN pg_attribute a ON a.attrelid = ext.oid
WHERE a.attname ~ '(mins|maxs)'
AND a.attstorage != 'm'
ORDER BY ext.relname::text COLLATE "C", a.attname::text COLLATe "C";
relname | attname
---------+---------
(0 rows)

-- Aggregate data every 5 snapshots
SET powa.coalesce = 5;
-- Test created ojects
Expand Down
84 changes: 56 additions & 28 deletions powa--5.0.0dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1353,11 +1353,13 @@ BEGIN
v_sql := v_sql || format('
coalesce_range tstzrange NOT NULL,
records @extschema@.%2$I[] NOT NULL,
mins_in_range @extschema@.%3$I STORAGE MAIN NOT NULL,
maxs_in_range @extschema@.%3$I STORAGE MAIN NOT NULL,
mins_in_range @extschema@.%3$I NOT NULL,
maxs_in_range @extschema@.%3$I NOT NULL,
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @extschema@.%1$I ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @extschema@.%1$I ALTER COLUMN maxs_in_range SET STORAGE MAIN;
CREATE INDEX %4$I ON @extschema@.%1$I USING gist(srvid, coalesce_range);',
v_module || '_history', v_module || '_history_record',
v_suffix, v_module || '_history_ts');
Expand Down Expand Up @@ -2031,11 +2033,13 @@ CREATE TABLE @[email protected]_statements_history (
userid oid NOT NULL,
coalesce_range tstzrange NOT NULL,
records @[email protected]_statements_history_record[] NOT NULL,
mins_in_range @[email protected]_statements_history_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_statements_history_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_statements_history_record NOT NULL,
maxs_in_range @[email protected]_statements_history_record NOT NULL,
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @[email protected]_statements_history ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_statements_history ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX powa_statements_history_query_ts ON @[email protected]_statements_history USING gist (srvid, queryid, coalesce_range);

Expand All @@ -2044,11 +2048,13 @@ CREATE TABLE @[email protected]_statements_history_db (
dbid oid NOT NULL,
coalesce_range tstzrange NOT NULL,
records @[email protected]_statements_history_record[] NOT NULL,
mins_in_range @[email protected]_statements_history_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_statements_history_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_statements_history_record NOT NULL,
maxs_in_range @[email protected]_statements_history_record NOT NULL,
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @[email protected]_statements_history_db ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_statements_history_db ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX powa_statements_history_db_ts ON @[email protected]_statements_history_db USING gist (srvid, dbid, coalesce_range);

Expand Down Expand Up @@ -2079,11 +2085,13 @@ CREATE TABLE @[email protected]_user_functions_history (
funcid oid NOT NULL,
coalesce_range tstzrange NOT NULL,
records @[email protected]_user_functions_history_record[] NOT NULL,
mins_in_range @[email protected]_user_functions_history_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_user_functions_history_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_user_functions_history_record NOT NULL,
maxs_in_range @[email protected]_user_functions_history_record NOT NULL,
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @[email protected]_user_functions_history ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_user_functions_history ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX powa_user_functions_history_funcid_ts ON @[email protected]_user_functions_history USING gist (srvid, funcid, coalesce_range);

Expand All @@ -2092,11 +2100,13 @@ CREATE TABLE @[email protected]_user_functions_history_db (
dbid oid NOT NULL,
coalesce_range tstzrange NOT NULL,
records @[email protected]_user_functions_history_record[] NOT NULL,
mins_in_range @[email protected]_user_functions_history_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_user_functions_history_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_user_functions_history_record NOT NULL,
maxs_in_range @[email protected]_user_functions_history_record NOT NULL,
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @[email protected]_user_functions_history_db ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_user_functions_history_db ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX powa_user_functions_history_db_dbid_ts ON @[email protected]_user_functions_history USING gist (srvid, dbid, coalesce_range);

Expand Down Expand Up @@ -2126,11 +2136,13 @@ CREATE TABLE @[email protected]_all_indexes_history (
indexrelid oid NOT NULL,
coalesce_range tstzrange NOT NULL,
records @[email protected]_all_indexes_history_record[] NOT NULL,
mins_in_range @[email protected]_all_indexes_history_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_all_indexes_history_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_all_indexes_history_record NOT NULL,
maxs_in_range @[email protected]_all_indexes_history_record NOT NULL,
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @[email protected]_all_indexes_history ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_all_indexes_history ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX powa_all_indexes_history_relid_ts ON @[email protected]_all_indexes_history USING gist (srvid, relid, coalesce_range);

Expand All @@ -2139,11 +2151,13 @@ CREATE TABLE @[email protected]_all_indexes_history_db (
dbid oid NOT NULL,
coalesce_range tstzrange NOT NULL,
records @[email protected]_all_indexes_history_db_record[] NOT NULL,
mins_in_range @[email protected]_all_indexes_history_db_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_all_indexes_history_db_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_all_indexes_history_db_record NOT NULL,
maxs_in_range @[email protected]_all_indexes_history_db_record NOT NULL,
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @[email protected]_all_indexes_history_db ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_all_indexes_history_db ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX powa_all_indexes_history_db_dbid_ts ON @[email protected]_all_indexes_history_db USING gist (srvid, dbid, coalesce_range);

Expand Down Expand Up @@ -2173,11 +2187,13 @@ CREATE TABLE @[email protected]_all_tables_history (
relid oid NOT NULL,
coalesce_range tstzrange NOT NULL,
records @[email protected]_all_tables_history_record[] NOT NULL,
mins_in_range @[email protected]_all_tables_history_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_all_tables_history_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_all_tables_history_record NOT NULL,
maxs_in_range @[email protected]_all_tables_history_record NOT NULL,
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @[email protected]_all_tables_history ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_all_tables_history ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX powa_all_tables_history_relid_ts ON @[email protected]_all_tables_history USING gist (srvid, relid, coalesce_range);

Expand All @@ -2186,11 +2202,13 @@ CREATE TABLE @[email protected]_all_tables_history_db (
dbid oid NOT NULL,
coalesce_range tstzrange NOT NULL,
records @[email protected]_all_tables_history_db_record[] NOT NULL,
mins_in_range @[email protected]_all_tables_history_db_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_all_tables_history_db_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_all_tables_history_db_record NOT NULL,
maxs_in_range @[email protected]_all_tables_history_db_record NOT NULL,
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @[email protected]_all_tables_history_db ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_all_tables_history_db ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX powa_all_tables_history_db_dbid_ts ON @[email protected]_all_tables_history_db USING gist (srvid, dbid, coalesce_range);

Expand Down Expand Up @@ -2844,13 +2862,15 @@ CREATE TABLE @[email protected]_kcache_metrics (
dbid oid NOT NULL,
userid oid NOT NULL,
metrics @[email protected]_kcache_history_record[] NOT NULL,
mins_in_range @[email protected]_kcache_history_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_kcache_history_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_kcache_history_record NOT NULL,
maxs_in_range @[email protected]_kcache_history_record NOT NULL,
top boolean NOT NULL,
PRIMARY KEY (srvid, coalesce_range, queryid, dbid, userid, top),
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @[email protected]_kcache_metrics ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_kcache_metrics ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX ON @[email protected]_kcache_metrics (srvid, queryid);

Expand All @@ -2859,13 +2879,15 @@ CREATE TABLE @[email protected]_kcache_metrics_db (
coalesce_range tstzrange NOT NULL,
dbid oid NOT NULL,
metrics @[email protected]_kcache_history_record[] NOT NULL,
mins_in_range @[email protected]_kcache_history_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_kcache_history_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_kcache_history_record NOT NULL,
maxs_in_range @[email protected]_kcache_history_record NOT NULL,
top boolean NOT NULL,
PRIMARY KEY (srvid, coalesce_range, dbid, top),
FOREIGN KEY (srvid) REFERENCES @[email protected]_servers(id)
MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @[email protected]_kcache_metrics_db ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_kcache_metrics_db ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE TABLE @[email protected]_kcache_metrics_current ( srvid integer NOT NULL,
queryid bigint NOT NULL,
Expand Down Expand Up @@ -2946,10 +2968,12 @@ CREATE TABLE @[email protected]_qualstats_quals_history (
userid oid,
coalesce_range tstzrange,
records @[email protected]_qualstats_history_record[],
mins_in_range @[email protected]_qualstats_history_record STORAGE MAIN,
maxs_in_range @[email protected]_qualstats_history_record STORAGE MAIN,
mins_in_range @[email protected]_qualstats_history_record,
maxs_in_range @[email protected]_qualstats_history_record,
FOREIGN KEY (srvid, qualid, queryid, dbid, userid) REFERENCES @[email protected]_qualstats_quals (srvid, qualid, queryid, dbid, userid) MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE @[email protected]_qualstats_quals_history ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_qualstats_quals_history ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX powa_qualstats_quals_history_query_ts ON @[email protected]_qualstats_quals_history USING gist (srvid, queryid, coalesce_range);

Expand Down Expand Up @@ -3029,10 +3053,12 @@ CREATE TABLE @[email protected]_wait_sampling_history (
event_type text NOT NULL,
event text NOT NULL,
records @[email protected]_wait_sampling_history_record[] NOT NULL,
mins_in_range @[email protected]_wait_sampling_history_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_wait_sampling_history_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_wait_sampling_history_record NOT NULL,
maxs_in_range @[email protected]_wait_sampling_history_record NOT NULL,
PRIMARY KEY (srvid, coalesce_range, queryid, dbid, event_type, event)
);
ALTER TABLE @[email protected]_wait_sampling_history ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_wait_sampling_history ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX powa_wait_sampling_history_query_ts ON @[email protected]_wait_sampling_history USING gist (srvid, queryid, coalesce_range);

Expand All @@ -3044,10 +3070,12 @@ CREATE TABLE @[email protected]_wait_sampling_history_db (
event_type text NOT NULL,
event text NOT NULL,
records @[email protected]_wait_sampling_history_record[] NOT NULL,
mins_in_range @[email protected]_wait_sampling_history_record STORAGE MAIN NOT NULL,
maxs_in_range @[email protected]_wait_sampling_history_record STORAGE MAIN NOT NULL,
mins_in_range @[email protected]_wait_sampling_history_record NOT NULL,
maxs_in_range @[email protected]_wait_sampling_history_record NOT NULL,
PRIMARY KEY (srvid, coalesce_range, dbid, event_type, event)
);
ALTER TABLE @[email protected]_wait_sampling_history_db ALTER COLUMN mins_in_range SET STORAGE MAIN;
ALTER TABLE @[email protected]_wait_sampling_history_db ALTER COLUMN maxs_in_range SET STORAGE MAIN;

CREATE INDEX powa_wait_sampling_history_db_ts ON @[email protected]_wait_sampling_history_db USING gist (srvid, dbid, coalesce_range);

Expand Down
18 changes: 18 additions & 0 deletions sql/01_general.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ FROM ext
WHERE descr NOT LIKE '%"PoWA"%'
ORDER BY descr COLLATE "C";

-- check (mins|maxs)_in_range columns not marked as STORAGE MAIN
WITH ext AS (
SELECT c.oid, c.relname
FROM pg_depend d
JOIN pg_extension e ON d.refclassid = 'pg_extension'::regclass
AND e.oid = d.refobjid
AND e.extname = 'powa'
JOIN pg_class c ON d.classid = 'pg_class'::regclass
AND c.oid = d.objid
WHERE c.relkind != 'v'
)
SELECT ext.relname, a.attname
FROM ext
JOIN pg_attribute a ON a.attrelid = ext.oid
WHERE a.attname ~ '(mins|maxs)'
AND a.attstorage != 'm'
ORDER BY ext.relname::text COLLATE "C", a.attname::text COLLATe "C";

-- Aggregate data every 5 snapshots
SET powa.coalesce = 5;

Expand Down

0 comments on commit edfbc9e

Please sign in to comment.