Skip to main content
Version: 1.0.16

CREATE SERVER

CREATE SERVER — Define a new foreign server

Synopsis

CREATE SERVER [ IF NOT EXISTS ] server_name [ TYPE 'server_type' ] [ VERSION 'server_version' ]

FOREIGN DATA WRAPPER fdw_name

[ OPTIONS ( option 'value' [, ... ] ) ]


Description

CREATE SERVER defines a new foreign server. The user who defines the server becomes its owner.

A foreign server typically encapsulates connection information that a foreign-data wrapper uses to access an external data source. Additional user-specific connection information can be specified via user mappings.

The server name must be unique within the database.

Creating a server requires USAGE privilege on the foreign-data wrapper being used.

Parameters

IF NOT EXISTS

Do not throw an error if a server with the same name already exists. A notice will be issued in this case. Note that there is no guarantee that the existing server is at all similar to the one to be created.

server_name

The name of the foreign server to be created.

server_type

An optional server type, potentially useful to the foreign-data wrapper.

server_version

An optional server version, potentially useful to the foreign-data wrapper.

fdw_name

The name of the foreign-data wrapper that manages the server.

OPTIONS ( option 'value' [, ... ] )

This clause specifies options for the server. These options typically define the connection details of the server, but the actual names and values depend on the server's foreign-data wrapper.

Notes

When using the dblink module, a foreign server name can be used as an argument to the dblink_connect function to indicate connection parameters. To use a foreign server in this way, you must have USAGE privilege on it.

Examples

Create a server named myserver using the foreign-data wrapper oracle_fdw:

CREATE SERVER myserver FOREIGN DATA WRAPPER oracle_fdw OPTIONS (host 'foo', dbname 'foodb', port '1521');

See Also

ALTER SERVER, DROP SERVER, CREATE FOREIGN DATA WRAPPER, CREATE FOREIGN TABLE, CREATE USER MAPPING