Created
July 23, 2025 11:16
-
-
Save NeuronButter/07642325a3137cfc1879c08ef735f88f to your computer and use it in GitHub Desktop.
PostgreSQL Physical Size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- Get total WAL sizes / file count | |
| SELECT | |
| pg_size_pretty(SUM(size)) AS total_wal_size, | |
| COUNT(*) AS wal_file_count | |
| FROM pg_ls_dir('pg_wal') f(name) | |
| JOIN LATERAL pg_stat_file('pg_wal/' || name) s ON true | |
| WHERE name ~ '^[0-9A-F]{24}$'; | |
| --- Get sizes per db | |
| SELECT | |
| d.datname AS database_name, | |
| pg_size_pretty(pg_database_size(d.datname)) AS size_pretty, | |
| pg_database_size(d.datname) AS size_bytes | |
| FROM | |
| pg_database d | |
| ORDER BY | |
| pg_database_size(d.datname) DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment