Skip to content

Commit 5e89a8c

Browse files
committed
2: do not show boring details; add TOTAL
1 parent d9671a6 commit 5e89a8c

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

init/generate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ do
3939
done
4040
echo "\\else" >> "$OUT"
4141
echo " \\echo" >> "$OUT"
42-
echo " \\echo '\\033[1;31mError:\\033[0m Unknown option!'" >> "$OUT"
42+
echo " \\echo '\\033[1;31mError:\\033[0m Unknown option! Try again.'" >> "$OUT"
4343
echo " \\echo" >> "$OUT"
4444
echo " \\i ./$OUT" >> "$OUT"
4545
echo "\\endif" >> "$OUT"

sql/2_table_sizes.sql

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
)
1732
select
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;

start.psql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ select
8383
\i ./start.psql
8484
\else
8585
\echo
86-
\echo '\033[1;31mError:\033[0m Unknown option!'
86+
\echo '\033[1;31mError:\033[0m Unknown option! Try again.'
8787
\echo
8888
\i ./start.psql
8989
\endif

0 commit comments

Comments
 (0)