Foreign Data Wrapper

suggest change

To access a whole schema on another PostgreSQL server, instead of a single table, follow the steps below. postgres_fdw must be available on the local server.

  1. Create the extension:
CREATE EXTENSION postgres_fdw;
  1. Create the server:
CREATE SERVER server_name FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'host_ip',
dbname 'db_name', port 'port_number');
  1. Create a user mapping:
CREATE USER MAPPING FOR CURRENT_USER
SERVER server_name
OPTIONS (user 'user_name', password 'password');
  1. Create a local schema to hold the foreign tables:
CREATE SCHEMA schema_name;
  1. Import the remote schema:
IMPORT FOREIGN SCHEMA schema_name_to_import_from_remote_db
FROM SERVER server_name
INTO schema_name;
  1. Read a remote table through the local schema:
SELECT * FROM schema_name.table_name;

Repeat the import for each remote schema you need. The remote user in the user mapping needs privileges on those tables.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents