The short answer is: Yes! The longer answer is: Yes, but very busy systems or in certain situations, you might experience a few hiccups.
The obvious place to look for the answer would be in the documentation. Unfortunately, there is no Patching Guide similar to the Upgrade Guide. The information in this blog post is pieced together from many different sources.
A few facts about patching with Datapatch:
- The database must be open in read write mode.
- You can’t run Datapatch on a physical standby database – even if it’s open (Active Data Guard).
- A patch is not fully installed until you have executed Datapatch successfully.
How To
First, let me state that it is fully supported to run Datapatch on a running database with users connected.
The procedure:
- Install a new Oracle Home and use OPatch to apply the desired patches.
- Shut down the database.
- Restart the database in the new, patched Oracle Home.
- Downtime is over! Users are allowed to connect to the database
- Execute
./datapatch -verbose.
- End of procedure. The patch is now fully applied.
Often users move step 4 (Downtime is over) to the end of the procedure. That’s of course also perfectly fine, but it does extend the downtime needed and often is not needed.
What About RAC and Data Guard
The above procedure is exactly what happens in a rolling patch apply on a RAC database. When you perform a rolling patch apply on a RAC database, there is no downtime at all. You use opatchauto to patch a RAC database. opatchauto restarts all instances of the database in the patched Oracle Home in a rolling manner. Finally, it executes datapatch on the last node. Individual instances are down temporarily, but the database is always up.
It is a similar situation when you use the Standby First Patch Apply. First, you restart all standby databases in the patched Oracle Home. Then, you perform a switchover and restart the former primary database in the patched Oracle Home. Finally, you execute datapatch to complete the patch installation. You must execute datapatch on the primary database.
Either way, don’t use Datapatch until all databases or instances run on the new, patched Oracle Home.
That’s It?
Yes, but I did write initally that there might be hiccups.
Waits
Datapatch connects to the database like any other session to make changes inside the database. These changes could be:
- Creating new tables
- Altering existing tables
- Creating or altering views
- Recreating PL/SQL packages like
DBMS_STATS
Imagine this scenario:
- You restart the database in the patched Oracle Home.
- A user connects and starts to use
DBMS_STATS.
- You execute
datapatch.
- Datapatch must replace
DBMS_STATS to fix a bug.
- Datapatch executes
CREATE OR REPLACE PACKAGE SYS.DBMS_STATS .....
- The Datapatch database session go into a wait.
- User is done with
DBMS_STATS.
- The Datapatch session come out of wait and replace the package.
In this scenario, the patching procedure was prolonged due to the wait. But it completed eventually.
Hangs
From time to time, we are told that Datapatch hangs. Most likely, it is not a real hang, but just a wait on a lock. You can identify the blocking session by using How to Analyze Library Cache Timeout with Associated: ORA-04021 ‘timeout occurred while waiting to lock object %s%s%s%s%s.’ Errors (Doc ID 1486712.1).
You might even want to kill the blocking session to allow Datapatch to do its work.
Timeouts
What will happen in the above scenario if the user never releases the lock on DBMS_STATS? By default, Datapatch waits for 15 minutes (controlled by _kgl_time_to_wait_for_locks) before throwing an error:
ORA-04021: timeout occurred while waiting to lock object
To resolve this problem, restart Datapatch and ensure that there are no blocking sessions. Optionally, increase the DDL timeout:
./datapatch -ddl_lock_timeout <time-in-sec>
Really Busy Databases
I recommend patching at off-peak hours to reduce the likelihood of hitting the above problems.
If possible, you can also limit the activity in the database while you perform the patching. If your application is using e.g. DBMS_STATS and locking on that object is often a problem, you can hold off these sessions for a little while.
The Usual Suspects
Based on my experience, when there is a locking situation, these are often the sinner:
- Scheduler Jobs – if you have jobs runnings very frequently, they may all try to start when you restart your database in the new Oracle Home. Suspend the workload temporarilty by setting
job_queue_processes to 0.
- Advanced Queeing – if you have lots of activities happening via AQ, you can suspend it temporarily by setting
aq_tm_processes to 0. If you disable the scheduler, you also disable AQ.
- Materialized Views – when the database refreshes materialized views it uses internal functionality (or depending objects) that Datapatch needs to replace. By disabling the scheduler, you also disable the materialized view refreshes.
- Backup jobs – I have seen several situations where Datapatch couldn’t replace the package
dbms_backup_restore because the backup system took archive backups.
Last Resort
If you want to be absolutely sure no one intervenes with your patching, use this approach. But it means downtime:
SQL> startup restrict
./datapatch -verbose
SQL> alter system disable restricted session;
I don’t recommend starting in upgrade mode. To get out of upgrade mode a database restart is needed extending the downtime window.
Datapatch And Resources
How much resources does Datapatch need? Should I be worried about Datapatch depleting the system?
No, you should not. The changes that Datapatch needs to make are not resource-intensive. However, a consequence of the DDL statements might be object invalidation. But even here, you should not worry. Datapatch will automatically recompile any ORACLE_MAINTAINED object that was invalidated by the patch apply. But the recompilation happens serially, i.e., less resources needed.
Of course, if you system is running at 99% capacity, it might be a problem. On the other hand, if your system is at 99%, patching problems are probably the least of your worries.
What About OJVM
If you are using OJVM and you apply the OJVM bundle patch, things are a little different.
| Release |
RAC Rolling |
Standby-First |
Datapatch |
| Oracle Database 21c |
Fully |
No |
No Datapatch downtime. |
| Oracle Database 19c + 18c |
Partial |
No |
No Datapatch downtime, but java system is patched which requires ~10 second outage. Connected clients using java will receive ORA-29548. |
| Oracle Database 12.2 + 12.1 |
No |
No |
Datapatch must execute in upgrade mode. |
| Oracle Database 11.2.0.4 |
No |
No |
Similar to 12.2 and 12.1 except you don’t use Datapatch. |
Mike Dietrich also has a good blog that you might want to read: Do you need STARTUP UPGRADE for OJVM?
What About Oracle GoldenGate
You should stop Oracle GoldenGate when you execute datapatch. When datapatch is done, you can restart Oracle GoldenGate.
If you are manually recompiling objects after datapatch, I recommend that you restart Oracle GoldenGate after the recompilation.
The above applies even if the patches being applied does not contain any Oracle GoldenGate specific patches.
Oracle GoldenGate uses several objects owned by SYS. When datapatch is running it might change some of those objects. In that case, unexpected errors might occur.
Recommendations
Based on my experience, these are my recommendations
Before Patching
- Recompile invalid objects (
utlrp).
- Perform a Datapatch sanity check (
$ORACLE_HOME/OPatch/datapatch -sanity_checks).
- Postpone your backup jobs.
- Stop any Oracle GoldenGate processes that connects to the database.
- Disable the scheduler.
Patching
- Always use the latest OPatch.
- Always use out-of-place patching, even for RAC databases.
- Always enable verbose output in Datapatch (
$ORACLE_HOME/OPatch/datapatch -verbose).
After Patching
- If applicable, re-enable
- Backup jobs.
- Oracle GoldenGate processes.
- The scheduler.
- Check Datapatch output. If Datapatch failed to recompile any objects, a message is printed to the console. If you patch interactively, you can find the same information in the log files.
Still Don’t Believe Me?
In Autonomous Database (ADB), there is no downtime for patching. An ADB runs on RAC and patching is fully rolling. The automation tooling executes Datapatch while users are connected to the database.
Of course, one might run into the same issues described above. But Oracle have automation to handle the situation. If necessary, the database kills any sessions blocking Datapatch. In the defined maintenance window in your ADB, you may end up in a situation that a long-running, blocking session terminates because it was blocking a Datapatch execution. But if you minimize your activities in the defined maintenance windows, then chances of that happening is minimal.
Conclusion
Go ahead and patch your database with Datapatch while users are connected.
Further Reading