My postgres database (version 8.2.3) is showing a size of 24 GB.
To get this figure I execute this query:
SELECT
oid, datname, pg_database_size(datname) as actualsize,
pg_size_pretty(pg_database_size(datname)) as size
FROM pg_database
ORDER BY datname
However, the sizes of the individual tables in the same database are not adding 24 GB when I execute this query:
SELECT
schemaname, tablename, pg_size_pretty(size) AS size_pretty,
pg_size_pretty(total_size) AS total_size_pretty
FROM
(SELECT *, pg_relation_size(schemaname||'.'||tablename) AS size,
pg_total_relation_size(schemaname||'.'||tablename) AS total_size
FROM pg_tables where schemaname = 'public') AS TABLES
ORDER BY total_size DESC;
I've done sum up the individual tables size with pretty size and total_size, but the value does not match:
I am getting a pretty size of 3.5 GB
I am getting a total_size_pretty of 5.2 GB.
Where do I find out what the rest of the total space is being used for?