Created
August 6, 2022 12:23
-
-
Save vip3r011/bfcd555f36d571e5e88f414850d8b81f to your computer and use it in GitHub Desktop.
POSTGRES page size
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 l.metric, l.nr AS bytes | |
, CASE WHEN is_size THEN pg_size_pretty(nr) END AS bytes_pretty | |
, CASE WHEN is_size THEN nr / NULLIF(x.ct, 0) END AS bytes_per_row | |
FROM ( | |
SELECT min(tableoid) AS tbl -- = 'public.tbl'::regclass::oid | |
, count(*) AS ct | |
, sum(length(t::text)) AS txt_len -- length in characters | |
FROM public.TABLE-NAME-HERE t -- provide table name *once* | |
) x | |
CROSS JOIN LATERAL ( | |
VALUES | |
(true , 'core_relation_size' , pg_relation_size(tbl)) | |
, (true , 'visibility_map' , pg_relation_size(tbl, 'vm')) | |
, (true , 'free_space_map' , pg_relation_size(tbl, 'fsm')) | |
, (true , 'table_size_incl_toast' , pg_table_size(tbl)) | |
, (true , 'indexes_size' , pg_indexes_size(tbl)) | |
, (true , 'total_size_incl_toast_and_indexes', pg_total_relation_size(tbl)) | |
, (true , 'live_rows_in_text_representation' , txt_len) | |
, (false, '------------------------------' , NULL) | |
, (false, 'row_count' , ct) | |
, (false, 'live_tuples' , pg_stat_get_live_tuples(tbl)) | |
, (false, 'dead_tuples' , pg_stat_get_dead_tuples(tbl)) | |
) l(is_size, metric, nr); | |
SOURCE: https://dba.stackexchange.com/questions/23879/measure-the-size-of-a-postgresql-table-row/23933 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment