Revision 79 (by dpavlin, 2008/05/14 16:28:17) added number of tuples to output of single database as last number
#!/bin/sh

if [ "$1" == "-u" ] ; then
	psql -A -l -t | grep -v template0 | awk -F'|' '{print $1}' | xargs -i psql -t -A -F" " -c "select sum(pg_relation_size(pg_class.oid)), '{}', pg_user.usename from pg_class inner join pg_user on pg_user.usesysid=pg_class.relowner group by pg_user.usename order by sum(pg_class.relpages) desc limit 1" {} | sort -k1,1 -n -r
elif [ ! -z "$1" ] ; then
	psql -t -A -F" " -c "select pg_relation_size(oid) as size,relname,reltuples from pg_class where relkind = 'r' and relname not like 'pg_%' order by size desc" $1
else
	psql -A -l -t -F: | grep -v template0 | cut -d: -f1 | xargs -i psql -t -A -F" " -c "select sum(pg_relation_size(oid)),'{}' from pg_class" {} | sort -r -n
fi