search
HomeDatabaseMysql TutorialOracle基础教程之管理还原数据

UNDO 表空间管理 1、对于DML语句来说,只要修改了数据块,Oracle数据库就会将修改前的数据块保留下来,保存在undo segment里面,

UNDO 表空间管理

1、对于DML语句来说,只要修改了数据块,Oracle数据库就会将修改前的数据块保留下来,保存在undo segment里面,而undo segment则保存在undo表空间中

2、undo的管理

自动undo管理(Oracle9i开始)AUM

手工undo管理MUM

9i以后,就建议使用AUM,因此就不再讨论MUM

一条DML语句的执行流程update t set coll=‘A’ where coll=‘B’

1、在shared pool里面进行解析,从而生成执行计划

2、根据执行计划,得出coll=‘B’的记录存放在10号数据文件的54号数据块里面

3、服务器进程首先在buffer cache寻找一个可用的undo数据块(如果一个事物已经提交,那么这个事务曾经使用过的undo数据块就可以被使用),如果没有发现,则到undo表空间里找到一个可用的undo数据块,,并调入到buffer cache。假设获得的undo数据块号为24号,位于11号undo数据文件里

4、将改变前的值,也就是B放入24号undo数据块(buffer cache中)

5、由于undo数据块发生了变化(只要是数据块发生变化,那么就产生重做记录),于是产生重做记录,假设重做记录号是120

6、在buffer cache里面找到54号数据块,如果没有,则从10号数据文件调入

7、将改变后的值,也就是A放入54号数据块

8、由于数据块发生了变化,于是产生重做记录,假设重做记录号是121

9、控制权返回给用户,如果使用SQLPLUS,那么表现为光标返回

10、用户发出commit命令,触发LGWR,将120、121这两个重做记录写入联机重做日志文件中,将54号、24号两个数据块头部所记录的事务状态标记设置为已提交,控制权返回给用户,如果使用SQLPLUS,那么表现为光标返回

11、这个时侯,54号和24号数据块并不一定被DBWr写入数据文件,只有在脏数据块的数量达到一定程度的时候才会被写入

事务提交以后,该事务所使用的undo数据块就可以被覆盖,上面的例子中,第10步用户提交以后,24号undo数据块就可以被覆盖

Undo的作用

1、提供读一执性

2、回滚事务

3、实例恢复

读一致性

一个场景描述

读一致性是相对脏读而言的,表T中有10000条记录,获取所有的记录需要15分钟的时间,当前时间为9点整,用户发出一条select * from T命令,该语句在9:15完成。当用户执行该语句到9:10分的时候,另外一个用户发出了一条删除命令,将最后一条记录删除,并且进行了提交。

到9点15分的时候,用户返回了多少条记录。

如果是9999条,那么就是脏读、如果是10000条,那么就是读一致性。

Oracle不会出现脏读,提供读一致性,而且没有阻塞DML操作

Oracle如何实现读一致性呢?

1、用户在9点发出select语句的时候,服务器进程会记录9点那个时刻的SCN号(SCN号是以时间(timestamp)作为参数的一个函数返回值,调用函数(默认以timestamp为参数)随时可以返回这个时刻的SCN号,可以使用函数在SCN和timestamp之间进行转换),假设该SCN号是SCN9:00,那么SCN9:00一定大于等于记录在所有数据块头部的ITL槽中的SCN号(如果有多个ITL槽,SCN最大的那个)

2、服务器进程扫描T表的时候,会把扫描的数据块头部的ITL槽中的SCN号与SCN9:00进行比较,哪个更大。如果数据块头部的SCN小于SCN9:00,那么说明这个数据块在9:00以后没有更改过,可以直接读取,如果数据块头部的SCN号大于SCN9:00,则说明该数据块在9:00以后更改过,已经不是9:00那个时刻的数据了于是要借助undo块

3、9点10分,用户更改了T表的最后一条记录并提交(无论是否提交,只要是更改了T表,用户就会去读undo数据块),假设被更改的是N号数据块,那么N号数据块头部的ITL槽中记录的SCN被修改为SCN9:10,当服务器进程扫描到这个数据块的时候,发现ITL槽中的SCN9:10大于SCN9:00,说明该数据块在9:00以后被更新了,于是服务器进程到N号块的头部,找到SCN9:10所在ITL槽,由于ITL槽记录了对应的undo块的地址,于是服务器进程找到undo数据块,结合undo数据块给用户提供读一致性。

