This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH stats_reset AS ( | |
SELECT EXTRACT( | |
EPOCH FROM ( | |
CURRENT_TIMESTAMP - | |
( | |
SELECT stats_reset FROM pg_stat_statements_info | |
) | |
) | |
) / 3600 AS hours_since_stats_reset | |
), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH t AS ( | |
SELECT | |
s.relid, | |
s.relname, | |
last_autovacuum, | |
last_vacuum | |
FROM pg_stat_user_tables s | |
WHERE s.schemaname = 'public' | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH stats_reset AS ( | |
SELECT EXTRACT( | |
EPOCH FROM ( | |
CURRENT_TIMESTAMP - | |
( | |
SELECT stats_reset FROM pg_stat_statements_info | |
) | |
) | |
) / 3600 AS hours_since_stats_reset | |
), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
ht.schema_name, | |
ht.table_name, | |
COUNT(DISTINCT ck.table_name) AS nb_of_chunks, | |
SUM(stat.seq_scan) AS seq_scan, | |
SUM(stat.idx_scan) AS idx_scan, | |
SUM(stat.idx_scan) - SUM(stat.seq_scan) AS difference, | |
CASE WHEN SUM(stat.idx_scan) < SUM(stat.seq_scan) THEN 'Missing index ?' ELSE 'OK' END AS missing_index | |
FROM _timescaledb_catalog.hypertable ht | |
JOIN _timescaledb_catalog.chunk ck ON ht.id = ck.hypertable_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH chunks AS ( | |
SELECT | |
ht.schema_name AS hypertable_schema, | |
ht.table_name AS hypertable_name, | |
ck.table_name AS chunk_name | |
FROM _timescaledb_catalog.hypertable ht | |
JOIN _timescaledb_catalog.chunk ck | |
ON ht.id = ck.hypertable_id | |
), |