I'm trying to understand 1) what components make a postgres database, and 2) how to determine the total size of each type, i.e., 40 MB Tables, 30 MB Indices, etc..
I am running version 9.2.
Best I understand it, the following queries should give me the total sizes of the database, all tables, and all indices.
Database: select pg_size_pretty(pg_database_size('postgres'))
Output: 5272 kB
Tables: select pg_size_pretty(SUM(pg_table_size(relid))) FROM pg_stat_all_tables
Output: 3720 kB
Indices: select pg_size_pretty(SUM(pg_indexes_size(relid))) FROM pg_stat_all_tables
Output: 2712 kB
The obvious problem is that the Tables and Indices add up to more than the Database itself. So, either my queries are wrong, or I'm not understanding how sizes are represented.
Can someone please tell me what is wrong with my queries? Also, are there other major components that I am overlooking?