Note
Other useful size queries include pg_column_size()
and pg_database_size()
.
A quick example of how to query this information across all the tables in the current database is as follows:
SELECT nspname, relname, pg_size_pretty(pg_relation_size(C.oid)) AS "size" FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) WHERE nspname NOT IN ('pg_catalog', 'information_schema') ORDER BY pg_relation_size(C.oid) DESC LIMIT 20;
On a pgbench
database with a lot of work done on it, and thus a large history table, output from this might look like the following:
nspname | relname | size ----------+-----------------------+-------- public | pgbench_accounts | 13 MB public | pgbench_history | 12 MB public | pgbench_accounts_pkey | 1768 kB public | pgbench_branches | 224 kB pg_toast | pg_toast_2618 | 208 kB public | pgbench_tellers | 32 kB
This shows the main issue with this simple...