Check the size of table in PostgreSQL

Check the size of table in PostgreSQL

pg_relation_size() function to get the table size. pg_size_pretty is used for human readable form.

SELECT pg_size_pretty(pg_relation_size('test'));

testdb=# SELECT pg_size_pretty(pg_relation_size('test'));
 pg_size_pretty
----------------
 8192 bytes


testdb=# SELECT pg_relation_size('test');
 pg_relation_size
------------------
             8192

Get the size of table and indexes for the table in PostgreSQL database:

pg_total_relation_size() function is used for get the table data size plus index size.

SELECT pg_size_pretty (pg_total_relation_size ('test'));

testdb=# SELECT pg_size_pretty (pg_total_relation_size ('test'));
 pg_size_pretty
----------------
 8192 bytes
(1 row)

Check the size of table with \d command:

testdb=# \d+
                                     List of relations
 Schema | Name | Type  |  Owner   | Persistence | Access method |    Size    | Description
--------+------+-------+----------+-------------+---------------+------------+-------------
 public | test | table | postgres | permanent   | heap          | 8192 bytes |
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.