Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

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
Help Center/ GaussDB(DWS)/ Troubleshooting/ Database Parameter Modification/ How to Change a Database's Default Time Zone When the Database Time Is Different from the System Time

How to Change a Database's Default Time Zone When the Database Time Is Different from the System Time

Updated on 2025-01-06 GMT+08:00

Symptom

The database time is inconsistent with the operating system time. After a user queries the default database time SYSDATE, it is found that the database time is eight hours later than the Beijing time. As a result, the updated data cannot be accurately located.

Possible Causes

The UTC time zone is used to display and interpret GaussDB(DWS) database timestamps. If the operating system's time zone is not the UTC, time of the GaussDB(DWS) database will be inconsistent with the system time. Generally, the time zone of the cluster does not need to be changed. Configuring the time zone of the client may affect SQL execution.

Prerequisites

You are advised to modify the timezone parameter during off-peak hours.

Handling Procedure

Method 1: Change the default time zone of the database in a GaussDB(DWS) cluster.

  1. Log in to the GaussDB(DWS) console.
  2. In the navigation tree on the left, click Clusters.
  3. In the cluster list, find the target cluster and click its name. The Basic Information page is displayed.
  4. Click the Parameter Modifications tab and change the value of parameter timezone to your time zone. Then click Save.
  5. In the Modification Preview dialog box, confirm the modification and click Save.
  6. (Optional) Check the Restart Cluster column of the timezone parameter. It indicates whether you need to restart the cluster to make the parameter modification take effect.

    NOTE:

    The modification of the timezone parameter takes effect immediately. You do not need to restart the cluster.

Method 2: Run background commands to query and change the database time zone.

  1. Query the time zone and current time of the client. The time zone of the client is UTC, and the now() function returns the current time.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    SHOW time zone;
     TimeZone
    ----------
     UTC
    (1 row)
     
    select now();
                  now
    -------------------------------
     2022-05-16 06:05:58.711454+00
    (1 row)
    

  2. Create a data table. timestamp and timestamptz are common time types. timestamp does not store the time zone, and timestamptz does.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    CREATE TABLE timezone_test (id int, t1 timestamp, t2 timestamptz) DISTRIBUTE BY HASH (id);
    
    \d timezone_test
               Table "public.timezone_test"
     Column |            Type             | Modifiers
    --------+-----------------------------+-----------
     id     | integer                     |
     t1     | timestamp without time zone |
     t2     | timestamp with time zone    |
    

  3. Insert the current time into the timezone_test table and query the current table.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    INSERT INTO timezone_test values (1, now(), now() );
    show time zone;
     TimeZone
    ----------
     UTC
    (1 row)
    
    SELECT * FROM timezone_test;
     id |             t1             |              t2
    ----+----------------------------+-------------------------------
      1 | 2022-05-16 06:10:04.564599 | 2022-05-16 06:10:04.564599+00
    (1 row)
    

    The t1 (timestamp type) parameter discards the time zone information when saving data. The t2 (timestamptz type) parameter saves the time zone information.

  4. Set the time zone of the client to UTC-8. Query the timezone_test table again.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    SET time zone 'UTC-8';
    SHOW time zone;
     TimeZone
    ----------
     UTC-8
    (1 row)
    
    SELECT now();
                  now
    -------------------------------
     2022-05-16 14:13:43.175416+08
    (1 row)
    

  5. Insert the current time to the timezone_test table and query the table. The value inserted to t1 is UTC-8 time, and t2 converts the time based on the time zone of the client.

    1
    2
    3
    4
    5
    6
    7
    INSERT INTO timezone_test values (2, now(), now() );
    SELECT * FROM timezone_test;
     id |             t1             |              t2
    ----+----------------------------+-------------------------------
      1 | 2022-05-16 06:10:04.564599 | 2022-05-16 14:10:04.564599+08
      2 | 2022-05-16 14:15:03.715265 | 2022-05-16 14:15:03.715265+08
    (2 rows)
    
    NOTE:
    • The timestamp type is affected the time zone used when data is inserted. The query result is not affected by the time zone of the client.
    • The timestamptz type records the time zone information used when data is inserted. In a query, the time is converted based on the time zone of the client.

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback