CREATE SERVER

Function

Creates an external server.

An external server stores information of HDFS clusters, OBS servers, DLI connections, or other homogeneous clusters.

Precautions

By default, only the system administrator can create a foreign server. Otherwise, creating a server requires the USAGE permission on the foreign-data wrapper being used. The syntax is as follows:

1
GRANT USAGE ON FOREIGN DATA WRAPPER fdw_name TO username;

fdw_name is the name of FOREIGN DATA WRAPPER, and username is the user name of creating SERVER.

Syntax

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

Parameter Description

Examples

Create the hdfs_server server, in which hdfs_fdw is the foreign-data wrapper:

1
2
3
4
5
CREATE SERVER hdfs_server FOREIGN DATA WRAPPER HDFS_FDW OPTIONS 
   (address '10.10.0.100:25000,10.10.0.101:25000',
    hdfscfgpath '/opt/hadoop_client/HDFS/hadoop/etc/hadoop', 
    type 'HDFS'
) ;

Create the obs_server server, in which dfs_fdw is the foreign-data wrapper:

1
2
3
4
5
6
CREATE SERVER obs_server FOREIGN DATA WRAPPER DFS_FDW OPTIONS ( 
  address 'obs.example.com', 
   access_key 'xxxxxxxxx', 
  secret_access_key 'yyyyyyyyyyyyy', 
  type 'obs'
);

Create the dli_server server, in which dfs_fdw is the foreign-data wrapper:

1
2
3
4
5
6
7
8
9
CREATE SERVER dli_server FOREIGN DATA WRAPPER DFS_FDW OPTIONS ( 
  address 'obs.example.com', 
  access_key 'xxxxxxxxx', 
  secret_access_key 'yyyyyyyyyyyyy', 
  type 'dli',
  dli_address 'dli.example.com',
  dli_access_key 'xxxxxxxxx',
  dli_secret_access_key 'yyyyyyyyyyyyy'
);

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
CREATE SERVER server_remote FOREIGN DATA WRAPPER GC_FDW OPTIONS 
   (address '10.10.0.100:25000,10.10.0.101:25000',
  dbname 'test', 
  username 'test', 
  password 'xxxxxxxx'
);

Create a server whose FOREIGN DATA WRAPPER is dist_fdw for importing and exporting text data on OBS.

1
2
3
4
5
CREATE SERVER import_server FOREIGN DATA WRAPPER DIST_FDW OPTIONS 
(
  access_key 'ak_string',
  secret_access_key 'sk_string'
);

Helpful Links

ALTER SERVER DROP SERVER