22-- Please see the included NOTICE for copyright information and
33-- LICENSE-APACHE for a copy of the license.
44
5+ -- Chunk relation names are not deterministic between a fresh install and a post-upgrade catalog.
6+ CREATE OR REPLACE FUNCTION pg_temp .normalize_chunk(t text ) RETURNS text
7+ LANGUAGE sql IMMUTABLE AS $$
8+ SELECT regexp_replace(
9+ regexp_replace(t,
10+ ' compress_hyper_[0-9]+_[0-9]+_chunk|_hyper_[0-9]+_[0-9]+_chunk_compressed' ,
11+ ' compressed_chunk' , ' g' ),
12+ ' (_hyper_[0-9]+)_[0-9]+_chunk' , ' \1 _X_chunk' , ' g' )
13+ $$;
14+
515SELECT NOT (extversion >= ' 2.19.0' AND extversion <= ' 2.20.3' ) AS has_fixed_compression_algorithms
616 FROM pg_extension
717 WHERE extname = ' timescaledb' \gset
@@ -161,10 +171,10 @@ ORDER BY conrelid::regclass::text, contype, conname, confrelid::regclass::text;
161171
162172-- child tables
163173SELECT parent .relname AS table_name,
164- i .inhrelid ::regclass AS child_table
174+ pg_temp . normalize_chunk ( i .inhrelid ::regclass:: text ) AS child_table
165175FROM pg_catalog .pg_inherits i
166176JOIN pg_catalog .pg_class parent ON parent .oid = i .inhparent AND parent .relnamespace = ' public' ::regnamespace
167- ORDER BY parent .relname , i .inhrelid ::regclass::text ;
177+ ORDER BY parent .relname , pg_temp . normalize_chunk ( i .inhrelid ::regclass::text ) ;
168178
169179-- Keep the output backward compatible
170180\if :PG_UPGRADE_TEST
@@ -199,24 +209,25 @@ ORDER BY parent.relname, i.inhrelid::regclass::text;
199209-- The list of tables configured to be dumped.
200210SELECT unnest(extconfig)::regclass::text , unnest(extcondition) FROM pg_extension WHERE extname = ' timescaledb' ORDER BY 1 ;
201211
202- -- Show chunks that include owner in the output
203- SELECT c .id , c .hypertable_id , c .schema_name , c .table_name , cl .relowner ::regrole
212+ -- Show chunks that include owner in the output. The chunk id is not
213+ -- deterministic post-upgrade, so drop it and normalize the chunk relation name.
214+ SELECT c .hypertable_id , c .schema_name , pg_temp .normalize_chunk (c .table_name ) AS table_name, cl .relowner ::regrole
204215FROM _timescaledb_catalog .chunk c
205216INNER JOIN pg_class cl ON (cl .oid = format(' %I.%I' , schema_name, table_name)::regclass)
206- ORDER BY c .id , c . hypertable_id ;
217+ ORDER BY c .hypertable_id , pg_temp . normalize_chunk ( c . table_name ) ;
207218
208- -- Per-chunk dimensional ranges. Slice ids are assigned by SERIAL and differ
209- -- between a fresh install and a post-upgrade catalog, so dump path-stable
210- -- columns only.
219+ -- Per-chunk dimensional ranges. Slice ids are assigned by SERIAL and chunk ids
220+ -- are renumbered, so both differ between a fresh install and a post-upgrade
221+ -- catalog. Dump and order by the dimensional range only.
211222\if :has_chunk_owned_slices
212- SELECT ds .chunk_id , ds . dimension_id , ds .range_start , ds .range_end
223+ SELECT ds .dimension_id , ds .range_start , ds .range_end
213224FROM _timescaledb_catalog .dimension_slice ds
214- ORDER BY ds .chunk_id , ds .dimension_id ;
225+ ORDER BY ds .dimension_id , ds .range_start , ds . range_end ;
215226\else
216- SELECT cc . chunk_id , ds .dimension_id , ds .range_start , ds .range_end
227+ SELECT ds .dimension_id , ds .range_start , ds .range_end
217228FROM _timescaledb_catalog .chunk_constraint cc
218229JOIN _timescaledb_catalog .dimension_slice ds ON ds .id = cc .dimension_slice_id
219- ORDER BY cc . chunk_id , ds .dimension_id ;
230+ ORDER BY ds . dimension_id , ds .range_start , ds . range_end ;
220231\endif
221232
222233-- Show attributes of all regclass objects belonging to our extension
@@ -240,7 +251,7 @@ ORDER BY attrelid::regclass::text COLLATE "C", a.attnum;
240251-- form (2.28.0) compare equal. The dimensional CHECKs are named
241252-- "constraint_<slice_id>" and slice ids are not deterministic between a
242253-- fresh install and a post-upgrade catalog, so collapse the suffix too.
243- SELECT conrelid::regclass::text ,
254+ SELECT pg_temp . normalize_chunk ( conrelid::regclass::text ) AS conrelid ,
244255 regexp_replace(
245256 regexp_replace(conname, ' ^([0-9]+_){1,2}' , ' ' ),
246257 ' ^constraint_[0-9]+$' , ' constraint_dim' ) AS conname,
@@ -256,4 +267,8 @@ ORDER BY 1, 2, 3;
256267-- orderby sparse index type changed across releases and existing chunks are
257268-- not rewritten on upgrade), so it differs between a fresh install and a
258269-- post-upgrade catalog. Skip it and compare the remaining columns.
259- SELECT relid, compress_relid, segmentby, orderby, orderby_desc, orderby_nullsfirst FROM _timescaledb_catalog .compression_settings ORDER BY relid::regclass::text ;
270+ SELECT pg_temp .normalize_chunk (relid::regclass::text ) AS relid,
271+ pg_temp .normalize_chunk (compress_relid::regclass::text ) AS compress_relid,
272+ segmentby, orderby, orderby_desc, orderby_nullsfirst
273+ FROM _timescaledb_catalog .compression_settings
274+ ORDER BY pg_temp .normalize_chunk (relid::regclass::text ), segmentby, orderby;
0 commit comments