Updated on 2025-02-27 GMT+08:00

ALTER SERVER

Description

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. System administrators have this permission by default. To change the owner of a server, the current user must be the owner of the server or a 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;

Parameters

The parameters for modifying the server are as follows:

  • server_name

    Specifies the name of the server to be modified.

  • new_version

    Specifies the latest version of the server.

  • OPTIONS

    Changes options of the server. ADD, SET, and DROP are operations to be performed. If the operation is not specified explicitly, ADD operations will be performed. The option name must be unique, and the name and value are also validated with the foreign data wrapper library of the server.

    • 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: Data is encrypted.
      • off: 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, the AK value is encrypted and saved to the metadata table of the database. This parameter is available only when type is set to OBS.

    • secret_access_key

      Specifies the SK value (obtained by users from the OBS console) used for the OBS access protocol. When you create a foreign table, the SK value is encrypted and saved to the metadata table of the database. 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 foreign data wrapper of the foreign server.

  • new_name

    Specifies the new name of the server.

Examples

1
2
3
4
5
6
7
8
-- Create my_server.
openGauss=# CREATE SERVER my_server FOREIGN DATA WRAPPER log_fdw;

-- Change the name of a foreign server.
openGauss=# ALTER SERVER my_server RENAME TO my_server_1;

-- Drop my_server_1.
openGauss=# DROP SERVER my_server_1;

Helpful Links

CREATE SERVER and DROP SERVER