UNDO表空间与Undo的认识
undo的三大作用:1.提供一致性读。2.回滚事务。3.实例恢复 查看表空间是属于temporary,undo还是permanent? select tablespace_name,contents,status from dba_tablespaces where tablespace_name like '%UNDO%'; 1.管理Undo表空间--创建新的Undo表空间CREATE
undo的三大作用: 1.提供一致性读。2.回滚事务。3.实例恢复 查看表空间是属于temporary,undo还是permanent? select tablespace_name,contents,status from dba_tablespaces where tablespace_name like '%UNDO%';1.管理Undo表空间 --创建新的Undo表空间 CREATE UNDO TABLESPACE UNDOTBS2 datafile '/paic/g2bh8060/dev/xqd/oradata/hd02ntlf/undotbs2_01.dbf' size 500m autoextend on RETENTION NOGUARANTEE; 默认是NOGUARANTEE --为Undo表空间增加文件 alter tablespace undotbs1 add datafile '/u01/oracle/undo01.dbf' size 500m autoextend on; alter tablespace undotbs1 add datafile '+DATA_MIDG' size 500m autoextend on; 查询与更改undo表空间是否retention guarantee select tablespace_name,RETENTION from dba_tablespaces where tablespace_name like '%UNDO%'; ALTER DATABASE UNDOTBS01 RETENTION GUARANTEE|NOGUARANTEE; 更改系统默认表空间 show parameter undo_tablespace alter system set undo_tablespace=undotbs2; undo表空间删除 drop tablespace undotbs1 INCLUDING CONTENTS AND DATAFILES; undo表空间更名 alter tablespace undotbs2 rename to undotbs1; 重建undo表空间 1.因为延迟段创建的原因,可以先将参数取消; show parameter segment alter system set deferred_segment_creation=false; 2.创建undotemp表空间 3.alter system set undo_tablespace=undotemp;(如果延迟段创建特性启用了,会提示表空间不存在) 4.旧的undotbs1 drop掉。 旧的表空间现在是pending offline状态,等待offline,要等其上的事务都结束后才能真正offline。 ORA-30013: undo tablespace 'UNDOTBS1' is currently in use 5.新的rename成旧的。
2.认识UNDO undo相关参数: undo_management AUTO --9i以后我们undo_management都用auto undo_tablespace UNDOTBS2 --可以动态指定系统undo表空间 undo_retention 900 --单位秒,默认900 undo_retention是针对select操作的,比如闪回查询,我们一般希望能闪回查询3小时内的数据。 事务中的undo块都是active的,事务结束后的块是inactive的,inactive的undo块在过了undo_retention 指定的时间后,就会变成expired。 比如DB最长的查询也在5分钟内,那我undo_retention只要设成300,那么这个select会遭遇01555快照太旧的可能性就比较小,但不保证。 ALTER SYSTEM SET undo_retention=10800 SCOPE=BOTH; 我们通过 undo_management 参数来控制使用哪种方式,如果设为auto,就使用UNDO 表空间,这时必须要指定一个UNDO 表空间。 如果设为manual,系统启动后使用rollback segment方式存储undo信息。如果系统没有指定undo_management,那么系统默认以manual方式启动,即使设置了auto方式的参数,这些参数将被忽略。 假如数据库中用RETENTIONGUARANTEE子句配置了保证保留撤销。如果撤销表空间太小不能满足使用它的所有活动事务,那么会发生以下情况: 1、如果撤销表空间用完85%,Oracle将发布一个自动表空间警告 2、当撤销表空间用完97%时,Oracle将发布一个自动表空间严重警告 3、所有DML语句将不允许,并且会接收到一个空间超出错误 4、DDL语句允许继续执行 所以PA数据库undo表空间都是NOGUARANTEE,无论生产还是测试库。 RETENTIONGUARANTEE的情况下,undo_retention秒数内的undo都不能被覆盖,所以如果expired与freed的块几乎没了,Undo表空间也不能自动扩展,就会报上面的错误。 undo_retention参数的作用,在RETENTIONGUARANTEE的情况下,可以作为是否保证undo块不被覆盖的分界线,而在没有设retention的情况下,例如PA的情况,就是作为是否被优先覆盖的分界线。所以此处只有两个优先级,在线的任何一边,都是随机随意地没优先级地覆盖的。 Undo表空间中已经分配给表空间的extend大小。 @tsfree 即 select d.tablespace_name, space "SUM_SPACE(M)", blocks sum_blocks, space - nvl(free_space, 0) "USED_SPACE(M)", round((1 - nvl(free_space, 0) / space) * 100, 2) "USED_RATE(%)", free_space "FREE_SPACE(M)" from (select tablespace_name, round(sum(bytes) / (1024 * 1024), 2) space, sum(blocks) blocks from dba_data_files group by tablespace_name) d, (select tablespace_name, round(sum(bytes) / (1024 * 1024), 2) free_space from dba_free_space group by tablespace_name) f where d.tablespace_name = f.tablespace_name(+) order by 1; 其中USED_SPACE(M)里面,都是已经分配给表空间使用的。里面有4钟状态的undo块。 undo块存在的四种状态 select tablespace_name,status,sum(bytes)/1024/1024 mb from dba_undo_extents group by tablespace_name,status; active:表示正在使用该undo的事务还没有commit或rollback UNEXPIRED(inactive):表示该undo上没有活动的事务,该状态的undo可以被其他事务覆盖。 expired:表示该undo块持续inactive的时间超过undo_retention所指定的时间 freed:表示该undo块内容是空的,从来没有被使用过。 一个事务申请Undo表空间: 1.如果undo表空间是可以自动扩展的,首先自动扩展。 2.如果没得扩展了,就找free的区用。 3.没有free的区了,就找expired的undo区用。 4.没有expired的,就找unexpired的,此时这些区还没过undo_retention时间,所以会导致闪回查询无法保证使用咯。 5.还是没有的话,报错,active的区肯定不会被使用的。 Retention Guarantee模式下,一个事务申请undo表空间只走上述的第1,2,3点。3点走完后也申请不到Undo空间就报错。也就是说undo_retention时间内的undo块一定不会被覆盖。
往数据库中做导数操作,批量DML而又长时间不能commit的操作的时候,要给Undo表空间加几个文件,并且开自动扩展,保持监控

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

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)

