# HG changeset patch # User Oleksandr Gavenko # Date 1428591223 -10800 # Node ID 601c3175368691423be7e6f6378e9eb76ef58b23 # Parent f34c6bc973cb45aa79beeffb7b4de1a966d1425c Database, table, index size. diff -r f34c6bc973cb -r 601c31753686 postgre.rst --- a/postgre.rst Fri Apr 03 10:57:19 2015 +0300 +++ b/postgre.rst Thu Apr 09 17:53:43 2015 +0300 @@ -70,6 +70,30 @@ set search_path to NAME; +Database, table, index size. +============================ + +Database size:: + + SELECT pg_database_size('geekdb'); -- in bytes + SELECT pg_size_pretty(pg_database_size('dbname')); + +List of databases sizes:: + + \l+ + +Table total size (with indexes):: + + SELECT pg_size_pretty(pg_total_relation_size('schemaname.tablename')); + +Sole table size (without indexes and other):: + + SELECT pg_size_pretty(pg_relation_size('schemaname.tablename')); + +Largest table in the PostgreSQL database:: + + SELECT relname, relpages FROM pg_class ORDER BY relpages DESC; + Using psql client. ================== @@ -84,3 +108,13 @@ $ psql -U $USER -h $HOST $SCHEMA +How to view execution plan:: + + EXPLAIN query; + EXPLAIN ANALYZE query; + +How to redirect the output of query to a file:: + + \o output_file + SELECT * FROM pg_class; +