Oracle11g温习-第十一章:管理undo

Posted ORACLE-fans

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle11g温习-第十一章:管理undo相关的知识,希望对你有一定的参考价值。

2013年4月27日 星期六

10:40

 

1undo tablespace 功能

 undo tablespace 功能:用来存放从datafiles 读出的数据块旧的镜像

 

       

            1)   回滚事务:rollback

            2)   读一致性:正在做DML操作的数据块,在没有提交前,其他用户不能读,其他用户读undo里面的数据块信息

            3)   事务的恢复:instance recover   (undo -------->rollback)

            4)   倒序查询flashback queryflashback table

         】

2undo 的管理模式

1)   manaual 手工:roll segment

2)   auto  自动:      undo tablespace ( init parameter :undo_management  = auto) ,自动创建undo段

3undo 表空间管理

 1)【建立新的undo表空间(处于active状态的undo tablespace 不能offline 和 drop),可以建立多个undo表空间,但一个时刻只有一个处于active 】

 

SYS @ prod > create undo tablespace        undotbs2     datafile ‘/u01/app/oracle/oradata/orcl/undotbs02.dbf‘       

size 100m         autoextend on next     10m maxsize 500m;                                       创建自动扩展的undo表空间

   

Tablespace created.

 

 SYS @ prod >  select tablespace_name,status,contents from dba_tablespaces;

 

TABLESPACE_NAME                STATUS    CONTENTS

------------------------------ --------- ---------

SYSTEM                                    ONLINE    PERMANENT

UNDOTBS                                ONLINE    UNDO

SYSAUX                                     ONLINE    PERMANENT

TEMP                                        ONLINE    TEMPORARY

USERS                                       ONLINE    PERMANENT

UNDOTBS02                            ONLINE    UNDO 

 

    2)查看当前正在使用的undo tablespace

     

 SYS @ prod > show parameter undo

 

NAME                                          TYPE                              VALUE

------------------------------------ --------------------------------- ------------------------------

undo_management                  string                            AUTO

undo_retention                         integer                           900

undo_tablespace                      string                            UNDOTBS

 

    

   3)切换undo表空间

 

 SYS @ prod >alter system set undo_tablespace=undotbs2;   

 

System altered.

 

 SYS @ prod > show parameter undo

 

NAME                                 TYPE                              VALUE

------------------------------------ --------------------------------- ------------------------------

undo_management                      string                            AUTO

undo_retention                       integer                           900

undo_tablespace                      string                            UNDOTBS02

 

    4)删除undo tablespace

  

 SYS @ prod >drop tablespace undotbs  including contents and  datafiles;  

 

Tablespace dropped.

 

5) undo_retention 参数

SYS @ prod > show parameter undo;

 

NAME                                        TYPE                              VALUE

------------------------------------ --------------------------------- ------------------------------

undo_management                string                            AUTO

undo_retention                       integer                           900

undo_tablespace                     string                            UNDOTBS

 

——undo_retention   设置当事务提交后,undo 数据块在undo tablespace空间未使用完之前的的保留时间】  

 

SYS @ prod > alter system set undo_retention=600;

SYS @ prod > show parameter undo

 

NAME                                 TYPE                              VALUE

------------------------------------ --------------------------------- ------------------------------

undo_management                   string                            AUTO

undo_retention                       integer                           600

undo_tablespace                      string                            UNDOTBS

 

SYS @ prod > Alter tablespace undotbs1 retention  guarantee;【保证在retention 期间不允许被覆盖】

SYS @ prod >  Alter tablespace undotbs1 retention noguarantee;【想禁止undo表空间retention guarantee

 

 

 6)undo 表空间的大小

          1)   undo_retention

         2)   undo block /per second 

         3)   UNDO BLOCK SIZE

4undo 信息的查询

       1) v$session 【查看用户建立的session】

       2) v$transaction  【当前的事务】

       3) v$rollname  【回滚段的名称】

       4) v$rollstat 【回滚段的状态】

      

           SSYS @ prod >   desc  v$session;            

 

 

SYS @ prod > select username,sid,serial# from v$session   where username is not null;

 

USERNAME                       SID       SERIAL#

------------------------------ ---------- ----------

SCOTT                                 141          4

