Can I Run Datapatch When Users Are Connected

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:

  1. Install a new Oracle Home and use OPatch to apply the desired patches.
  2. Shut down the database.
  3. Restart the database in the new, patched Oracle Home.
  4. Downtime is over! Users are allowed to connect to the database
  5. Execute ./datapatch -verbose.
  6. 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:

  1. You restart the database in the patched Oracle Home.
  2. A user connects and starts to use DBMS_STATS.
  3. You execute datapatch.
    1. Datapatch must replace DBMS_STATS to fix a bug.
    2. Datapatch executes CREATE OR REPLACE PACKAGE SYS.DBMS_STATS .....
    3. The Datapatch database session go into a wait.
  4. User is done with DBMS_STATS.
  5. 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:

  1. SQL> startup restrict
  2. ./datapatch -verbose
  3. 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

11 thoughts on “Can I Run Datapatch When Users Are Connected

  1. Hi Daniel,

    running datapatch while users are already connected sounds good as it reduces downtime. But in case datapatch fails and you have to rollback the database (e.g. flashback to a GRP) you will lose data (committed transactions) of these users or of the application.

    Therefore, as long as datapatch succeeds, fine. In case datapatch fails, you might lose data. How do you solve this?

    Regards, Andreas

    Andreas Becker External On behalf of SAP AG Oracle Server Technologies – SAP Development T +49 6227 748276 E andreas.becker@sap.comandreas.becker@sap.com ORACLE Deutschland B.V. & Co. KG Hauptverwaltung: Riesstr. 25, D-80992 München

    [Green Oracle]http://www.oracle.com/commitmentOracle is committed to developing practices and products that help protect the environment

    Pflichtangaben/Mandatory Disclosure Statements: http://www.sap.com/company/legal/impressum.epx Diese E-Mail kann Betriebs- oder Geschäftsgeheimnisse oder sonstige vertrauliche Informationen enthalten. Sollten Sie diese E-Mail irrtümlich erhalten haben, ist Ihnen eine Kenntnisnahme des Inhalts, eine Vervielfältigung oder Weitergabe der E-Mail ausdrücklich untersagt. Bitte benachrichtigen Sie uns und vernichten Sie die empfangene E-Mail. Vielen Dank.

    This e-mail may contain trade secrets or privileged, undisclosed, or otherwise confidential information. If you have received this e-mail in error, you are hereby notified that any review, copying, or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal. Thank you for your cooperation.

    Like

  2. Hi Andreas,

    That’s a good question.

    First, you should always test changes in a test environment that is similar to the production environment.

    Second, if you have Data Guard you can follow the “standby-first patch apply” procedure. When the standby database is running in the new Oracle Home, you can convert it to a snapshot standby database and run the datapatch part. This will now test datapatch on your live production data. If that goes fine, you can revert the snapshot standby back to a physical standby database and follow the patching procedure.

    Finally, if datapatch fails on the production/primary database, you don’t have to roll back to the GRP. Datapatch has rollback functionality as well that can revert the changes made. Datapatch rollback should be sufficient to bring you back.

    Rollback to a GRP can be a solution, but it will never be “the only solution”. You can always get help from support if the datapatch rollback fails.

    Regards,
    Daniel

    Like

  3. Hi Daniel
    I run opatchauto apply successful now datapatch gave me errors and timeouts. I need to wait for the next window and low load. The question is how long can I wait and state running with the new binary already patched.?

    Like

  4. Hi,
    I couldn’t find a specific statement about this scenario. Personally, I would get it done as soon as possible. You can run datapatch with users connected. If you start datapatch and it runs into concurrency issues, it will wait until the locks can be acquired.
    I can’t give you a specific time. I guess if the database runs fine with no errors then you can wait for the next low-peak period. But I would get it done as soon as possible.
    Regards,
    Daniel

    Like

  5. ‪Thanks for your article, is it good idea to start only the database without the listener and run datapatch then start up the listener(extended outage I know). can be a solution for exceptional systems where known locking is happening.‬

    Also, sanity_checks flag can help report potential problem you might face during datapatch process in advance before actual implementation in maintenance window:

    ./datapatch -sanity_checks

    Liked by 1 person

  6. Hi,
    You can stop the listener, it would prevent people from logging on, but it is not my preferred option. Often, if you have more databases on the host, then the listener serves many databases. By stopping the listener, you are preventing users from connecting to the other databases.
    Further, stopping the listener only prevents connections from coming over the network. Local connections (like a cron job or the like) can still connect and jobs started by the database scheduler can kick off as well.
    In the blog post, I describe how to start up the database in restricted mode. That is my preferred method.

    The datapatch sanity checks are a fairly new concept. The developers are working on finalizing the documentation. Once it is out, I will blog about it as well. But you’re right. It is a good way of checking your system before starting a patch installation.

    Regards,
    Daniel

    Like

  7. So pure technically, the answer is No, since you’re making changes, and usage should be prohibited during such changes. And that’s it. An option is to take risks, obviously. But then I can come up with many more things that take risks.

    Like

  8. Hi John,
    Thanks for the input, but I disagree with you. The patching process has been designed specifically to meet the requirements for a rolling patch installation. RAC Rolling and Standby-First patch installation relies on this methodology. Customers all over the world are using this with success and have done so for many years. Also, our autonomous databases use the technology. It is a mature and proven technology, so I disagree in you when you say that it is overly risky to use.
    I encourage you to give it a try and see for yourself. I’m confident you’ll be surprised.
    Regards,
    Daniel

    Like

  9. Hi Daniel,
    so this means in a SingleInstance environment CDB+PDBs (without RAC or DG) for me to proceed like this:
    Test the patches in Test and Stage systems with switching to new patched Home
    – Patch will be done with switching to new Home and startup the DBs and running datapatch online.
    – Is it recommended to create a GRP before running datapatch ?
    – If datapatch fails rerun it
    – If datapatch fails multiple times -> try to rollback the patch(-es) which fail (s)
    – open SR with information of failing patches
    – all DB changes since patching will not be rolled back, because only the patches will be rolled back with datapatch rollback
    Would this be the recommndation how to proceed ?

    Thanks!
    Best regards, Karlheinz

    Like

  10. Hi,

    That does sound like a viable approach. Setting the GRP is optional. Datapatch can rollback patches – normally – without problems. But I have seen rare issues in the rollback scripts. So, setting a GRP would be icing on the cake – but once in a while might be useful.
    Regards,
    Daniel

    Like

Leave a comment