Listing active PostgreSQL foreign data wrappers
-
05-03-2021 - |
题
I have a few foreign data wrappers set up from my main PostgreSQL database to other databases. Is there a table I can query to list all of the FDWs? Unfortunately select * from information_schema.schemata
doesn't give any hints about which schemas are foreign and which are local.
解决方案
The information you're looking for is in various pg_catalog tables. pg_class
is the main table that represents all relations, normal or foreign; you can limit it to foreign tables by including WHERE relkind='f'
. Information on the foreign data wrappers themselves is in pg_foreign_data_wrappers
, on servers in pg_foreign_servers
, and on foreign tables in pg_foreign_tables
.
Start with select relname from pg_class where relkind='f'
to just get a list of table names, and from there you can use the pg_catalog docs to find whatever other pieces of information you need for what you're trying to do.