是否可以获取我的 PostgreSQL 数据库服务器中所有数据库的数据库名称和大小?
Is it possible to get database name and size for all databases in my PostgreSQL database server?
我有一个带有多个数据库的 PostgreSQL 数据库服务器。我想 select 每个数据库的名称、大小,如下所示:
| name | size |
-------------------
| db_1 | 21115439 |
| db_2 | 34238574 |
| db_3 | 83859902 |
| db_4 | 18447618 |
我知道如何获取一个特定的数据库大小SELECT pg_database_size('db_1')
,但是有什么方法可以获取多个数据库吗?
根据本网站
https://wiki.postgresql.org/wiki/Disk_Usage;
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
我有一个带有多个数据库的 PostgreSQL 数据库服务器。我想 select 每个数据库的名称、大小,如下所示:
| name | size |
-------------------
| db_1 | 21115439 |
| db_2 | 34238574 |
| db_3 | 83859902 |
| db_4 | 18447618 |
我知道如何获取一个特定的数据库大小SELECT pg_database_size('db_1')
,但是有什么方法可以获取多个数据库吗?
根据本网站 https://wiki.postgresql.org/wiki/Disk_Usage;
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