Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

ALTER DATABASE

Updated on 2022-07-29 GMT+08:00

Function

This command is used to modify the attributes of a database, including the database name, owner, maximum number of connections, and object isolation attribute.

Important Notes

  • Only the owner of a database or a system administrator has the permission to run the ALTER DATABASE statement. Users other than system administrators may have the following permission constraints depending on the attributes to be modified:
    • To modify the database name, you 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.
    • Only database owners and system administrators can modify the object isolation attribute of a database.
  • You are not allowed to rename a database in use. To rename it, connect to another database.

Syntax

  • Modify the maximum number of connections of the database.
    1
    2
    ALTER DATABASE database_name
        [ [ WITH ] CONNECTION LIMIT connlimit ];
    
  • Rename the database.
    1
    2
    ALTER DATABASE database_name
        RENAME TO new_name;
    
    NOTE:

    If the database contains OBS hot or cold tables, the database name cannot be changed.

  • Change the database owner.
    1
    2
    ALTER DATABASE database_name
        OWNER TO new_owner;
    
  • Change the default tablespace of the database.
    1
    2
    ALTER DATABASE database_name
        SET TABLESPACE new_tablespace;
    
    NOTE:

    The current tablespaces cannot be changed to OBS tablespaces.

  • Modify the session parameter value of the database.
    1
    2
    ALTER DATABASE database_name
        SET configuration_parameter { { TO | = } { value | DEFAULT } | FROM CURRENT };
    
  • Reset the database configuration parameter.
    1
    2
    ALTER DATABASE database_name RESET
        { configuration_parameter | ALL };
    
  • Modify the object isolation attribute of a database.
    1
    ALTER DATABASE database_name [ WITH ] { ENABLE | DISABLE } PRIVATE OBJECT;
    
    NOTE:
    • To modify the object isolation attribute of a database, the database must be connected. Otherwise, the modification will fail.
    • For a new database, the object isolation attribute is disabled by default. After this attribute is enabled, common users can view only the objects (such as tables, functions, views, and columns) that they have the permission to access. This attribute does not take effect for administrators. After this attribute is enabled, administrators can still view all database objects.

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.

  • 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, preferably between 1 and 50. The default value -1 indicates no restrictions.

  • new_name

    Specifies the new name of a database.

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

  • new_owner

    Specifies the new owner of a database.

    Value range: a string indicating a valid user name

  • configuration_parameter

    value

    Sets a specified database session parameter. 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 based on the database connected to the current 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 all the tables or indexes from the old tablespace to the new one. 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.

Examples

Modify the number of connections of the music database.

1
ALTER DATABASE music CONNECTION LIMIT= 10;

Change the name of the music database to music1.

1
ALTER DATABASE music RENAME TO music1;

Change the owner of the music1 database.

1
ALTER DATABASE music1 OWNER TO tom;

Modify the tablespace of the music1 database.

1
ALTER DATABASE music1 SET TABLESPACE PG_DEFAULT;

Disable the default index scan on the music1 database.

1
ALTER DATABASE music1 SET enable_indexscan TO off;

Reset the enable_indexscan parameter of the music1 database.

1
ALTER DATABASE music1 RESET enable_indexscan;

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback