Skip to main content

Upgrade the Oracle Database Time Zone File Using the DBMS_DST Package


Upgrade the Oracle Database Time Zone File Using the DBMS_DST Package


The current web page context is about how to upgrade the database time zone file using the DBMS_DST package. Here are some key takeaways:

  • The DBMS_DST package is a PL/SQL package that simplifies the process of upgrading the database time zone file and the time zone data based on the new file.
  • Upgrading the time zone file is necessary when countries change their time zones or daylight saving time policies, which may affect the data stored in TIMESTAMP WITH TIME ZONE columns.
  • The DBMS_DST package provides procedures to check the current and latest versions of the time zone file, prepare for the upgrade, perform the upgrade, and end the upgrade.
  • The upgrade process involves three phases: prepare, upgrade, and end. The prepare phase is optional but recommended to check the impact of the upgrade. The upgrade phase can be done in online or offline mode. The end phase finalizes the upgrade and cleans up temporary data.

1.0. Check Current Time Zone Version

SELECT * FROM v$timezone_file;
or
SELECT tz_version FROM registry$database;
or
COLUMN property_name FORMAT A30
COLUMN property_value FORMAT A20
SELECT property_name, property_value FROM database_properties WHERE  property_name LIKE 'DST_%' ORDER BY property_name;
or
alter system set "_exclude_seed_cdb_view"=false scope=both;
select value$, con_id from containers(SYS.PROPS$) where NAME='DST_PRIMARY_TT_VERSION' order by 2;

1.1. Latest timezone file

SELECT DBMS_DST.get_latest_timezone_version FROM dual;

2.0. Prepare for the Time Zone Upgrade

DECLARE
  l_tz_version PLS_INTEGER;
BEGIN
  l_tz_version := DBMS_DST.get_latest_timezone_version;

  DBMS_OUTPUT.put_line('l_tz_version=' || l_tz_version);
  DBMS_DST.begin_prepare(l_tz_version);
END;
/

2.1. Check the DST_UPGRADE_STATE

COLUMN property_name FORMAT A30
COLUMN property_value FORMAT A20
SELECT property_name, property_value FROM database_properties WHERE  property_name LIKE 'DST_%' ORDER BY property_name;

Now DST_UPGRADE_STATE is in PREPARE mode.

3.0. To clear the data from the tables that store the information about the affected tables and the errors, you need TRUNCATE sys.dst$affected_tables and sys.dst$error_table. If you have created your own custom tables using the CREATE_AFFECTED_TABLE, CREATE_ERROR_TABLE, or CREATE_TRIGGER_TABLE, then you need to TRUNCATE those tables instead of the default ones.

TRUNCATE TABLE sys.dst$affected_tables;
TRUNCATE TABLE sys.dst$error_table;

3.1. To identify the tables that affected by the upgrade. This query will return the names of the tables and columns that have the TIMESTAMP WITH TIME ZONE data type. If you do not use this data type in your database, the query will return an empty result set.

EXEC DBMS_DST.find_affected_tables;

3.2. Check the results of the executing the DBMS_DST.find_affected_tables procedure.

SELECT * FROM sys.dst$affected_tables;
SELECT * FROM sys.dst$error_table;

3.3. After reviewing the tables that will be impacted by the operation and confirming that you are ready to proceed, you can complete the prepare stage.

EXEC DBMS_DST.end_prepare;

4.0. Upgrade the Time Zone File (Multitenant)

The time zone file is a critical component of a multitenant database, as it affects the date and time calculations for different regions. When upgrading the time zone file, you need to ensure that all containers are updated, not just the root container. Otherwise, you will have inconsistency and errors in your data. The "catcon.pl" Perl script is a tool that allows you to run commands or scripts in multiple containers at once. By using this script, you can upgrade the time zone file in the root container and all PDBs in one step. This will also ensure that any new PDBs created from the seed will have the latest time zone file.

4.1. Create a script with the following contents. The shutdown and startup operations are obsolete from 21c onward.

tee /oracle/scripts/ug/tz/upgrade_tzf.sql > /dev/null << EOF
-- Pre-21c Version only.
SHUTDOWN IMMEDIATE;
STARTUP UPGRADE;

SET SERVEROUTPUT ON
DECLARE
  l_tz_version PLS_INTEGER;
BEGIN
  SELECT DBMS_DST.get_latest_timezone_version
  INTO   l_tz_version
  FROM   dual;

  DBMS_OUTPUT.put_line('l_tz_version=' || l_tz_version);
  DBMS_DST.begin_upgrade(l_tz_version);
END;
/

-- Pre-21c Version only.
SHUTDOWN IMMEDIATE;
STARTUP;

SET SERVEROUTPUT ON
DECLARE
  l_failures   PLS_INTEGER;
BEGIN
  DBMS_DST.upgrade_database(l_failures);
  DBMS_OUTPUT.put_line('DBMS_DST.upgrade_database : l_failures=' || l_failures);
  DBMS_DST.end_upgrade(l_failures);
  DBMS_OUTPUT.put_line('DBMS_DST.end_upgrade : l_failures=' || l_failures);
END;
/
EOF

4.2. Run the above script to all of the containers.

To execute the script on all containers, we use the "catcon.pl" Perl script. The -n parameter is set to 1, so the script runs each PDB recompilation in sequence.. The script performs a shutdown and startup. If the script is executed in parallel, the root container will interfere with some of the PDBs' upgrade when it shuts down or starts up. Using a single worker ensures a sequential order. You may run it in cron job.

touch /oracle/scripts/ug/tz/upgrade_tzf.log
touch /oracle/scripts/ug/tz/upgrade_tzf.lockfile
touch /oracle/scripts/ug/tz/upgrade_tzf.sh
chmod a+x /oracle/scripts/ug/tz/upgrade_tzf.sh

