Extension FDW

suggest change

postgres_fdw is a foreign-data wrapper for other PostgreSQL servers. It is usually a better fit than dblink when you want to query remote tables as if they were local.

  1. Create the extension:
CREATE EXTENSION postgres_fdw;
  1. Create the server:
CREATE SERVER name_srv FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'hostname', 
dbname 'bd_name', port '5432');
  1. Create a user mapping for the local role that will use the server:
CREATE USER MAPPING FOR postgres SERVER name_srv OPTIONS(user 'postgres', password 'password');
  1. Create a foreign table:
CREATE FOREIGN TABLE table_foreign (id INTEGER, code character varying) 
SERVER name_srv OPTIONS(schema_name 'schema', table_name 'table');
  1. Use the foreign table like a local table:
SELECT * FROM table_foreign;

Feedback about page:

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



Table Of Contents