Skip to content

Instantly share code, notes, and snippets.

@edvardm
Last active October 27, 2020 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edvardm/75a4d05988d5f431cf0bb17f4bf035fc to your computer and use it in GitHub Desktop.
Save edvardm/75a4d05988d5f431cf0bb17f4bf035fc to your computer and use it in GitHub Desktop.
timescaledb, estimated row count
SELECT h.schema_name,
h.table_name,
h.id AS table_id,
h.associated_table_prefix,
((round(row_estimate.row_estimate::numeric / 1000000, 3))::text || 'M') as estimated_rows
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, table_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment