CREATE SERVER
CREATE SERVER defines a new foreign server in the database. Foreign servers store the connection information that a foreign data wrapper (FDW) uses to access an external data source.
Syntax
CREATE SERVER server_name FOREIGN DATA WRAPPER fdw_name
[ OPTIONS ( option 'value' [, ... ] ) ]Usage notes
The user who runs
CREATE SERVERbecomes the owner of the server.The server name must be unique within the database.
You must have the
USAGEprivilege on the foreign data wrapper before creating a server. Without this privilege, the statement fails.A foreign server stores connection details for the external data source. To specify user credentials separately, create user mappings after the server is defined.
To use a foreign server name as a connection argument to
dblink_connect, you must have theUSAGEprivilege on that foreign server.
Parameters
| Parameter | Description |
|---|---|
server_name | The name of the foreign server to create. Must be unique in the database. |
fdw_name | The name of the foreign data wrapper that manages the foreign server. |
OPTIONS ( option 'value' [, ... ] ) | Options for the server, typically defining connection details. The available option names and values depend on the foreign data wrapper. |
Example
The following example creates a foreign server named foreign_server using the postgres_fdw foreign data wrapper.
Note: Create the postgres_fdw extension before defining a server that uses it.CREATE EXTENSION postgres_fdw;
CREATE SERVER foreign_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (channel_name 'localhost', dbname 'foodb');