What is Undo used for?
Before introducing UNDO, let's talk about another thing. We need to apply for many resources in the process of conducting a transaction, and a complex transaction also requires many steps to complete. Then a complex transaction has only two results, either success or failure (which is equivalent to never happening).
A very typical example, bank transfer, actually requires two steps. The first step is to subtract the money in your account, and the second step is to add the money to the transferred account. This is a complete transaction.
If it is executed halfway and your money is reduced but the money from the transferred account is not added, the transaction will be rolled back at this time and rolled back to the original state. That is to say, before transferring money, you need to record the amount on you and the transferred account. This ensures that once a transaction fails, it will be rolled back to the state before the transaction occurred.
In order to ensure the originality and integrity of a transaction, the concept of undo is introduced. Undo is used to record and save data during transaction operations. If an error occurs in the transaction, it can be filled with previous data.
Undo Segment Undo Segment:
From the view above, we can clearly see that we want to delete a The data is modified. Before modifying, put the old image on undo. Then put new image in the table.
If the process fails, we can also take back the old image on undo and put it in its original position, so that it looks like it never happened.
Undo segment is saved in the table space. The size of Undo is fixed, and since it is fixed, it is limited. If there are too many records saved, it will be full and the new recorded data will overwrite the oldest data.
So using a circular disk can express it more vividly. Data is written starting from a position. When a circle is filled, the latest data will overwrite the earliest written data.
What can you do with undo?
Transaction rollback transaction reversal, Transaction recovery transaction recovery. The effect of transaction reversal and transaction recovery is the same. Transaction reversal is something people take the initiative to do. People regret it during the operation, which is equivalent to me pressing ctrl z when writing a document. Transaction recovery is automatically completed by the machine. For example, if Jianpin suddenly loses power during the transaction, the system will automatically roll back after the service is restarted next time.
Read consistency Read and execute. Read consistency is very important for multi-user operations. If you have used version control tools (git\cvs\svn) in multi-person development, you will easily understand the following concepts.
Oracle Read Consistency Concept , this process may take several minutes. During this process, other users made modifications to the data you queried. Here you need to ensure that the results of your query are before they are modified.
Here is a clear concept. The beginning of a transaction is when we execute an (update, modify, delete) statement; at the end of the transaction, a commit action must be executed (execute commit or rollback command) Let’s understand how Oracle ensures read consistency from the flow chart above.
Of course, there will be a special situation, that is, the undo segment is too small, and a maximum of 100 pieces of data can be placed. But 120 pieces of data come in all at once, so the first 20 pieces of data written are replaced by the last 20 pieces of data written. cover. An error will be reported at this time, which is why the data needs to be tuned.
Redo or Undo d. For the purpose of recovery.
For example, if the machine loses power, online redo logs are needed to restore the system to the point of failure after restarting.For example, if the disk is damaged, you need to use archived redo logs and online redo logs areas to recover data.
What is Undo
Redo is to re-implement your operation, while Undo, on the contrary, is to undo the operation you did. Undo is more like the commonly used ctrl z, which undoes the previous step. Redo will also record undo operations.When we insert a piece of data, first the action will be recorded in the redo log, the operation will also be recorded in undo, and the action of undo itself will also be When a piece of data is recorded in the redo log, when a piece of data is inserted, the indexes will change, and the changes in the indexes will also cause a piece of data to be recorded in the redo log. Redo records all relevant information of an operation, so that the scene can be completely reproduced.
It should be noted that in the above chart, both undo and redo are written in the memory. Once the power is turned off, all information will disappear. Only the information written to the disk will not be lost due to power outage.
The redo log information is written to the disk first, because it has the most comprehensive information and can completely guarantee the scene reproduction. We can control redo writing to disk through various mechanisms, such as writing every 3 seconds, or writing redo log files larger than 1MB.
How to configure and use undo ? We can create multiple undo table spaces, but only one undo table space can be in use.
View undo configuration information:
SQL> show parameter undo NAME TYPE VALUE ------------------------------------ ---------------------------------------------------- undo_management string AUTO undo_retention integer 900 undo_tablespace string UNDOTBS1
Undo configuration parameter meaning
-DNDO_MANAGEMENT The management mode of undo is divided into automatic and manual.-UNDO_TABLESPACE is currently being used The undo table used
-UNDO_RETENTION specifies how long the data cannot be overwritten.
AUTO means undo is in automatic management mode.
900 means that the data on undo cannot be overwritten within 900 seconds.
UNDOTBS1 is the undo table space currently in use.
Creating an undo table space is similar to creating a general table space. The command is as follows:
SQL> create undo tablespace myundotbs 2 datafile '/ora10/product/oradata/ora10/myundotbs1.dbf' size 10M; Tablespace created.
View the newly created undo table space
SQL> select tablespace_name,contents from dba_tablespaces; TABLESPACE_NAME CONTENTS ------------------------------------------------------------ ------------------ SYSTEM PERMANENT UNDOTBS1 UNDO //老的undo表空间 SYSAUX PERMANENT TEMP TEMPORARY USERS PERMANENT PAUL PERMANENT MYUNDOTBS UNDO // 新创建的undo表空间 SQL> show parameter undo 再次查看当前使用的表空间 NAME TYPE VALUE ------------------------------------ ---------------------------------------------------- undo_management string AUTO undo_retention integer 900 undo_tablespace string UNDOTBS1
Switch undo table space:
SQL> alter system set undo_tablespace=myundotbs; System altered. SQL> show parameter undo 再次查看当前使用的表空间 NAME TYPE VALUE ------------------------------------ ---------------------------------------------------- undo_management string AUTO undo_retention integer 900 undo_tablespace string MYUNDOTBS //已经切换的了undo表空间
Delete undo table space:
SQL> drop tablespace myundotbs; Tablespace dropped.
After dropping an undo table space, it still exists on the disk. We need to use the rm command to delete the file through the operating system level.
Thinking:
The table space switching and deletion commands are very simple, but here we need to think about the actual switching scenario. When we execute a transaction, half of the transaction execution has not yet been committed. Can we successfully switch the undo table space at this time?
Theoretically, the undo table space is in use and switching is not allowed. But in fact, the undo table space can be switched during use, but if it is deleted immediately after switching, the system will prompt an error. After committing the transaction and then deleting it, the system still prompts an error. Here, the replaced undo tablespace can only be deleted if it is switched to the used state and then to the abandoned state.
Undo tuning. How can we set up undo to work more rationally for us?
The size of the Undo table space:
When we create an undo table space, we specify its size. Once created, this size cannot be changed. It is a waste to set it too large. If it is set too small, for example, if you delete 1 million records, these deleted records will be temporarily stored in the undo table space. If the undo size cannot store 1 million records, problems will occur. .
Undo data storage time:
也就是undo_retention 参数所对应的时间,undo上有数据存放时间与undo大小的密切关系。存放时间越长,需要的表空间越大。就像理发师的数量与理发师的效率的关系一样。理发师效率很高,一秒钟解决一个客户,那么就不需要太多的理发师傅。
Undo表空间的历史信息:
如何合理设置undo表空间的大小和存放时间呢?那么就需要参考历史记录
这个数据每隔10分钟采集一次,结束时间减去开始时间,在这段时间内使用了多少个undo数据块。
计算每秒钟使用数据块的多少?
求最大值: SQL> select max(undoblks / ((end_time-begin_time)*24*3600)) from v$undostat; MAX(UNDOBLKS/((END_TIME-BEGIN_TIME)*24*3600)) --------------------------------------------- 14.15833333 求平均值: SQL> select sum(undoblks)/sum((end_time - begin_time)*24*3600) from v$undostat; SUM(UNDOBLKS)/SUM((END_TIME-BEGIN_TIME)*24*3600) ------------------------------------------------ 4.122282389
The above is the detailed content of oracle undo analysis. For more information, please follow other related articles on the PHP Chinese website!

Oracle is suitable for enterprise-level applications that require high performance and complex queries, and MySQL is suitable for web applications that are rapidly developed and deployed. 1. Oracle supports complex transaction processing and high availability, suitable for financial and large ERP systems. 2.MySQL emphasizes ease of use and open source support, and is widely used in small and medium-sized enterprises and Internet projects.

The differences in user experience between MySQL and Oracle are mainly reflected in: 1. MySQL is simple and easy to use, suitable for quick access and high flexibility scenarios; 2. Oracle has powerful functions, suitable for scenarios that require enterprise-level support. MySQL's open source and free features attract startups and individual developers, while Oracle's complex features and tools meet the needs of 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.

Key features of Oracle software include multi-tenant architecture, advanced analytics and data mining, real-time application clustering (RAC), and automated management and monitoring. 1) A multi-tenant architecture allows for the management of multiple independent databases in one database instance, simplifying management and reducing costs. 2) Advanced analytics and data mining tools such as Oracle Advanced Analytics and OracleDataMining help extract insights from data. 3) Real-time application cluster (RAC) provides high availability and scalability, improving system fault tolerance and performance. 4) Automated management and monitoring tools such as Oracle EnterpriseManager (OEM) to automate daily maintenance tasks and monitor numbers in real time

Oracle has a profound impact in the fields of data management and enterprise applications. Its database is known for its reliability, scalability and security, and is widely used in industries such as finance, medical care and government. Oracle's influence has also expanded to middleware and cloud computing fields such as WebLogicServer and OracleCloudInfrastructure (OCI), providing innovative solutions. Despite the competition in the open source database and cloud computing market, Oracle maintains its leading position through continuous innovation.

Oracle's mission is to "help people see the value of data", and its core values include: 1) Customer first, 2) Integrity, 3) Innovation, and 4) Teamwork. These values guide Oracle's strategic decision-making and business innovation in the market.

Oracle Database is a relational database management system that supports SQL and object relational models to provide data security and high availability. 1. The core functions of Oracle database include data storage, retrieval, security and backup and recovery. 2. Its working principle involves multi-layer storage structure, MVCC mechanism and optimizer. 3. Basic usages include creating tables, inserting and querying data; advanced usages involve stored procedures and triggers. 4. Performance optimization strategies include the use of indexes, optimized SQL statements and memory management.

In addition to database management, Oracle software is also used in JavaEE applications, data grids and high-performance computing. 1. OracleWebLogicServer is used to deploy and manage JavaEE applications. 2. OracleCoherence provides high-performance data storage and caching services. 3. OracleExadata is used for high performance computing. These tools allow Oracle to play a more diversified role in the enterprise IT architecture.


Hot AI Tools

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

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

Undress AI Tool
Undress images for free

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
