How to get the table size in PostgreSQL

We can determine table size by running following query will give the size of table accounts of the datbase ‘bank’

bank=# select pg_relation_size('accounts'); pg_relation_size ------------------ 8192

Or run the command \dt+ accounts

To get table sizes by order use following query

select table_name, pg_relation_size(quote_ident(table_name)) from information_schema.tables where table_schema = 'public' order by 2

To get top 10 biggest tables of database:(Only user tables. excluded the tables from information schema and pg_catalog)

SELECT table_name ,pg_relation_size(table_name) as size FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'pg_catalog') ORDER BY size DESC LIMIT 10;

Related Posts

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: