Postgresql 中文操作指南

CREATE SERVER

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 定义新外部服务器。定义服务器的用户成为其所有者。

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 resource. Additional user-specific connection information may be specified by means of user mappings.

服务器名称在数据库中必须唯一。

The server name must be unique within the database.

创建服务器需要使用中的外部数据包装器上的 USAGE 权限。

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 is issued in this case. Note that there is no guarantee that the existing server is anything like the one that would have been created.

  • server_name

    • The name of the foreign server to be created.

  • server_type

    • Optional server type, potentially useful to foreign-data wrappers.

  • server_version

    • Optional server version, potentially useful to foreign-data wrappers.

  • fdw_name

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

  • OPTIONS ( _option 'value' [, …​ ] )_

    • This clause specifies the options for the server. The options typically define the connection details of the server, but the actual names and values are dependent on the server’s foreign-data wrapper.

Notes

使用 dblink 模块时,外部服务器的名称可以用作 dblink_connect 函数的参数,以指示连接参数。必须在外部服务器上具有 USAGE 权限,才能以这种方式使用它。

When using the dblink module, a foreign server’s name can be used as an argument of the dblink_connect function to indicate the connection parameters. It is necessary to have the USAGE privilege on the foreign server to be able to use it in this way.

如果外部服务器支持排序下推,则它必须与本地服务器具有相同的排序顺序。

If the foreign server supports sort pushdown, it is necessary for it to have the same sort ordering as the local server.

Examples

创建使用外部数据包装器 postgres_fdwmyserver 服务器:

Create a server myserver that uses the foreign-data wrapper postgres_fdw:

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

有关更多详细信息,请参见 postgres_fdw

See postgres_fdw for more details.

Compatibility

CREATE SERVER 符合 ISO/IEC 9075-9 (SQL/MED)。

CREATE SERVER conforms to ISO/IEC 9075-9 (SQL/MED).