Show the total disk size of a database
Read-only
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Reports the total on-disk size of a database so you can monitor storage growth and plan capacity.
postgresqlsizestoragemonitor
Parameters
Name of the database to measure.
Commands
Display the total size of the database on disk
psql -c "SELECT pg_size_pretty(pg_database_size('<database_name>')) AS size;"Verification
psql -c "SELECT pg_size_pretty(pg_database_size('<database_name>'));"A human-readable size string like "2.5 GB" is printed.
Undo
Not undoable
This recipe only reads storage metadata and changes nothing.
Pitfalls
- The database must exist and the user must have CONNECT privilege.
- This reports allocated disk space which may exceed the size of live data due to bloat and free space map.
- Template databases are typically small; measuring them is rarely useful.