All Products
Search
Document Center

ApsaraDB RDS:Change the time zone of an ApsaraDB RDS for PostgreSQL instance

Last Updated:Jan 17, 2024

If the time zone of your ApsaraDB RDS for PostgreSQL instance does not match business logic or your application needs to handle the data of multiple time zones, you can change the time zone of the RDS instance. This ensures that the data is correctly converted and displayed in different time zones.

Prerequisites

Your RDS instance uses cloud disks.

Usage notes

  • The SET timezone statement takes effect only for the current session. If you want the change to permanently take effect, we recommend that you change the time zone based on the description in Modify instance parameters.

  • If you want to specify a time zone for a database, execute the ALTER DATABASE <Name of the database> SET timezone TO '<Name of the time zone>'; statement.

    Note

    If you want to restore the time zone of a database to the default time zone, execute the ALTER DATABASE <Name of the database> SET timezone TO DEFAULT; statement.

  • PostgreSQL supports two data types for timestamps: TIMESTAMP and TIMESTAMPTZ. We recommend that you select a data type based on your business requirements.

    • TIMESTAMP: stores a combined date and time value in UTC, but does not store time zone data. If you change the time zone based on this topic, the query results of the value of this type remain unchanged.

    • TIMESTAMPTZ: stores a combined time zone-aware date and time value. When you insert a value of the TIMESTAMPTZ type, the system converts the value into a UTC value and stores the UTC value in a table. When you query the value from your RDS instance, the system converts the value into the time that is specified by the configured time zone for the instance or database. If you change the time zone based on this topic, the query results of the value of this type vary based on the new time zone.

Change the time zone

You can change the time zone only of an RDS instance that uses cloud disks. To change the time zone, log on to the ApsaraDB RDS console and modify the timezone parameter on the Parameters page. For more information, see Modify instance parameters.

timezone

Note

If an RDS instance uses local disks, the timezone parameter is not supported.

Query supported time zones

You can execute the following statement to query supported time zones:

SELECT name,utc_offset FROM pg_timezone_names;
Note

For more information about the pg_timezone_names table, see pg_timezone_names.

查看支持时区

References