Get sizes of objects using built-in functions
Get the size of a database:
select pg_size_pretty(pg_database_size('my_db'));
Get the size of a table (but not its toast tables or indices):
select pg_size_pretty(pg_relation_size('my_table'));
Get the size of a table and its toast tables (but not its indices):
select pg_size_pretty(pg_table_size('my_table'));
Get the size of a table and its toast tables and its indices:
select pg_size_pretty(pg_total_relation_size('my_table'));