Postgres DB Size Command

后端 未结 10 555
孤独总比滥情好
孤独总比滥情好 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条回答
  •  失恋的感觉
    2021-01-29 18:00

    SELECT pg_size_pretty(pg_database_size('name of database'));
    

    Will give you the total size of a particular database however I don't think you can do all databases within a server.

    However you could do this...

    DO
    $$
    DECLARE
    r   RECORD;
    db_size TEXT;
    BEGIN
    FOR r in
    SELECT datname FROM pg_database
    WHERE datistemplate = false
    LOOP
    db_size:= (SELECT pg_size_pretty(pg_database_size(r.datname)));
    
    RAISE NOTICE 'Database:% , Size:%', r.datname , db_size;
    
    END LOOP;
    END;
    $$
    

提交回复
热议问题