SYS                                       159          3

 

            SYS @ prod > desc  v$transaction ;

 

 Name                                      Null?    Type

 ----------------------------------------- -------- ----------------------------

 ADDR                                               RAW(4)                              事务处理状态对象的地址

 XIDUSN                                             NUMBER                         ——xidusn :undo segment 的id   撤消段的号

 XIDSLOT                                            NUMBER                         ——xidslot:事务槽的id    插曹号

 XIDSQN                                             NUMBER                        序列号

 UBAFIL                                             NUMBER                         撤消块地址(UBA)的文件号

 UBABLK                                             NUMBER                        UBA 块号

 UBASQN                                             NUMBER                      UBA 序列号

 UBAREC                                             NUMBER                       UBA 记录号

 STATUS                                             VARCHAR2(16)              状态号

 START_TIME                                         VARCHAR2(20)         起始时间(挂钟)

 START_SCNB                                         NUMBER                   起始系统更改号(SCN)的基点

 START_SCNW                                         NUMBER                  起始SCN 包

 START_UEXT                                         NUMBER                    起始区号

 START_UBAFIL                                       NUMBER                  起始UBA 文件号

 START_UBABLK                                       NUMBER                起始UBA 块号

 START_UBASQN                                       NUMBER               起始UBA 序列号

 START_UBAREC                                       NUMBER               起始记录号

 SES_ADDR                                           RAW(4)                               ——SES_ADDR  当前会话的地址

FLAG                                               NUMBER                              标志位

 SPACE                                              VARCHAR2(3)                    如果为空间事务处理,则为Yes

 RECURSIVE                                          VARCHAR2(3)               如果为递归事务处理,则为Yes

 NOUNDO                                             VARCHAR2(3)                如果为撤消事务处理,则为Yes

 PTX                                                VARCHAR2(3)                        如果为并行事务处理,则为Yes,否则设为No

NAME                                               VARCHAR2(256)

 PRV_XIDUSN                                         NUMBER                      上一个事务处理的撤消段的号

 PRV_XIDSLT                                         NUMBER                          上一个事务处理的插槽号

 PRV_XIDSQN                                         NUMBER                          上一个事务处理的序列号

 PTX_XIDUSN                                         NUMBER                          父级XID 的回退段号

 PTX_XIDSLT                                         NUMBER                          父级XID 的插曹号

 PTX_XIDSQN                                         NUMBER                         父级XID 的序列号

 DSCN-B                                             NUMBER                             独立的SCN 基点

 DSCN-W                                             NUMBER                            独立的SCN 包

 USED_UBLK                                          NUMBER                         已用的撤消块数量

 USED_UREC                                          NUMBER                         已用的撤消记录数量

 LOG_IO                                             NUMBER                                逻辑I/O

 PHY_IO                                             NUMBER                                物理I/O

 CR_GET                                             NUMBER                                一致性获取

 CR_CHANGE                                          NUMBER                         一致性更改

 START_DATE                                         DATE

 DSCN_BASE                                          NUMBER

 DSCN_WRAP                                          NUMBER

 START_SCN                                          NUMBER

 DEPENDENT_SCN                                      NUMBER

 XID                                                      RAW(8)

 PRV_XID                                            RAW(8)

 PTX_XID                                            RAW(8)

                                                          

SYS @ prod > select a.SID,a.SERIAL#,a.USERNAME,b.xidusn,xidslot,b.ubablk,b.status,b.name from v$session a, v$transaction  b    where a.saddr=b.ses_addr;

                                                                                                                     

 

        SID    SERIAL#       USERNAME                 XIDUSN    XIDSLOT     UBABLK    STATUS           NAME

---------- ---------- -------------------- ---------- ---------- ---------- ---------------- ----------

       144            7               SCOTT                             15            26                76          ACTIVE

 

                                                  

     

 

SYS @ prod > desc  v$rollname;    【查看当前的回滚段】

 

——【默认system有一个undo segment,undo tablespace 会被分配10个undo segment】

 

SYS @ prod > select * from v$rollname;                                                                                                  

 

       USN NAME

---------- ----------

         0 SYSTEM

        11 _SYSSMU11$

        12 _SYSSMU12$

        13 _SYSSMU13$

        14 _SYSSMU14$

        15 _SYSSMU15$

        16 _SYSSMU16$

        17 _SYSSMU17$

        18 _SYSSMU18$

        19 _SYSSMU19$

        20 _SYSSMU20$

                                                                                     

SYS @ prod > select usn,extents,writes,xacts,status from v$rollstat;      【查看回滚段的状态

 

       USN    EXTENTS     WRITES      XACTS STATUS

---------- ---------- ---------- ---------- ---------------

         0          6       5560          0 ONLINE

        11         10     529954          0 ONLINE

        12         17    1344804          0 ONLINE

        13         16     800720          0 ONLINE

        14         27   11447082          1 ONLINE

        15         17    1033468          0 ONLINE

        16          6     307764          0 ONLINE

        17         15     734590          0 ONLINE

        18          8     398340          0 ONLINE

        19         16     785134          0 ONLINE

        20          8     407692          0 ONLINE 

 

 SYS @ prod > select a.sid,  a.serial#,  a.username,  b.xidusn,  xidslot,  b.ubablk,  b.status,  c.usn,  c.name,   d.extents,   d.writes,    d.xacts

               from v$session a,v$transaction b,v$rollname c ,v$rollstat d

             where a.saddr=b.ses_addr and b.xidusn=c.usn and c.usn=d.usn

 

                                                                                                                                

 

       SID        SERIAL#   USERNAME     XIDUSN    XIDSLOT     UBABLK     STATUS         USN     NAME            EXTENTS     WRITES          XACTS

