• Data Warehouse Service

dws
  1. Help Center
  2. Data Warehouse Service
  3. Developer Guide
  4. SQL Reference
  5. SQL Syntax
  6. ALTER DATABASE

ALTER DATABASE

Function

ALTER DATABASE changes the attributes of the database, including its name, owner and connection limitation.

Only the owner of a database or a system administrator has the permission to run the ALTER DATABASE command. Users other than system administrators may have the following permission constraints depending on the attribute to be modified:

  • To modify the name of a database, the operator must have the CREATEDB permission.
  • To modify a database owner, you must be a database owner and a member of the new owner, and have the CREATEDB permission.
  • To change the default tablespace, you must be a database owner or a system administrator, and must have the CREATE permission on the new tablespace. This statement physically migrates tables and indexes in a default tablespace to a new tablespace. Note that tables and indexes outside the default tablespace are not affected.
  • Only a database owner or a system administrator can modify GUC parameters for the database.

Precautions

You cannot rename a database in use. To rename it, connect to another database.

Syntax

  • Set the maximum number of connections of the database.
    ALTER DATABASE database_name 
        [ [ WITH ] CONNECTION LIMIT connlimit ];
  • Change the name of the database.
    ALTER DATABASE database_name 
        RENAME TO new_name;
  • Change the owner of the database.
    ALTER DATABASE database_name 
        OWNER TO new_owner;
  • Change the specified session parameter value of the database.
    ALTER DATABASE database_name 
        SET configuration_parameter { { TO | = } { value | DEFAULT } | FROM CURRENT };
  • Change the database tablespace.
    ALTER DATABASE database_name
        SET TABLESPACE new_tablespace;
  • Reset the database configuration parameter.
    ALTER DATABASE database_name RESET 
        { configuration_parameter | ALL };

Parameter Description

  • database_name

    Specifies the name of the database whose attributes are to be modified.

    Value range: a string. It must comply with the naming convention rule.

  • connlimit

    Specifies the maximum number of concurrent connections that can be made to this database (excluding administrators' connections).

    Value range: The value must be an integer. It is recommended to set the value between 1 and 50. The default value -1 indicates that there is no restriction on the number of concurrent connections.

  • new_name

    Specifies the new name of a database.

    Value range: a string. It must comply with the naming convention rule.

  • new_owner

    Specifies the new owner of a database.

    Value range: A string. It must be a valid user name.

  • configuration_parameter

    value

    Sets a specified database session parameter to a specified value. If the value is DEFAULT or RESET, the default setting is used in the new session. OFF closes the setting.

    Value range: A string. It can be set to:

    • DEFAULT
    • OFF
    • RESET
  • FROM CURRENT

    Sets the value of the database based on the current connected session.

  • RESET configuration_parameter

    Resets the specified database session parameter.

  • RESET ALL

    Resets all database session parameters.

NOTE:
  • Modifies the default tablespace of a database by moving the table or index in the old tablespace into the new tablespace. This operation does not affect the tables or indexes in other non-default tablespaces.
  • The modified database session parameter values will take effect in the next session.

Example

See the Example in CREATE DATABASE.

Helpful Links

CREATE DATABASEDROP DATABASE