Database Reference
In-Depth Information
Working with postgres_fdw
PostgreSQL provides a template to create your own foreign data wrapper, and
there are many foreign data wrappers available on the Internet. But there are only
two oficially supported foreign data wrappers:
postgres_fdw
and
file_fdw
. The
postgres_fdw
is a foreign data wrapper that is used to retrieve and manipulate
the remote PostgreSQL's server. The
postgres_fdw
data wrapper can be used by
performing the following steps:
1.
Load the extension using
CREATE EXTENSION
:
postgres=# CREATE EXTENSION postgres_fdw;
2.
Create the server using
CREATE SERVER
:
postgres=# CREATE SERVER postgres_server FOREIGN DATA
WRAPPER postgres_fdw OPTIONS (host, '127.0.0.1',
port '5432', dbname 'postgres');
3.
Create user mapping using
CREATE USER MAPPING
:
postgres=# CREATE USER MAPPING FOR PUBLIC SERVER
postgres_server;
4.
Create a foreign table using
CREATE FOREIGN TABLE
:
postgres=# CREATE FOREIGN TABLE dummy_table (foo INTEGER,
bar TEXT) SERVER postgres_server OPTIONS
(table_name 'remote_dummy_table');
5.
Insert data into the foreign table:
postgres=# INSERT INTO dummy_table VALUES (1, 'foo');
6.
Select data from the foreign data wrapper:
postgres=# SELECT * FROM dummy_table;
foo | bar
-----+-----
(0 rows)
Working with ile_fdw
The
file_fdw
data wrapper is another oficially supported foreign data wrapper.
This is used to access the iles in the server ile system. The
file_fdw
data wrapper
can be used by performing the following steps:
1.
Load extension using
CREATE EXTENSION
:
postgres=# CREATE EXTENSION file_fdw;