Oracle DST time zone upgrade

Upgrade Oracle Database Time Zone (DST) version: Key Considerations

It depends. When I was a junior, I used to be frustrated by that answer, but now I’ve come to understand and appreciate it. If your database does not store any timestamp data with a time zone (i.e., the data types DATE or TIMESTAMP are without time zone attributes), then it may not be necessary. However, you might think, ‘I don’t have any data that should make me anxious, and I can just stay up-to-date since it’s always recommended to keep up with the latest updates.’

But if your organization operates across different geographic regions with clients in different time zones, and you have data stored with time zone information, then it is important to consider time zones when managing your data.

The TIMESTAMP WITH TIME ZONE (TSTZ) and TIMESTAMP WITH LOCAL TIME ZONE (TSLTZ) data types depend on time zone information, whereas DATE and TIMESTAMP data types do not.

TSTZ stores both the timestamp and the time zone offset/name at the time of insertion. This makes it ideal for applications dealing with multiple time zones, as it retains the original time zone used. This way, you have the complete offset or named time zone information preserved.

When users input timestamps with a time zone, Oracle Database automatically converts the data to UTC, using the transition rules defined in the time zone file. Upon retrieval, the database performs the reverse conversion from UTC back to the original time zone. For example, the timestamp TIMESTAMP ‘2024-13-11 13:00:00 Europe/Istanbul’ is stored as UTC value 2024-13-11 10:00:00 (along with the original time zone identifier for ‘Europe/Istanbul’). This is because Istanbul was operating at UTC +3 hours at that time.

TSLTZ does not store explicit time zone information. Instead, it normalizes the timestamp to the database’s time zone (DBTIMEZONE value of database) when data is sent to and from clients. Internally, it converts timestamps based on the database time zone at the time of insertion and retrieval. TSLTZ requires 11 bytes of storage.

TSTZ requires 13 bytes of storage (2 more bytes than TIMESTAMP and TSLTZ) because it stores additional time zone information, either as a region name or as a UTC offset.

A common misconception is that the database time zone should match your server’s physical location. This is not necessary. The database time zone has no impact on where the server is hosted. The best practice is to set time_zone (DBTIMEZONE) to +00:00 (or another offset like -09:00 or +08:00) and leave it unchanged if already set to an offset. It is strongly recommended to never use any named time zone that is affected by DST as a database time zone, the preferred value is an offset like +00:00 .

Tables that contain TSTZ columns must be in a state that allows updates while apply script was running during the timezone upgrades. Timestamps affected by time zone changes must be converted. However, DST updates do not directly affect the data stored in TSLTZ columns.

Although it may seem a bit complicated at first glance, I recommend reading Timestamps & time zones – Frequently Asked Questions (Doc ID 340512.1) , Primary Note DST FAQ : Updated DST Transitions and New Time Zones in Oracle RDBMS and OJVM Time Zone File Patches (Doc ID 412160.1) and How to Determine Whether Time Zone Changes Will Affect Your Database (Doc ID 406410.1) to better understand the concepts and the impact of a time zone upgrade on the database.

You may use query provided below to find columns with timezone data. (Both TSTZ and TSLTZ)

ORA-39405: Oracle Data Pump does not support importing from a source database with TSTZ version 43 into a target database with TSTZ version 32.
ORA-39405
Oracle Data Pump does not support importing from a source database with TSTZ version string into a target database with TSTZ version string.
Cause
The source database was at a different time zone version than the target database and there were tables that contained TIMESTAMP WITH TIME ZONE (TSTZ) data.
Action
Convert the target database to the same time zone version or later as the source database or use Oracle Data Pump with conventional data movement to export then import this data.

Also There is a pitfall to be aware of before updating the database time zone is the possibility of encountering the ORA-39405 error in datapump operations even if you don’t have any timestamp data with time zones in the data you are trying to transfer. Oracle Data Pump does not support importing from a source database with TSTZ version X into a target database with TSTZ version Y. This issue occurs when the time zone version on your source database is newer than the version on the target database. The time zone file is cumulative, meaning it includes information from past versions but doesn’t have any info about future versions. As a result, if you’re migrating to an older time zone release, the target database won’t be able to correctly interpret the time zone from the source database. Impdp to a higher DST version is not a problem. The issue occurs while you want to go backwards only.

Of course there are some workarounds in Mike Dietrich’s blog post ORA-39405 with impdp when you have mixed time zone versions. You can also use the workaround provided below. I came across this idea from Shakil Shaikh in a LinkedIn comment.

A simple solution for ORA-39405: Oracle Data Pump does not support importing from a source database with TSTZ version 43 into a target database with TSTZ version 32.

Actually, Updating the target database time zone to the same time zone version as the source database will fix all these errors.

