I have a PostgreSQL DB in which I'm importing many data files into separate tables (one table per file).
I would like to get the size (on disk byte size, including indexes, etc.) of the corresponding table after each import is done.
I don't want to list all tables with their size, but rather get the size of a target table which I could easily consume as a query result.
I'm looking for something like: SELECT table_size(*) as "size" FROM my_table;
Answer: Thanks @a_horse_with_no_name for guiding me in the right direction. The command I was looking for is pg_total_relation_size()
. It also helps to use pg_size_pretty()
to get the data in a human-readable format. So the command I ended up using is:
SELECT pg_size_pretty(pg_total_relation_size('my_table')) AS size;
And it returns something like:
size
----------------
723 kB
(1 row)