forked from RedHatSatellite/satellite-support
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgres-size-report
executable file
·47 lines (38 loc) · 1.26 KB
/
postgres-size-report
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
TABLEQUERY=$(cat <<-END
SELECT table_name, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
FROM (
SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
, pg_indexes_size(c.oid) AS index_bytes
, pg_total_relation_size(reltoastrelid) AS toast_bytes
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE relkind = 'r'
) a
) a order by total_bytes DESC LIMIT 30;
END
)
# echo $TABLEQUERY
cd ~postgres
echo ""
echo "************* Candlepin Tablesizes *************"
echo ""
echo $TABLEQUERY | sudo -u postgres psql -d candlepin
echo ""
echo "************** Foreman Tablesizes **************"
echo ""
echo $TABLEQUERY | sudo -u postgres psql -d foreman
echo ""
echo "*************** FileSystem Usage ***************"
echo ""
echo "du -hs /var/lib/pgsql/*"
du -hs /var/lib/pgsql/*
echo
echo "du -hs /var/lib/pgsql/data/*"
du -hs /var/lib/pgsql/data/*