Questions And Answers

More Tutorials

postgreSQL Foreign Data Wrapper

To access complete schema of server db instead of single table. Follow below steps:

1. Create EXTENSION :

 CREATE EXTENSION postgres_fdw;

2. Create SERVER :

 CREATE SERVER server_name FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'host_ip',
 dbname 'db_name', port 'port_number');


 SERVER server_name
 OPTIONS (user 'user_name', password 'password');

4. Create new schema to access schema of server DB:

 CREATE SCHEMA schema_name;

5. Import server schema:

 IMPORT FOREIGN SCHEMA schema_name_to_import_from_remote_db
 FROM SERVER server_name
 INTO schema_name;

6. Access any table of server schema:

 SELECT * FROM schema_name.table_name;

This can be used to access multiple schema of remote DB.


In this page (written and validated by ) you learned about postgreSQL Foreign Data Wrapper . What's Next? If you are interested in completing postgreSQL tutorial, your next topic will be learning about: postgreSQL Find String Length Character Length.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.