All Products
Search
Document Center

PolarDB:CREATE SERVER

Last Updated:Dec 07, 2023

This topic describes how to define a new foreign server by using CREATE SERVER.

Syntax

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

Usage notes

  • CREATE SERVER is used to define a new foreign server. The user who defines a server becomes the owner of the server.

  • In most cases, a foreign server contains the connection information that a foreign data wrapper uses to access an external data source. Additional user-related connection information may be specified by using user mappings.

  • The server name must be unique in the database.

  • You must have the USAGE privilege on the foreign data wrapper to create a new server.

  • If you use the dblink module, you can use the name of a foreign server as an argument of the dblink_connect function to indicate the connection parameters, provided that you have the USAGE privilege on that foreign server.

  • PolarDB for PostgreSQL does not allow you to specify the host and port keywords in OPTIONS. Use channel_name instead. By default, each PolarDB for PostgreSQL cluster is configured with a channel named localhost, which is the channel to connect to the local server. If you want to connect to other clusters, create a channel first.

Components

Component

Description

server_name

The name of the foreign server to be created.

fdw_name

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

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

This clause specifies options for the server. These options usually define the connection details for the server, but the actual names and values depend on the foreign data wrapper for that server.

Example

The following sample code shows how to create a server named myserver that uses the postgres_fdw foreign data wrapper.

Note

You must first create the postgres_fdw extension.

CREATE EXTENSION  postgres_fdw;
CREATE SERVER foreign_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (channel_name 'localhost', dbname 'foodb');