


How does Oracle manage transaction commits and rollbacks using redo and undo mechanisms?
Jul 08, 2025 am 12:16 AMOracle ensures transaction durability and consistency using redo for commits and undo for rollbacks. During a commit, Oracle generates a commit record in the redo log buffer, marks changes as permanent in redo logs, and updates the SCN to reflect the current database state. For rollbacks, Oracle uses undo data to revert changes by reconstructing original values and maintaining read consistency. Redo records changes for recovery, stored in online redo logs, while undo stores how to reverse changes for rollback and consistency, kept in undo tablespaces. Key practical considerations include: 1) frequent commits increase redo but reduce undo usage; 2) large transactions may trigger "snapshot too old" errors if undo retention is insufficient; 3) monitor redo via V$SYSSTAT or trace files; 4) ensure adequate undo tablespace size and retention for long queries; and 5) check wait events like log file sync or enq: TX – contention when troubleshooting performance issues.
Oracle handles transaction commits and rollbacks using two core mechanisms: redo and undo. These work together to ensure data consistency, durability, and the ability to recover from failures.
What happens during a commit
When you issue a COMMIT
, Oracle doesn’t immediately write all changes to the data files. Instead, it does a few key things:
- It generates a commit record in the redo log buffer.
- All the changes made by the transaction up to that point are marked as permanent in the redo logs.
- The System Change Number (SCN) is updated to reflect the current point in time of the database.
So even if the actual data blocks haven’t been written to disk yet, the fact that the transaction committed is recorded in the redo log. That’s why Oracle can guarantee durability — once a commit returns successfully, the change is safe, even in case of a crash.
How rollback works with undo
If a transaction is rolled back (either explicitly or due to an error), Oracle uses undo data to revert the changes.
Each change made by a transaction is first logged in the undo tablespace before the actual data is modified. This allows Oracle to:
- Reconstruct the original values of changed data.
- Maintain read consistency for other sessions that might be querying the same data concurrently.
For example, if Session A updates a row and Session B queries it before the commit, Session B sees the original version of the row using the undo data.
Rollback essentially plays back this undo information in reverse, restoring the database to its state before the transaction began.
Redo vs Undo – Key differences
It's easy to mix up redo and undo, but here's how they differ in function:
-
Redo:
- Records what changes were made to the database.
- Used for recovery — instance recovery, media recovery, etc.
- Stored in online redo log files.
- Every change goes through the redo log buffer before being flushed to disk.
-
Undo:
- Records how to undo a change.
- Used for rollbacks and maintaining read consistency.
- Stored in undo tablespaces.
- Also used by Oracle for flashback features and consistent reads.
In short:
Redo is about recording changes for recovery; undo is about preserving old values for rollback and consistency.
Practical implications and tuning considerations
Understanding these mechanisms helps when dealing with performance or recovery issues.
Here are a few practical points:
- Frequent commits reduce the amount of undo needed but increase redo generation. So, in bulk operations, batch your commits wisely.
- Large transactions may cause "snapshot too old" errors if undo retention isn't sufficient.
- You can monitor redo generation via views like
V$SYSSTAT
(redo size
) or trace files. - For long-running reports or queries, make sure your undo tablespace is large enough and configured with appropriate retention.
If you're troubleshooting performance issues related to redo or undo, checking wait events like log file sync
(for redo) or enq: TX – contention
(for undo) can help pinpoint bottlenecks.
That’s how Oracle ensures reliable transaction handling under the hood. Not something you see every day, but good to understand when tuning or debugging database behavior.
The above is the detailed content of How does Oracle manage transaction commits and rollbacks using redo and undo mechanisms?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MongoDB is suitable for unstructured data and high scalability requirements, while Oracle is suitable for scenarios that require strict data consistency. 1.MongoDB flexibly stores data in different structures, suitable for social media and the Internet of Things. 2. Oracle structured data model ensures data integrity and is suitable for financial transactions. 3.MongoDB scales horizontally through shards, and Oracle scales vertically through RAC. 4.MongoDB has low maintenance costs, while Oracle has high maintenance costs but is fully supported.

The main difference between MySQL and Oracle is licenses, features, and advantages. 1. License: MySQL provides a GPL license for free use, and Oracle adopts a proprietary license, which is expensive. 2. Function: MySQL has simple functions and is suitable for web applications and small and medium-sized enterprises. Oracle has powerful functions and is suitable for large-scale data and complex businesses. 3. Advantages: MySQL is open source free, suitable for startups, and Oracle is reliable in performance, suitable for large enterprises.

The difference between MySQL and Oracle in performance and scalability is: 1. MySQL performs better on small to medium-sized data sets, suitable for fast scaling and efficient reading and writing; 2. Oracle has more advantages in handling large data sets and complex queries, suitable for high availability and complex business logic. MySQL extends through master-slave replication and sharding technologies, while Oracle achieves high availability and scalability through RAC.

MySQL uses GPL and commercial licenses for small and open source projects; Oracle uses commercial licenses for enterprises that require high performance. MySQL's GPL license is free, and commercial licenses require payment; Oracle license fees are calculated based on processors or users, and the cost is relatively high.

In different application scenarios, choosing MongoDB or Oracle depends on specific needs: 1) If you need to process a large amount of unstructured data and do not have high requirements for data consistency, choose MongoDB; 2) If you need strict data consistency and complex queries, choose Oracle.

The key to learning Java without taking detours is: 1. Understand core concepts and grammar; 2. Practice more; 3. Understand memory management and garbage collection; 4. Join online communities; 5. Read other people’s code; 6. Understand common libraries and frameworks; 7. Learn to deal with common mistakes; 8. Make a learning plan and proceed step by step. These methods can help you master Java programming efficiently.