Hot Topics

When we browse the win11 settings, we may find that there is a touch keyboard setting, but our screen does not support touch screen, so what is the use of this win11 touch keyboard? In fact, it is an on-screen keyboard. The functions of the win11 touch keyboard: 1. The win11 touch keyboard is actually an "on-screen keyboard" 2. It can simulate a real keyboard and use the keyboard by clicking. 3. When we don’t have a keyboard or the keyboard is broken, we can use it to type. 4. Win11 provides a wealth of personalized options for the touch keyboard. 5. It includes various colors and themes, allowing users to freely switch their favorite styles. 6. Click the "gear" in the upper left corner to modify the keyboard layout, handwriting and other input methods.

Analysis of the role and principle of nohup In Unix and Unix-like operating systems, nohup is a commonly used command that is used to run commands in the background. Even if the user exits the current session or closes the terminal window, the command can still continue to be executed. In this article, we will analyze the function and principle of the nohup command in detail. 1. The role of nohup: Running commands in the background: Through the nohup command, we can let long-running commands continue to execute in the background without being affected by the user exiting the terminal session. This needs to be run

What does a Bluetooth adapter do? With the continuous development of science and technology, wireless communication technology has also been rapidly developed and popularized. Among them, Bluetooth technology, as a short-distance wireless communication technology, is widely used in data transmission and connection between various devices. The Bluetooth adapter plays a vital role as an important device that supports Bluetooth communication. A Bluetooth adapter is a device that can turn a non-Bluetooth device into a device that supports Bluetooth communication. It realizes wireless connection and data transmission between devices by converting wireless signals into Bluetooth signals. Bluetooth adapter

Swap space plays an important role in Linux systems, especially when the system is low on memory. It acts as a backup memory storage space that helps the system run smoothly and maintain stability even under high load. This article provides you with a detailed guide to adding swap space on Ubuntu 22.04LTS to ensure that your system performance is optimized and can handle various workloads. Understanding Swap Space Swap space provides virtual memory that is used to supplement the system's physical RAM. When the system is low on RAM, the kernel swaps data to disk to prevent out-of-memory and system crashes. Linux systems commonly use swap space to handle this situation. Run multiple memory-intensive applications simultaneously to process very large files or data

Understand the role and usage of LinuxDTS In the development of embedded Linux systems, Device Tree (DeviceTree, DTS for short) is a data structure that describes hardware devices and their connection relationships and attributes in the system. The device tree enables the Linux kernel to run flexibly on different hardware platforms without modifying the kernel. In this article, the function and usage of LinuxDTS will be introduced, and specific code examples will be provided to help readers better understand. 1. The role of device tree device tree

The importance and role of the define function in PHP 1. Basic introduction to the define function In PHP, the define function is a key function used to define constants. Constants will not change their values during the running of the program. Constants defined using the define function can be accessed throughout the script and are global. 2. The syntax of define function The basic syntax of define function is as follows: define("constant name","constant value&qu

Basic concepts and functions of Gunicorn Gunicorn is a tool for running WSGI servers in Python web applications. WSGI (Web Server Gateway Interface) is a specification defined by the Python language and is used to define the communication interface between web servers and web applications. Gunicorn enables Python web applications to be deployed and run in production environments by implementing the WSGI specification. The function of Gunicorn is to

PHP is a server-side scripting language widely used in web development. Its main function is to generate dynamic web content. When combined with HTML, it can create rich and colorful web pages. PHP is powerful. It can perform various database operations, file operations, form processing and other tasks, providing powerful interactivity and functionality for websites. In the following articles, we will further explore the role and functions of PHP, with detailed code examples. First, let’s take a look at a common use of PHP: dynamic web page generation: P
