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.NoteIf 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.
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;
For more information about the pg_timezone_names table, see pg_timezone_names.
References
If you do not specify a time zone when you create an RDS instance, the system assigns the default time zone of the region that you specify for the RDS instance. For more information, see Default time zones for ApsaraDB RDS for PostgreSQL instances.
ApsaraDB RDS for PostgreSQL allows you to configure only time zone names. Time zones represented in UTC offsets are not supported. For more information, see Common time zones for ApsaraDB RDS for MySQL instances and ApsaraDB RDS for PostgreSQL instances.
You can also modify the timezone parameter by calling an API operation.
Operation
Description
Modifies the parameters of an instance.