Skip to content

Commit 5d119d0

Browse files
committed
Add query for orphanded chunks
1 parent 14320c0 commit 5d119d0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

diagnostic.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@ $$
2424
DECLARE
2525
v_count int8;
2626
BEGIN
27+
-- corrupt _timescaledb_catalog.chunk_column_stats entries
2728
SELECT count(*) INTO v_count FROM _timescaledb_catalog.chunk_column_stats WHERE range_start > range_end;
2829
IF v_count >= 1 THEN
2930
RAISE WARNING 'Found %s entries in _timescaledb_catalog.chunk_column_stats with range_start > range_end', v_count;
3031
END IF;
32+
-- orphaned chunks
33+
SELECT count(*), array_agg(oid::regclass) INTO v_count, v_rels
34+
FROM pg_class
35+
WHERE
36+
relnamespace='_timescaledb_internal'::regnamespace AND
37+
relkind='r' AND
38+
relname LIKE '%_chunk' AND
39+
NOT EXISTS(SELECT FROM _timescaledb_catalog.chunk where schema_name='_timescaledb_internal' and table_name = relname);
40+
IF v_count >= 1 THEN
41+
RAISE WARNING 'Found % orphaned chunk relations: %', v_count, v_rels;
42+
END IF;
3143
END
3244
$$ SET search_path = pg_catalog, pg_temp;
3345

0 commit comments

Comments
 (0)