原 PG查询数据库大小
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | SELECT d.datname as "Name", pg_catalog.pg_get_userbyid(d.datdba) as "Owner", pg_catalog.pg_encoding_to_char(d.encoding) as "Encoding", d.datcollate as "Collate", d.datctype as "Ctype", pg_catalog.array_to_string(d.datacl, E'\n') AS "Access privileges", 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", t.spcname as "Tablespace", pg_catalog.shobj_description(d.oid, 'pg_database') as "Description" FROM pg_catalog.pg_database d JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid UNION ALL SELECT '总计' as "Name", '' as "Owner", '' as "Encoding", '' as "Collate", '' as "Ctype", '' AS "Access privileges", pg_catalog.pg_size_pretty(SUM((pg_catalog.pg_database_size(d.datname)))) as "Size", '' as "Tablespace", '' as "Description" FROM pg_catalog.pg_database d JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid ORDER BY 1; Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description -----------+----------+-----------+------------+------------+-----------------------+---------+------------+-------------------------------------------- bench | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | 23 MB | pg_default | db1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | 7433 kB | pg_default | db10 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | 7433 kB | pg_default | db2 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | 7433 kB | pg_default | db3 | postgres | SQL_ASCII | C | C | | 7433 kB | pg_default | db4 | postgres | SQL_ASCII | en_US.utf8 | en_US.utf8 | | 7433 kB | pg_default | db5 | postgres | SQL_ASCII | C | C | | 7433 kB | pg_default | db6 | postgres | SQL_ASCII | C | C | | 7433 kB | pg_default | db7 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | 7433 kB | pg_default | korean | postgres | SQL_ASCII | C | C | | 7433 kB | pg_default | lhrdb | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | 263 MB | pg_default | postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | 697 MB | pg_default | default administrative connection database template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +| 7433 kB | pg_default | unmodifiable empty database | | | | | postgres=CTc/postgres | | | template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +| 7433 kB | pg_default | default template for new databases | | | | | postgres=CTc/postgres | | | 总计 | | | | | | 1062 MB | | (15 rows) |