Postgres DB Size Command

后端 未结 10 559
孤独总比滥情好
孤独总比滥情好 2021-01-29 17:09

What is the command to find the size of all the databases?

I am able to find the size of a specific database by using following command:

         


        
10条回答
  •  -上瘾入骨i
    2021-01-29 17:49

    You can use below query to find the size of all databases of PostgreSQL.

    Reference is taken from this blog.

    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;
    

提交回复
热议问题