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
On this page

Before You Start

Updated on 2023-10-23 GMT+08:00

This section explains how to use databases, including creating databases and tables, inserting data to tables, and querying data in tables.

Prerequisites

GaussDB is running properly.

Procedure

  1. Connect to a database. For details, see Connecting to a Database.
  2. Create a database user.

    Only administrators that are created during database installation can access the initial database by default. You can also create other database users.

    1
    openGauss=# CREATE USER joe WITH PASSWORD "xxxxxxxxx";
    

    If the following information is displayed, the table has been created:

    1
    CREATE ROLE
    

    In this case, you have created a user named joe, and the user password is xxxxxxxxx.

    Run the following command to set user joe as the system administrator.

    openGauss=# GRANT ALL PRIVILEGES TO joe;

    Run the GRANT command to set related permissions. For details, see GRANT.

    Note: For details about how to create users, see Managing Users and Their Permissions.

  3. Create a database.

    1
    openGauss=# CREATE DATABASE db_tpcc OWNER joe;
    

    If the following information is displayed, the database has been created:

    1
    CREATE DATABASE
    

    After db_tpcc database is created, you can run the following command to exit the postgres database and log in to the db_tpcc database as the user you created for more operations. You can also continue using the default postgres database.

    openGauss=# \q
    gsql -d db_tpcc -p 8000 -U joe
    Password for user joe:
    gsql((GaussDB Kernel VxxxRxxxCxx 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_tpcc=> 

    Create a schema.

    db_tpcc=> CREATE SCHEMA joe AUTHORIZATION joe;

    If the following information is displayed, the schema has been created:

    1
    CREATE SCHEMA
    

    Note:

    New databases are created in the pg_default tablespace by default. To specify another tablespace, run the following statement:

    1
    2
    openGauss=# CREATE DATABASE db_tpcc 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.

  4. Create a table.

    • Create a table named mytable that has only one column. The column name is firstcol and the column type is integer.
      1
      db_tpcc=>  CREATE TABLE mytable (firstcol int);
      
      1
      CREATE TABLE
      
    • Insert data into the table.
      1
      db_tpcc=> INSERT INTO mytable values (100);
      

      If the following information is displayed, the data has been inserted:

      1
      INSERT 0 1
      
    • View the data in the table.
      1
      2
      3
      4
      5
      db_tpcc=> SELECT * from mytable;
       firstcol 
      ----------
            100
      (1 row)
      

    Note:

    • By default, new database objects, such as the newly created table, are created in the $user schema. For more details about schemas, see Creating and Managing Schemas.
    • For more details about how to create a table, see Creating and Managing Tables.
    • In addition to the created tables, a database contains many system catalogs. These system catalogs contain database installation information and information about various queries and processes in GaussDB. You can collect information about the database by querying system catalogs. For details, see Querying a System Catalog.

      GaussDB supports hybrid row-column store, providing high query performance for interaction analysis in complex scenarios. For details about how to select a store method, see Planning a Storage Model.

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