How much disk space does a database use?
It is very important to allocate sufficient disk space for your database. If the disk gets full, it will not corrupt the data, but it might lead to database server panic and then consequent shutdown.
For planning or space monitoring, we often need to know how big a database currently is, so that we get a hint of how fast it grows and are not caught by surprise later on.
How to do it...
We can do this in the following ways:
- Look at the size of the files that make up the database server.
- Run a SQL request to confirm the database size. 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 down all the different pieces.
The easiest way is to ask the database a simple query, like this:
SELECT pg_database_size(current_database...