1

我想列出 Postgres 集群中的所有数据库和模式,如何获得该列表?

我已经运行了以下查询(我正在使用 pgAdmin)

SELECT * FROM pg_database; --This lists all the databases in the cluster

SELECT distinct table_catalog, table_schema
FROM information_schema.tables
ORDER BY table_schema; --This lists all the schemas in the current database I am in.

我尝试将它们组合起来(在查询下方),但它只给出来自 information_schema 的结果,并且仅限于一个数据库。

select distinct db.datname, t.table_schema from pg_database db
inner join information_schema.tables t on db.datname = t.table_catalog
order by db.datname, t.table_schema
4

1 回答 1

1

数据库在 PostgreSQL 中(逻辑上)严格分离;您无法通过另一个数据库中的查询获取有关一个数据库中对象的信息(例如模式)。

您必须依次连接到所有数据库并查询每个数据库的模式。

于 2019-03-20T20:17:01.443 回答