Use pg_table_size for table stats query (#685)

This commit is contained in:
Dan Sosedoff 2023-07-18 20:15:09 -05:00 committed by GitHub
parent a4185415e2
commit e0c2099e91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@ SELECT
tables.schemaname AS schema_name,
tables.relname AS table_name,
pg_size_pretty(pg_total_relation_size(tables.relid)) AS total_size,
pg_size_pretty(pg_relation_size(tables.relid)) AS data_size,
pg_size_pretty(pg_table_size(tables.relid)) AS data_size,
pg_size_pretty(pg_indexes_size(tables.relid)) AS index_size,
pg_class.reltuples AS estimated_rows_count,
CASE
@ -25,7 +25,7 @@ SELECT
END AS estimated_rows,
CASE
WHEN pg_class.reltuples > 1000
THEN ROUND(pg_indexes_size(tables.relid)::numeric / pg_relation_size(tables.relid), 2)
THEN ROUND(pg_indexes_size(tables.relid)::numeric / pg_table_size(tables.relid), 2)
END AS index_to_data_ratio,
indexes_counts.num AS indexes_count,
columns_counts.num AS columns_count
@ -41,4 +41,4 @@ LEFT JOIN columns_counts
AND columns_counts.table_name = tables.relname
ORDER BY
pg_total_relation_size(tables.relid) DESC,
pg_relation_size(tables.relid) DESC
pg_table_size(tables.relid) DESC