Skip to content

Commit 40b8846

Browse files
committed
Prepare for removal of column dropped from chunk catalog table
1 parent 21384c3 commit 40b8846

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

diagnostic.sql

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ $$;
4242
-- catalog corruption checks
4343
DO $$
4444
DECLARE
45+
v_query text;
4546
v_count int8;
4647
v_relnames text[];
4748
v_rels regclass[];
@@ -53,10 +54,18 @@ BEGIN
5354
END IF;
5455

5556
-- chunks with missing relations
56-
SELECT count(*), array_agg(format('%I.%I',ch.schema_name,ch.table_name)) INTO v_count, v_relnames
57-
FROM _timescaledb_catalog.chunk ch WHERE
58-
NOT dropped AND
59-
NOT EXISTS (SELECT FROM pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid WHERE c.relname=ch.table_name AND n.nspname = ch.schema_name);
57+
-- this check finds chunks that have an entry in our catalog but the actual table is missing
58+
v_query := $sql$
59+
SELECT count(*), array_agg(format('%I.%I',ch.schema_name,ch.table_name))
60+
FROM _timescaledb_catalog.chunk ch WHERE
61+
NOT EXISTS (SELECT FROM pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid WHERE c.relname=ch.table_name AND n.nspname = ch.schema_name)
62+
$sql$;
63+
PERFORM FROM pg_attribute a JOIN pg_class c ON c.oid = a.attrelid AND c.relnamespace='_timescaledb_catalog'::regnamespace AND c.relname = 'chunk' WHERE a.attname = 'dropped';
64+
IF FOUND THEN
65+
v_query := v_query || ' AND NOT ch.dropped';
66+
END IF;
67+
68+
EXECUTE v_query INTO v_count, v_relnames;
6069
IF v_count > 0 THEN
6170
RAISE WARNING 'Found % chunk entries without relations: %', v_count, v_relnames[1:20];
6271
END IF;

0 commit comments

Comments
 (0)