Database, table, index size.
--- 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;
+