Updated on 2024-05-07 GMT+08:00

CREATE SERVER

Function

Creates a foreign server.

A foreign server stores other homogeneous cluster information.

Precautions

Only a system administrator and users with permission to use a specified FOREIGN DATA WRAPPER can create a foreign server. The authorization syntax is as follows:

GRANT USAGE ON FOREIGN DATA WRAPPER fdw_name TO username

fdw_name is the name of the FOREIGN DATA WRAPPER, and username is the name of the user creating a foreign server.

When multi-layer quotation marks are used for sensitive columns (such as password) in OPTIONS, the semantics is different from that in the scenario where quotation marks are not used. Therefore, sensitive columns are not identified for anonymization.

Syntax

1
2
3
CREATE SERVER server_name 
    FOREIGN DATA WRAPPER fdw_name
    [ OPTIONS ( { option_name ' value ' } [, ...] ) ];

Parameters

  • server_name

    Specifies the server name.

    Value range: a string containing no more than 63 characters

  • FOREIGN DATA WRAPPER fdw_name

    Specifies the name of the foreign data wrapper.

    Value range: fdw_name is the data wrapper created by the system during database initialization. Currently, fdw_name can only be gc_fdw for other homogeneous clusters. You can also create dist_fdw, file_fdw, and log_fdw. log_fdw is used only for syntax compatibility and can be used to create foreign tables, but it is meaningless. dist_fdw is used to import GDS data. You do not need to manually create a server using dist_fdw because gsmpp_server is already built in.

  • OPTIONS ( { option_name ' value ' } [, ...] )

    Specifies the parameters for the foreign server. The detailed parameter description is as follows:

    • address

      Address of the foreign server.

    • dbname

      Database name of the foreign server.

    • username

      Username of a foreign server.

    • password

      Password of the foreign server.

Examples

Create my_server, in which dfs_fdw is the built-in foreign data wrapper.

1
2
3
4
5
-- Create my_server.
gaussdb=# CREATE SERVER my_server FOREIGN DATA WRAPPER file_fdw;

-- Delete my_server.
gaussdb=# DROP SERVER my_server;

You are advised to create another server in the homogeneous cluster, where gc_fdw is the foreign data wrapper in the database.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
-- Create a server.
gaussdb=# CREATE SERVER server_remote FOREIGN DATA WRAPPER GC_FDW OPTIONS 
   (address '10.146.187.231:8000,10.180.157.130:8000' ,
  dbname 'test', 
  username 'test', 
  password '********'
);

-- Delete the server.
gaussdb=# DROP SERVER server_remote;

Helpful Links

ALTER SERVER and DROP SERVER