PostgreSQL tips
Get the size of a database⌗
SELECT pg_size_pretty(pg_database_size('somedatabase')) As fulldbsize;
Get the size of a table (excluding the indexes)⌗
SELECT pg_size_pretty( pg_relation_size('your_table') );
Get size of a table (including the indexes)⌗
SELECT pg_size_pretty( pg_total_relation_size('your_table') );
Get the list of all databases including their sizes⌗
SELECT tablename,pg_size_pretty(pg_total_relation_size(tablename)) AS total_usage
FROM pg_tables
WHERE schemaname != 'pg_catalog'
AND schemaname != 'information_schema'
Get list of tables in information schema ‘database’⌗
SELECT *
FROM information_schema.tables;
Get a list of all the db sizes for all the dbs on a server⌗
SELECT datname as "DB Name", pg_size_pretty(pg_database_size(datname)) AS "Full DB Size"
FROM pg_catalog.pg_database
WHERE datname NOT IN ('template0', 'template1', 'postgres')
ORDER BY pg_database_size(datname) DESC;
References⌗
http://www.postgresql.org/docs/8.1/static/functions-admin.html