All Products
Search
Document Center

PolarDB:CREATE SERVER

Last Updated:Mar 28, 2026

CREATE SERVER defines a new foreign server. The user who runs the statement becomes the owner of the server.

A foreign server stores the connection information that a foreign data wrapper (FDW) uses to access an external data source. To attach additional user-specific credentials to a server, use user mappings.

Syntax

CREATE SERVER server_name
    FOREIGN DATA WRAPPER fdw_name
    [ OPTIONS ( option 'value' [, ... ] ) ]

Parameters

ParameterDescription
server_nameThe name of the foreign server. Must be unique within the database.
fdw_nameThe name of the foreign data wrapper that manages this server.
OPTIONS ( option 'value' [, ... ] )Connection options for the server. The available option names and values depend on the foreign data wrapper.
channel_namePolarDB for PostgreSQL only. Use channel_name instead of host and port in OPTIONS. Each PolarDB for PostgreSQL cluster has a default channel named localhost that connects to the local server. To connect to a different cluster, create a channel first, then reference it here.
PolarDB for PostgreSQL does not support the host and port keywords in OPTIONS.

Usage notes

  • To create a server, you must have the USAGE privilege on the foreign data wrapper.

  • If you use the dblink module, pass the foreign server name to dblink_connect as the connection argument. USAGE privilege on the foreign server is required.

Example

The following example creates a foreign server named foreign_server using the postgres_fdw wrapper. It connects to the database foodb through the default localhost channel.

-- Create the postgres_fdw extension first
CREATE EXTENSION postgres_fdw;

-- Create the foreign server
CREATE SERVER foreign_server
    FOREIGN DATA WRAPPER postgres_fdw
    OPTIONS (channel_name 'localhost', dbname 'foodb');