Skip to content

Commit cd8c151

Browse files
committed
Delete orphaned compression_settings before migrating catalog table
When upgrading from 2.18.2 to 2.19.0 with orphaned compression_settings present the update would fail with: ERROR: null values cannot be formatted as an SQL identifier
1 parent 12fbe6b commit cd8c151

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

.unreleased/pr_9795

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #9795 Delete orphaned compression_settings before migrating catalog table

sql/updates/2.18.2--2.19.0.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ INSERT INTO _timescaledb_catalog.compression_algorithm( id, version, name, descr
88
( 6, 1, 'COMPRESSION_ALGORITHM_NULL', 'null')
99
;
1010

11+
-- clean up orphaned compression settings
12+
DELETE FROM _timescaledb_catalog.compression_settings cs
13+
WHERE
14+
NOT EXISTS (SELECT FROM _timescaledb_catalog.hypertable h WHERE format('%I.%I', h.schema_name, h.table_name)::regclass = cs.relid)
15+
AND NOT EXISTS (
16+
SELECT FROM _timescaledb_catalog.chunk cch
17+
JOIN _timescaledb_catalog.chunk ch ON ch.compressed_chunk_id = cch.id
18+
WHERE NOT ch.dropped AND NOT cch.dropped AND format('%I.%I', cch.schema_name, cch.table_name)::regclass = cs.relid
19+
);
20+
1121
-------------------------------
1222
-- Update compression settings
1323
-------------------------------
@@ -95,4 +105,4 @@ CREATE FUNCTION @extschema@.add_continuous_aggregate_policy(
95105
)
96106
RETURNS INTEGER
97107
AS '@MODULE_PATHNAME@', 'ts_update_placeholder'
98-
LANGUAGE C VOLATILE;
108+
LANGUAGE C VOLATILE;

0 commit comments

Comments
 (0)