2929 IF FOUND THEN
3030 RAISE WARNING ' Found relations using the deprecated hypercore access method.' ;
3131 END IF;
32+
3233 -- check for continuous aggregates using non-finalized form
3334 PERFORM FROM _timescaledb_catalog .continuous_agg WHERE NOT finalized;
3435 IF FOUND THEN
@@ -41,13 +42,28 @@ CREATE OR REPLACE FUNCTION pg_temp.check_catalog_corruption() RETURNS void LANGU
4142$$
4243DECLARE
4344 v_count int8;
45+ v_relnames text [];
4446 v_rels regclass[];
4547BEGIN
4648 -- corrupt _timescaledb_catalog.chunk_column_stats entries
4749 SELECT count (* ) INTO v_count FROM _timescaledb_catalog .chunk_column_stats WHERE range_start > range_end;
4850 IF v_count >= 1 THEN
4951 RAISE WARNING ' Found %s entries in _timescaledb_catalog.chunk_column_stats with range_start > range_end' , v_count;
5052 END IF;
53+
54+ -- chunks with missing relations
55+ SELECT count (* ), array_agg(format(' %I.%I' ,ch .schema_name ,ch .table_name )) INTO v_count, v_relnames
56+ FROM _timescaledb_catalog .chunk ch WHERE
57+ NOT dropped AND
58+ 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 );
59+ IF v_count > 0 THEN
60+ IF v_count < 20 THEN
61+ RAISE WARNING ' Found % chunk entries without relations: %' , v_count, v_relnames;
62+ ELSE
63+ RAISE WARNING ' Found % chunk entries without relations' , v_count;
64+ END IF;
65+ END IF;
66+
5167 -- orphaned chunks
5268 SELECT count (* ), array_agg(oid ::regclass) INTO v_count, v_rels
5369 FROM pg_class
@@ -189,7 +205,7 @@ DECLARE
189205 v_batch_sub100 int8;
190206 v_batch_sub100_pct float;
191207 v_batch_sub100_avg float;
192- v_batch_total int8;
208+ v_batch_total int8;
193209 v_chunks_sub100 int8;
194210 v_chunks_total int8;
195211 v_returned_rows int ;
@@ -213,11 +229,11 @@ BEGIN
213229
214230 -- check if batch has more than 20% of batches with less than 100 tuples
215231 EXECUTE format('
216- SELECT
217- count(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100) batch_sub100,
218- avg(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100) batch_sub100_avg,
219- (count(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100)/count(_ts_meta_count)::float) * 100 batch_sub100_pct,
220- count(_ts_meta_count) batch_total
232+ SELECT
233+ count(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100) batch_sub100,
234+ avg(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100) batch_sub100_avg,
235+ (count(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100)/count(_ts_meta_count)::float) * 100 batch_sub100_pct,
236+ count(_ts_meta_count) batch_total
221237 FROM %s HAVING (count(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100)/count(_ts_meta_count)::float) > 0.2;
222238 ' , v_compressed_chunk) INTO v_batch_sub100, v_batch_sub100_avg, v_batch_sub100_pct, v_batch_total;
223239
0 commit comments