0

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.

2
  • 1
    There is no such thing as a foreign schema. Only schemas which contain (at least one? Exclusively?) foreign tables. And how would you turn a "foreign" schema into an "active" fdw? Commented Jul 28, 2020 at 18:53
  • @jjanes "IMPORT FOREIGN SCHEMA my_schema FROM SERVER my_server INTO my_server_my_schema;" I assumed that postgres was representing the entire schema as foreign somehow, but it seems like the "IMPORT FOREIGN SCHEMA" is just a shortcut to make multiple pg_foreign_table entries. Commented Jul 28, 2020 at 21:33

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.