pg_database_size() essentially queries the filesystem for the size of $PGDATA/base/oid-of-database (the per-database data directory), plus the size of every such directory in non-default tablespaces added with CREATE TABLESPACE. If there are files in these directories that don't pertain to any relation , they will be counted too. https://dba.stackexchange.com/questions/121804/what-parts-make-up-pg-database-sizeSELECT current_database() as db;SELECT pg_database_size(current_database()) as size;SELECT pg_size_pretty(pg_database_size(current_database())) as size;SELECT SUM(pg_total_relation_size(oid)) AS dbsize,           pg_database_size(current_database()) AS dbsizeondiskFROM   pg_classWHERE  relkind IN ('r','m','S')  AND NOT relisshared;jira17147806961635 MB17319854081732098584