Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/diagnostic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:
INSERT INTO t SELECT '2025-01-01';
INSERT INTO t SELECT '2025-02-01';
SELECT compress_chunk(show_chunks('t'));
-- test orphaned chunks
CREATE TABLE _timescaledb_internal.compress_hyper_100_1_chunk();
CREATE TABLE _timescaledb_internal._hyper_100_1_chunk();
SQL
)"

Expand Down
28 changes: 22 additions & 6 deletions diagnostic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ BEGIN
IF FOUND THEN
RAISE WARNING 'Found relations using the deprecated hypercore access method.';
END IF;

-- check for continuous aggregates using non-finalized form
PERFORM FROM _timescaledb_catalog.continuous_agg WHERE NOT finalized;
IF FOUND THEN
Expand All @@ -41,13 +42,28 @@ CREATE OR REPLACE FUNCTION pg_temp.check_catalog_corruption() RETURNS void LANGU
$$
DECLARE
v_count int8;
v_relnames text[];
v_rels regclass[];
BEGIN
-- corrupt _timescaledb_catalog.chunk_column_stats entries
SELECT count(*) INTO v_count FROM _timescaledb_catalog.chunk_column_stats WHERE range_start > range_end;
IF v_count >= 1 THEN
RAISE WARNING 'Found %s entries in _timescaledb_catalog.chunk_column_stats with range_start > range_end', v_count;
END IF;

-- chunks with missing relations
SELECT count(*), array_agg(format('%I.%I',ch.schema_name,ch.table_name)) INTO v_count, v_relnames
FROM _timescaledb_catalog.chunk ch WHERE
NOT dropped AND
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);
IF v_count > 0 THEN
IF v_count < 20 THEN
RAISE WARNING 'Found % chunk entries without relations: %', v_count, v_relnames;
ELSE
RAISE WARNING 'Found % chunk entries without relations', v_count;
END IF;
END IF;

-- orphaned chunks
SELECT count(*), array_agg(oid::regclass) INTO v_count, v_rels
FROM pg_class
Expand Down Expand Up @@ -189,7 +205,7 @@ DECLARE
v_batch_sub100 int8;
v_batch_sub100_pct float;
v_batch_sub100_avg float;
v_batch_total int8;
v_batch_total int8;
v_chunks_sub100 int8;
v_chunks_total int8;
v_returned_rows int;
Expand All @@ -213,11 +229,11 @@ BEGIN

-- check if batch has more than 20% of batches with less than 100 tuples
EXECUTE format('
SELECT
count(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100) batch_sub100,
avg(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100) batch_sub100_avg,
(count(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100)/count(_ts_meta_count)::float) * 100 batch_sub100_pct,
count(_ts_meta_count) batch_total
SELECT
count(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100) batch_sub100,
avg(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100) batch_sub100_avg,
(count(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100)/count(_ts_meta_count)::float) * 100 batch_sub100_pct,
count(_ts_meta_count) batch_total
FROM %s HAVING (count(_ts_meta_count) FILTER (WHERE _ts_meta_count < 100)/count(_ts_meta_count)::float) > 0.2;
', v_compressed_chunk) INTO v_batch_sub100, v_batch_sub100_avg, v_batch_sub100_pct, v_batch_total;

Expand Down