Modify the time zone of your ApsaraDB RDS for PostgreSQL instance if the current setting does not meet your business requirements or if your application handles data across multiple time zones. This ensures that data is correctly converted and displayed across different time zones.
Prerequisites
You have an ApsaraDB RDS for PostgreSQL instance that uses cloud disks.
Usage notes
-
The
SET timezonestatement applies only to the current session and is not persistent. To make the change permanent, modify the parameter as described in Set instance parameters. -
To set a time zone for a specific database, run this statement:
ALTER DATABASE <database_name> SET timezone TO '<time_zone_name>';.NoteTo reset the time zone of a database to the system default, run this statement:
ALTER DATABASE <database_name> SET timezone TO DEFAULT;. -
PostgreSQL supports two data types for storing timestamps: TIMESTAMP and TIMESTAMPTZ. Choose the appropriate data type based on your business requirements:
-
TIMESTAMP: This data type stores date and time values in UTC but does not store time zone information. If you modify the time zone as described in this topic, query results for this data type remain unchanged.
-
TIMESTAMPTZ: This data type is time zone-aware. When you store a timestamp, PostgreSQL converts it to UTC for storage. When you retrieve the data, PostgreSQL converts it from UTC to the time zone set for the instance or session. If you modify the time zone as described in this topic, query results for this data type automatically reflect the new time zone.
-
Modify the time zone
For an ApsaraDB RDS for PostgreSQL instance that uses cloud disks, go to the Parameters page in the console to modify the timezone parameter. For detailed instructions, see Set instance parameters.
The default value of the timezone parameter is Asia/Shanghai. Modifying this parameter does not require an instance restart.
ApsaraDB RDS for PostgreSQL instances that use Premium Local SSD do not support the timezone parameter.
View supported time zones
To view all supported time zones, run this command:
SELECT name,utc_offset FROM pg_timezone_names;
For more information about the pg_timezone_names table, see pg_timezone_names.
Related documents
-
If you do not configure the time zone parameter when you create an instance, the system assigns a default time zone based on the region. For a list of regions and their corresponding default time zone names, see Default time zone names for ApsaraDB RDS for PostgreSQL instances by region.
-
ApsaraDB RDS for PostgreSQL supports only time zone names, not UTC offsets. For a list of commonly used time zone names, see List of common time zone names for ApsaraDB RDS for PostgreSQL instances.
-
You can also use an API operation to modify the timezone parameter.
API
Description
Modifies instance parameters