@@ -13,6 +13,21 @@ with data as (
1313 from pg_class c
1414 left join pg_namespace n on n .oid = c .relnamespace
1515 where relkind = ' r'
16+ ), data2 as (
17+ select
18+ null ::oid as oid ,
19+ null as schema_name,
20+ ' *** TOTAL ***' as table_name,
21+ sum (row_estimate) as row_estimate,
22+ sum (total_bytes) as total_bytes,
23+ sum (index_bytes) as index_bytes,
24+ sum (toast_bytes) as toast_bytes,
25+ sum (table_bytes) as table_bytes
26+ from data
27+ union all
28+ select null ::oid , null , null , null , null , null , null , null
29+ union all
30+ select * from data
1631)
1732select
1833 coalesce(nullif(schema_name, ' public' ) || ' .' , ' ' ) || table_name as table,
@@ -26,15 +41,16 @@ select
2641 pg_size_pretty(total_bytes) || ' (' || round(100 * total_bytes::numeric / sum (total_bytes) over (), 2 )::text || ' %)' as " total (% of all)" ,
2742 pg_size_pretty(table_bytes) || ' (' || round(100 * table_bytes::numeric / sum (table_bytes) over (), 2 )::text || ' %)' as " table (% of all tables)" ,
2843 pg_size_pretty(index_bytes) || ' (' || round(100 * index_bytes::numeric / sum (index_bytes) over (), 2 )::text || ' %)' as " index (% of all indexes)" ,
29- pg_size_pretty(toast_bytes) || ' (' || round(100 * toast_bytes::numeric / sum (toast_bytes) over (), 2 )::text || ' %)' as " toast (% of all toast data)" ,
44+ pg_size_pretty(toast_bytes) || ' (' || round(100 * toast_bytes::numeric / sum (toast_bytes) over (), 2 )::text || ' %)' as " toast (% of all toast data)"
45+ /* ,
3046 row_estimate,
3147 total_bytes,
3248 table_bytes,
3349 index_bytes,
3450 toast_bytes,
3551 schema_name,
3652 table_name,
37- oid
38- from data
39- where schema_name <> ' information_schema'
40- order by total_bytes desc nulls last;
53+ oid*/
54+ from data2
55+ where schema_name is distinct from ' information_schema'
56+ order by oid is null desc , total_bytes desc nulls last;
0 commit comments