This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing one SQL Script to find the size of all your PostgreSQL Databases.
I am sharing this kind of script because It helps a lot for reporting and monitoring Database Server.
Recently, I have used this script to generate all database size reports because suddenly one of our PostgreSQL Server increased utilization of the Disk.
Using pg_catalog.pg_database, I am finding the size of Databases.
Below is a script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
SELECT datname AS DatabaseName ,pg_catalog.pg_get_userbyid(datdba) AS OwnerName ,CASE WHEN pg_catalog.has_database_privilege(datname, 'CONNECT') THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(datname)) ELSE 'No Access For You' END AS DatabaseSize FROM pg_catalog.pg_database ORDER BY CASE WHEN pg_catalog.has_database_privilege(datname, 'CONNECT') THEN pg_catalog.pg_database_size(datname) ELSE NULL END DESC; |