查询 timescale table 行数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
SELECT h.schema_name,
h.table_name,
h.id AS table_id,
h.associated_table_prefix,
row_estimate.row_estimate
FROM _timescaledb_catalog.hypertable h
CROSS JOIN LATERAL (
SELECT SUM(cl.reltuples) AS row_estimate
FROM _timescaledb_catalog.chunk c
JOIN pg_class cl ON cl.relname = c.table_name
WHERE c.hypertable_id = h.id
GROUP BY h.schema_name, h.table_name
) row_estimate
ORDER BY schema_name, row_estimate DESC, table_name;