CREATE SERVER
An SQL 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 (FDW).
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 commands
\des
lists available foreign servers\des+
displays additional details such as access privileges and values provided with theOPTIONS
clause.
Change history
- PostgreSQL 10
IF NOT EXISTS
clause added (commit b6fb534f)
- PostgreSQL 8.4
- added (commit cae565e5)
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 |
References
- PostgreSQL server: CREATE SERVER