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

Creating and Managing Databases

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

Prerequisites

Only the database system administrator or users granted with database creation permissions can create a database. For details about how to grant database creation permissions to a user, see Users and Permissions.

Context

  • GaussDB has two default template databases template0 and template1 and a default user database postgres.
  • CREATE DATABASE creates a database by copying a template database Only template0 can be copied. Do not use a client or other methods to connect to or operate the two template databases.
    NOTE:
    • The template database does not contain any user table. You can view the attributes of the template database in the PG_DATABASE system catalog.
    • The template0 template does not allow user connections. Only the initial user of the database and the system administrator can connect to template1.
  • A database system consists of multiple databases. A client can connect to only one database at a time. Currently, cross-database query or cross-database transaction is not supported.
  • If multiple databases exist in the database cluster, you can use the -d parameter of the client tool to specify the target database for login. Alternatively, you can run the \c command to switch the database after the client program logs in to the database.

Precautions

Assume that the database encoding is SQL_ASCII. (You can run the show server_encoding command to query the encoding used for storing data in the current database.) If the database object name contains multi-byte characters (such as Chinese) or if the object name length exceeds the allowed maximum (63 bytes), the database truncates the last byte (not the last character) of the object name. In this case, half characters may appear.

To resolve this problem, you need to:

  • Ensure that the name of the data object does not exceed the maximum length.
  • Use a proper coded character set, such as UTF-8, as the default database storage code set (server_encoding).
  • Exclude multi-byte characters from object names.
  • If you fail to delete an object whose name is truncated mistakenly, specify its original name to delete it, or manually delete it from the corresponding system catalog on each node.

Procedure

  1. Create a database named db_tpcds.

    1
    2
    gaussdb=# CREATE DATABASE db_tpcds;
    CREATE DATABASE
    
    NOTE:
    • Database names must comply with the general naming convention rules of SQL identifiers. The current role automatically becomes the owner of this new database.
    • If a database system is used to support independent users and projects, store them in different databases.
    • If the projects or users are associated with each other and share resources, store them in one database. However, you can divide them into different schemas. A schema is a logical structure, and the access permission for a schema is controlled by the permission system module.
    • A database name contains a maximum of 63 bytes and the excessive bytes at the end of the name will be truncated by the server. You are advised to specify a database name no longer than 63 bytes when you create a database.
    • New databases are created in the pg_default tablespace by default. Specify another tablespace.
      1
      2
      gaussdb=# CREATE DATABASE db_tpcds WITH TABLESPACE = hr_local;
      CREATE DATABASE
      

      hr_local indicates the tablespace name. For details about how to create a tablespace, see Creating and Managing Tablespaces.

    • After creating the db_tpcds database, you can perform other operations in the default postgres database. Alternatively, you can perform the following operations to exit the postgres database, connect to the db_tpcds database as a new user, and perform operations such as creating tables.
      gaussdb=# \q
      gsql -d db_tpcds -p 8000 -U joe
      Password for user joe:
      gsql((GaussDB Kernel 503.0.XXX build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release)
      Non-SSL connection (SSL connection is recommended when requiring high-security)
      Type "help" for help.
       
      db_tpcds=> 

  2. View databases.

    • Run the \l meta-command to view the database list of the database system.
      1
      gaussdb=# \l
      
    • Query the database list in the pg_database system catalog.
      1
      gaussdb=# SELECT datname FROM pg_database;
      

  3. Modify the database.

    You can modify database configuration such as the database owner, name, and default settings.

    • Rename the database.
      1
      2
      gaussdb=# ALTER DATABASE db_tpcds RENAME TO human_tpcds;
      ALTER DATABASE
      
    NOTE:

    After setting the parameters, you need to manually run the CLEAN CONNECTION command to clear the old connections. Otherwise, the parameter values between nodes may be inconsistent.

  4. Delete the database.

    You can run the DROP DATABASE command to delete a database. This command deletes the system directory in the database, as well as the database directory on the disk that stores data. Only the database owner or system administrator can delete a database. A database accessed by users cannot be deleted. You need to connect to another database before deleting this database.

    Delete the database.
    1
    2
    gaussdb=# DROP DATABASE human_tpcds;
    DROP DATABASE
    

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