Skip to content

Instantly share code, notes, and snippets.

@zeroDivisible
Created June 21, 2013 21:43
Show Gist options
  • Save zeroDivisible/5834551 to your computer and use it in GitHub Desktop.
Save zeroDivisible/5834551 to your computer and use it in GitHub Desktop.
Check database size of current database in PostgreSQL.
SELECT d.datname AS Name, pg_catalog.pg_get_userbyid(d.datdba) AS Owner,
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
ELSE 'No Access'
END AS Size
FROM pg_catalog.pg_database d
ORDER BY
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_database_size(d.datname)
ELSE NULL
END DESC -- nulls first
LIMIT 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment