CREATE SERVER

A DDL command for creating a foreign server

CREATE SERVER is a DDL command for creating a foreign server, which defines an external data source accesse via a foreign data wrapper.

CREATE SERVER was added in PostgreSQL 8.4.

Usage

CREATE SERVER is usually used in conjunction with CREATE EXTENSION and CREATE USER MAPPING to set up a foreign server.

The OPTIONS clause is for providing parameters defined by the respective foreign data wrapper. These typically include connection parameters and configuration settings.

psql

\des lists available foreign servers.

\des+  displays additional details such as access privileges and values provided with the OPTIONS clause.

Change history

Examples

Create a foreign server as a loopback to the local node:

postgres=# CREATE EXTENSION postgres_fdw;
CREATE EXTENSION

postgres=# CREATE SERVER pg_fdw_test
             FOREIGN DATA WRAPPER postgres_fdw
             OPTIONS (
               host 'localhost',
               dbname 'postgres'
            );
CREATE SERVER

postgres=# \des
            List of foreign servers
    Name     |  Owner   | Foreign-data wrapper 
-------------+----------+----------------------
 pg_fdw_test | postgres | postgres_fdw
(1 row)

postgres=# \des+
List of foreign servers
-[ RECORD 1 ]--------+--------------------------------------
Name                 | pg_fdw_test
Owner                | postgres
Foreign-data wrapper | postgres_fdw
Access privileges    | 
Type                 | 
Version              | 
FDW options          | (host 'localhost', dbname 'postgres')
Description          | 


Categories

DDL, Foreign Data Wrapper (FDW)

See also

ALTER SERVER, DROP SERVER, foreign server, pg_foreign_server