Updated on 06.02.2025 : : According to Mike Dietrich’s blog post, “Remember ORA-39405 with impdp? There is a fix for it,” a fix (Patch 37041429) will be available soon and is most likely to be shipped with the Data Pump Bundle Patch.

Exadata image version updates do not include the database, JDK/JRE or OJVM time zone upgrades by default. Only Operating system time zone files are updated at the image upgrade (operating system) phase. There should be no problem with updating database time zones. When the database has a more up-to-date time zone file than the storage server (cell), it sends the updated file to the cell.

This transfer happens when a query is executed. If a newer time zone file is found on the DB node, it is sent to the cell. From that point on, the new time zone file is cached on the cellsrv. Considering that each PDB may have a different database time zone, it’s understandable why it works this way. There is also a document you may refer to “Exadata and DST (time zones) (Doc ID 1343576.1)“.

DST Upgrade for OJVM : There are very few applications who actually use the DST information of the OJVM. OJVM and Database DST version are NOT depending on each other and they can be at different versions.

DST Upgrade for Java : There is no technical need to apply “java DST updates” to the JDK/JRE that is installed in the Oracle Database Home, this information is not used by the database at all.

No action should be taken for Oracle Grid Software.

Note: Much more detailed information about the separate update procedures for each component/product is provided in the Applying document for DSTvx. For version 43, you can refer to Applying the DSTv43 Update for the Oracle Database (Doc ID 3002390.1) for a comprehensive explanation.

It’s time to roll up our sleeves and get the job done.

Since Oracle Database 19c Release Update (RU) 19.18 all available time zone files are shipped and deployed to $ORACLE_HOME/oracore/zoneinfo but not applied. That is up to us.

I will provide the steps for a non-CDB 19c database. For a CDB with PDBs, the process is largely the same, you will follow the same routine for each PDB and CDB. The PDB$SEED always receives the time zone during the creation of the CDB. Officially, upgrading PDB$SEED is not supported, but there are possible solutions available.

As I already have DBRU 19.24 installed, I have latest time zone files on my database homes.

Chapter 4 Datetime Data Types and Time Zone Support of Database Globalization Support Guide for Oracle Database 19c is the guide we will follow.

We will run utltz_countstats.sql script which shows the optimizer statistics of num_rows of all the tables having TIMESTAMP WITH TIME ZONE (TSTZ) data. Since it relies on database optimizer statistics, statistics should be up to date. If not you should run the utltz_countstar.sql script.

To minimize the downtime, we will purge the scheduler job log records.

Whenever statistics in the dictionary are modified, older versions of the statistics are automatically saved for potential future restoration. These versions are stored in the SYS.WRI$_OPSTAT_HIST* tables. Since these tables can hold large amounts of data, and to minimize the overall process duration, we will purge older statistics.

Using DBMS_STATS.PURGE_STATS(DBMS_STATS.PURGE_ALL) performs a fast TRUNCATE instead of a DELETE, especially on systems version 11.2.0.3 and above. This method is significantly faster for purging millions of rows from SYS.WRI$_OPTSTAT_HIST% tables compared to DBMS_STATS.PURGE_STATS(systimestamp). It only affects historical stats tables without touching current statistics, making it a safe and efficient option.

Check the version of current time zone file.

You can stop applications here. (Internet Information Services and all other middleware products etc.) At the apply stage database will be restarted twice. No application should query or insert time zone data in the database during the time zone upgrade process.

TIME ZONE_VERSION_UPGRADE_ONLINE parameter which comes with 21c, also gives the chance of near zero downtime time zone upgrade.

Change RAC database to single instance (by setting cluster_database to FALSE). Otherwise you may get the warning provided below when running utltz_upg_check.sql

You may also take a restore point as a precautionary measure, just to ensure you have a recovery plan in place. I assume that your applications are stopped and no data is being modified at the moment. Daniel Overby Hansen demonstrates how you can revert a time zone file upgrade using Flashback Database.

We will run check script (utltz_upg_check.sql)

On Standby Databases:

Time zone upgrade patch starts the primary database in upgrade mode, but redo logs that were generated while the database is in upgrade mode cannot be applied to an active standby/data guard database. Otherwise MRP process will get terminated with error ORA-10485 You should stop Real Time Apply in standby databases and apply shoud be started with using archived logfile.

On Primary Database:

If the check script (utltz_upg_check.sql) runs successfully, we will complete the database time zone upgrade with the apply (utltz_upg_apply.sql) command. This will restart the database twice. First, it will restart the database in UPGRADE mode to begin the DST upgrade and update all SYS-owned TSTZ data. On the second restart, it will restart the database in NORMAL mode to upgrade non-SYS TSTZ data

The TZ_VERSION column in the Registry$database table now updated with the new time zone version.

Hope it helps.


Discover More from Osman DİNÇ


Comments

Leave your comment