更多Oracle相关信息见Oracle 专题页面 ?tid=12

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are some tools you can use to monitor MySQL performance?What are some tools you can use to monitor MySQL performance?Apr 23, 2025 am 12:21 AM

How to effectively monitor MySQL performance? Use tools such as mysqladmin, SHOWGLOBALSTATUS, PerconaMonitoring and Management (PMM), and MySQL EnterpriseMonitor. 1. Use mysqladmin to view the number of connections. 2. Use SHOWGLOBALSTATUS to view the query number. 3.PMM provides detailed performance data and graphical interface. 4.MySQLEnterpriseMonitor provides rich monitoring functions and alarm mechanisms.

How does MySQL differ from SQL Server?How does MySQL differ from SQL Server?Apr 23, 2025 am 12:20 AM

The difference between MySQL and SQLServer is: 1) MySQL is open source and suitable for web and embedded systems, 2) SQLServer is a commercial product of Microsoft and is suitable for enterprise-level applications. There are significant differences between the two in storage engine, performance optimization and application scenarios. When choosing, you need to consider project size and future scalability.

In what scenarios might you choose SQL Server over MySQL?In what scenarios might you choose SQL Server over MySQL?Apr 23, 2025 am 12:20 AM

In enterprise-level application scenarios that require high availability, advanced security and good integration, SQLServer should be chosen instead of MySQL. 1) SQLServer provides enterprise-level features such as high availability and advanced security. 2) It is closely integrated with Microsoft ecosystems such as VisualStudio and PowerBI. 3) SQLServer performs excellent in performance optimization and supports memory-optimized tables and column storage indexes.

How does MySQL handle character sets and collations?How does MySQL handle character sets and collations?Apr 23, 2025 am 12:19 AM

MySQLmanagescharactersetsandcollationsbyusingUTF-8asthedefault,allowingconfigurationatdatabase,table,andcolumnlevels,andrequiringcarefulalignmenttoavoidmismatches.1)Setdefaultcharactersetandcollationforadatabase.2)Configurecharactersetandcollationfor

What are triggers in MySQL?What are triggers in MySQL?Apr 23, 2025 am 12:11 AM

A MySQL trigger is an automatically executed stored procedure associated with a table that is used to perform a series of operations when a specific data operation is performed. 1) Trigger definition and function: used for data verification, logging, etc. 2) Working principle: It is divided into BEFORE and AFTER, and supports row-level triggering. 3) Example of use: Can be used to record salary changes or update inventory. 4) Debugging skills: Use SHOWTRIGGERS and SHOWCREATETRIGGER commands. 5) Performance optimization: Avoid complex operations, use indexes, and manage transactions.

How do you create and manage user accounts in MySQL?How do you create and manage user accounts in MySQL?Apr 22, 2025 pm 06:05 PM

The steps to create and manage user accounts in MySQL are as follows: 1. Create a user: Use CREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password'; 2. Assign permissions: Use GRANTSELECT, INSERT, UPDATEONmydatabase.TO'newuser'@'localhost'; 3. Fix permission error: Use REVOKEALLPRIVILEGESONmydatabase.FROM'newuser'@'localhost'; then reassign permissions; 4. Optimization permissions: Use SHOWGRA

How does MySQL differ from Oracle?How does MySQL differ from Oracle?Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

What are the disadvantages of using MySQL compared to other relational databases?What are the disadvantages of using MySQL compared to other relational databases?Apr 22, 2025 pm 05:49 PM

The disadvantages of MySQL compared to other relational databases include: 1. Performance issues: You may encounter bottlenecks when processing large-scale data, and PostgreSQL performs better in complex queries and big data processing. 2. Scalability: The horizontal scaling ability is not as good as Google Spanner and Amazon Aurora. 3. Functional limitations: Not as good as PostgreSQL and Oracle in advanced functions, some functions require more custom code and maintenance.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.