---------- ---------- ------ ---------- ---------- ---------- ------- ---------- ---------- ---------- ---------- ------------ ---------- ---------- ------------ ----------

       147         54            SCOTT                14                22              2595         ACTIVE          14    _SYSSMU14$         27           11447082          

                                          

【查看undo segment 数据块状态dba_undo_EXTENTS)】

 

SYS @ prod > insert into t01 values (6) ;                                                                                               

 

SYS @ prod > insert into t01 values (7) ;                                                                                               

 

SYS @ prod > create table emp1 as select * from scott.emp;                                                                              

 

SYS @ prod > insert into emp1 select * from emp1;                                                                                      

 

SYS @ prod > select segment_name,tablespace_name,extent_id,file_id ,bytes/1024 ,status from dba_undo_extents                           

    where status like ‘%ACTIVE%‘;                                                           查看数据库中各个undo段的状态】                                                                                     

 

SEGMENT_NAME                   TABLESPACE_NAME                 EXTENT_ID    FILE_ID     BYTES/1024 STATUS

------------------------------ ------------------------------ ---------- ---------- ---------- ----------- ---------- ---------- ----------

_SYSSMU18$                              UNDO_TBS                                    2                     7                 64                ACTIVE

_SYSSMU15$                              UNDO_TBS                                    0                     7                 64                 ACTIVE

 

SYS @ prod > COMMIT;                                                                                                                   

 

Commit complete.

 

SYS @ prod > /                                                                                                                         

 

SEGMENT_NAME                   TABLESPACE_NAME                 EXTENT_ID    FILE_ID BYTES/1024 STATUS

------------------------------ ------------------------------ ---------- ---------- ---------- ----------

_SYSSMU15$                     UNDO_TBS                                0          7         64 ACTIVE

 

 

【查看undo tablespace 统计信息v$undostat;】

 

SYS @ prod > select BEGIN_TIME,end_time,undotsn,undoblks,ACTIVEBLKS,EXPIREDBLKS,MAXQUERYID from v$undostat;                             

 

BEGIN_TIME          END_TIME               UNDOTSN   UNDOBLKS ACTIVEBLKS EXPIREDBLKS MAXQUERYID

------------------- ------------------- ---------- ---------- ---------- ----------- -------------

2011-08-08 10:22:35 2011-08-08 10:23:20          8          0        160         760

2011-08-08 10:12:35 2011-08-08 10:22:35          8          6        160         760

2011-08-08 10:02:35 2011-08-08 10:12:35          8        589        160           8

2011-08-08 09:52:35 2011-08-08 10:02:35          8        179        160           8

2011-08-08 09:42:35 2011-08-08 09:52:35          8         19        160           0

2011-08-08 09:32:35 2011-08-08 09:42:35          1          7        160        2840

2011-08-08 09:22:35 2011-08-08 09:32:35          1          2        160        2848

2011-08-08 09:12:35 2011-08-08 09:22:35          1          0          0           0

2011-08-08 09:02:35 2011-08-08 09:12:35          1          3          0           0

 

SYS @ prod > select segment_name,tablespace_name ,segment_id,file_id ,status from dba_rollback_segs;                                    

 

SEGMENT_NAME                   TABLESPACE_NAME                SEGMENT_ID    FILE_ID STATUS

------------------------------ ------------------------------ ---------- ---------- ----------------

SYSTEM                         SYSTEM                                  0          1 ONLINE

_SYSSMU1$                      RTBS                                    1          2 ONLINE

_SYSSMU2$                      RTBS                                    2          2 ONLINE

_SYSSMU3$                      RTBS                                    3          2 ONLINE

_SYSSMU4$                      RTBS                                    4          2 ONLINE

_SYSSMU5$                      RTBS                                    5          2 ONLINE

_SYSSMU6$                      RTBS                                    6          2 ONLINE

_SYSSMU7$                      RTBS                                    7          2 ONLINE

_SYSSMU8$                      RTBS                                    8          2 ONLINE

_SYSSMU9$                      RTBS                                    9          2 ONLINE

_SYSSMU10$                     RTBS                                   10        2 ONLINE

 






以上是关于Oracle11g温习-第十一章:管理undo的主要内容,如果未能解决你的问题,请参考以下文章

Oracle11g温习-第十八章:role管理

Oracle11g温习-第十九章:审计(audit)

第十一章 SpringBoot事物管理器

第十一章 linux磁盘管理

第十一章:使用智能指针管理对象资源

构建之法阅读笔记08-第十一章