May 2018
Intermediate to advanced
576 pages
30h 25m
English
We can do this in the following ways:
If you look at the size of the actual files, you'll need to make sure that you include the data directory and all subdirectories, as well as all other directories that contain tablespaces. This can be tricky, and it is also difficult to break out all the different pieces.
The easiest way is to ask the database a simple query, like this:
SELECT pg_database_size(current_database());
However, this is limited to only the current database. If you want to know the size of all the databases together, then you'll need a query such as the following:
SELECT sum(pg_database_size(datname)) ...