How to get top 10 tables in PostgreSQL Server database

In this article, we are going to find out the top 10 tables in PostgreSQL Database by SQL query.

To get top 10 tables in PostgreSQL Server database:

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

Output:

table_name | size ------------+------ stock | 8192 orderline | 8192 barcode | 8192 customer | 8192 item | 8192 orderinfo | 0 (6 rows)

To get top 5 tables in PostgreSQL Server database:

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

Output:

table_name | size ------------+------ stock | 8192 orderline | 8192 barcode | 8192 customer | 8192 item | 8192 (5 rows)