watch -n 1 'ps -axuwwf | grep upgrade_tzf'
watch -n 1 'sudo tail -n 5 /var/log/cron'
tail -f -n 5 /oracle/scripts/ug/tz/upgrade_tzf.lockfile
tail -f -n 5 /oracle/scripts/ug/tz/upgrade_tzf.log

tee /oracle/scripts/ug/tz/upgrade_tzf.sh > /dev/null << EOF
#!/bin/bash
echo 'Generating Config File Start............................................'$(date) 2>&1 | tee /oracle/scripts/ug/tz/upgrade_tzf.log
source /oracle/scripts/Oracle19cEnvVar.sh
$ORACLE_HOME/perl/bin/perl -I$ORACLE_HOME/perl/lib -I$ORACLE_HOME/rdbms/admin $ORACLE_HOME/rdbms/admin/catcon.pl -n 1 -l /oracle/scripts/ug/tz/ -b upgrade_tzf -d /oracle/scripts/ug/tz/ /oracle/scripts/ug/tz/upgrade_tzf.sql 2>&1 | tee -a /oracle/scripts/ug/tz/upgrade_tzf.log
echo 'Generating Config File End............................................'$(date) 2>&1 | tee -a /oracle/scripts/ug/tz/upgrade_tzf.log
EOF

crontab -e
#50 18 * * 4 /usr/bin/flock -n /oracle/scripts/ug/tz/upgrade_tzf.lockfile /oracle/scripts/ug/tz/upgrade_tzf.sh > /dev/null 2>&1

5.0. 21c and onward Update
One of the new features of Oracle 21c is the ability to update the time zone file without putting the database in upgrade mode. This means that the database can remain online and available while the time zone file is upgraded to the latest version. To perform this operation, you can use the following command:

alter system set timezone_version_upgrade_online=true;

Now follow the setp 4 without database shutdown and startup command.

6.0. Conclusion

In conclusion, upgrading the Oracle Database time zone file using the DBMS_DST package is a necessary and beneficial process that allows the database to handle changes in daylight saving time rules and ensure data accuracy and consistency. The DBMS_DST package provides various procedures and functions to perform the upgrade in a safe and efficient manner, such as validating the data, preparing the upgrade scripts, applying the patches, and verifying the results. The upgrade process requires careful planning and testing before applying it to the production environment, as well as proper backup and recovery strategies in case of any issues. By following the steps and best practices outlined in this document, you can successfully upgrade the Oracle Database time zone file using the DBMS_DST package and enjoy the benefits of having an up-to-date and reliable database.

Comments

Popular posts from this blog

Upgrading Issue for RHEL 7 to 8 With Leapp

Overview The Leapp utility is a framework for updating and upgrading operating systems as well as applications. The operations of this utility consist of two phases 1. the preupgrade Phase – that chack the upgrade possibilities and 2. the actual upgrade phase – that map packages between previous and current versions of the software packages. Issue – 01: After running ‘ sudo leapp preupgrade ‘ sometimes you find the below issue in ‘ /var/log/leapp/leapp-report.txt ‘. Detail: Risk Factor: high (inhibitor) Title: Leapp detected loaded kernel drivers which have been removed in RHEL 8. Upgrade cannot proceed. Summary: Support for the following RHEL 7 device drivers has been removed in RHEL 8: – pata_acpi Key: f08a07da902958defa4f5c2699fae9ec2eb67c5b Remediation: 1. Disable detected kernel drivers in order to proceed with the upgrade process using the rmmod or modprobe -r . rmmod – Simple program to remove a module from the Linux Kernel modprobe – Add and remove modules from the Linux Ke...

Upgrading Oracle Linux 6 to 7

Overview It is possible to upgrade an Oracle Linux 6 system to Oracle Linux 7.6 under the following conditions: The system meets the minimum installation requirements for Oracle Linux 7 as described in Chapter 1, System Requirements and Limits. The Oracle Linux 6 system has been completely updated from the ol6_x86_64_latest channel or ol6_latest repository. UEK R3 or UEK R4 has been installed on the system to be upgraded and is the default boot kernel. Upgrading from UEK R2 is not supported. Note that the system is upgraded to use the UEK R5 release provided with Oracle Linux 7.6. Upgrading is supported only for systems that are installed with the Minimal Install base environment. If additional packages are installed from an alternative repository or channel, upgrade might fail or the resulting upgrade might not function as expected. reference: https://docs.oracle.com/en/operating-systems/oracle-linux/7/relnotes7.6/ol7-install.html#ol7-upgrade-ol6 Verifying the system before Upgrade: #...

Install Oracle Database 12c Release 2 On Red Hat 8

Overview According to Oracle, Oracle Database 12c is ‘the first database designed for the cloud’; the suffix ‘c’ stands for the cloud. There are many new features in this release such as multitenant architecture, pluggable database, in-memory, etc. The multitenant architecture is designed to simplify consolidation without requiring any changes to the applications. The rapid provisioning and portability capabilities are enhanced by the pluggable databases. Another new feature is in-memory makes it the first Oracle database to offer real-time analytics. This article describes the installation of Oracle Database 12c release 2 (12.2.0.1.0) 64-bit on Red Hat 8 64-bit. Lab Environment Server Machine Work Station or Client Machine OS Release Red Hat Enterprise Linux release 8.4 (Ootpa) Red Hat Enterprise Linux release 8.4 (Ootpa) Kernel 4.18.0-305.3.1.el8_4.x86_64 4.18.0-305.7.1.el8_4.x86_64 Release Oracle Database 12.1.0.2.0 Oracle SQL Developer Version 19.2.1.247 IP Address 192.168.201.116 ...