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

ALTER SERVER

Function

ALTER SERVER adds, modifies, or deletes the parameters of an existing server. You can query existing servers from the pg_foreign_server system catalog.

Precautions

Only the server owner or a user granted with the ALTER permission can run the ALTER SERVER command. The system administrator has this permission by default. To change the owner of a server, the current user must be the owner of the server or the system administrator, and the user must be a member of the new owner role.

When multi-layer quotation marks are used for sensitive columns (such as password and secret_access_key) 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

  • Change the parameters for a foreign server.
1
2
ALTER SERVER server_name [ VERSION 'new_version' ]
    [ OPTIONS ( {[ ADD | SET | DROP ] option ['value']} [, ... ] ) ];

In OPTIONS, ADD, SET, and DROP are operations to be performed. If these operations are not specified, ADD operations will be performed by default. option and value are the parameters of the corresponding operation.

  • Change the owner of a foreign server.
1
2
ALTER SERVER server_name 
    OWNER TO new_owner;
  • Change the name of a foreign server.
1
2
ALTER SERVER server_name 
    RENAME TO new_name;

Parameter Description

The parameters for modifying the server are as follows:

  • server_name

    Specifies the name of the server to be modified.

  • new_version

    Specifies the new version of the server.

  • The server parameters in OPTIONS are as follows:
    • encrypt

      Specifies whether to encrypt data. This parameter can be set only when type is set to OBS. The default value is off.

      Value range:

      • on indicates that data is encrypted.
      • off indicates that data is not encrypted.
    • access_key

      Specifies the access key (AK) (obtained by users from the OBS console) used for the OBS access protocol. When you create a foreign table. This parameter is available only when type is set to OBS.

    • secret_access_key

      Specifies the secret key (SK) value (obtained by users from the OBS console) used for the OBS access protocol. This parameter is available only when type is set to OBS.

  • new_owner

    Specifies the new owner of the server. To change the owner, you must be the owner of the foreign server and a direct or indirect member of the new owner role, and must have the USAGE permission on the encapsulator of the foreign server.

  • new_name

    Specifies the new name of the server.

Examples

1
2
3
4
5
6
7
8
9
-- Create my_server.
gaussdb=# CREATE SERVER my_server FOREIGN DATA WRAPPER log_fdw;
 
-- Change the name of an external service.
gaussdb=# ALTER SERVER my_server 
    RENAME TO my_server_1;
 
-- Delete my_server_1.
gaussdb=# DROP SERVER my_server_1;

Helpful Links

CREATE SERVER and DROP SERVER