Extension FDW
suggest changepostgres_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.
- Create the extension:
CREATE EXTENSION postgres_fdw;
- Create the server:
CREATE SERVER name_srv FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'hostname',
dbname 'bd_name', port '5432');
- 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');
- Create a foreign table:
CREATE FOREIGN TABLE table_foreign (id INTEGER, code character varying)
SERVER name_srv OPTIONS(schema_name 'schema', table_name 'table');
- Use the foreign table like a local table:
SELECT * FROM table_foreign;
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents