Skip to content

Instantly share code, notes, and snippets.

@NeuronButter
Created July 23, 2025 11:16
Show Gist options
  • Save NeuronButter/07642325a3137cfc1879c08ef735f88f to your computer and use it in GitHub Desktop.
Save NeuronButter/07642325a3137cfc1879c08ef735f88f to your computer and use it in GitHub Desktop.
PostgreSQL Physical Size
--- 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