• Oracle Undo和Redo的关系,区别及相关查询


    redo->每次操作都先记录到redo日志中,当出现实例故障(像断电),导致数据未能更新到数据文件,则数据库重启时须redo,重新把数据更新到数据文件
    undo->记录更改前的一份copy,但你系统rollback时,把这份copy重新覆盖到原来的数据

    redo->记录所有操作,用于恢复(redo records all the database transaction used for recovery)
    undo->记录所有的前印象,用于回滚(undo is used to store uncommited data infor used for rollback)

    redo->已递交的事务,实例恢复时要写到数据文件去的
    undo->未递交的事务.

    redo的原因是:每次commit时,将数据的修改立即写到online redo中,但是并不一定同时将该数据的修改写到数据文件中。因为该数据已经提交,但是只存在联机日志文件中,所以在恢复时需要将数据从联机日志文件中找出来,重新应用一下,使已经更改数据在数据文件中也改过来!

    undo的原因是:在oracle正常运行时,为了提高效率,假如用户还没有commit,但是空闲内存不多时,会由DBWR进程将脏块写入到数据文件中,以便腾出宝贵的内存供其它进程使用。这就是需要UNDO的原因。因为还没有发出commit语句,但是oracle的dbwr进程已经将没有提交的数据写到数据文件中去了。

    Undo存在的意义就是为了读一致性,回滚,让数据库知道它过去的状态

    读一致性的具体步骤

    1、确认读取时间的SCN号

    2、搜索所有关联此表、行的数据块,要求数据块ILT事务槽的SCN号要小于读取时刻的SCN号。

    3、如果搜索到小于读取时刻的SCN号,直接读取

    4、如果全部没有小于读取时刻的SCN号,则根据数据块内ILT事务槽记录的undo信息,查找改变之前的数据。如果SCN号还是大于读取时刻,那么通过递归读取undo块所有关联这一事务的数据块,直至找到比读取时刻SCN号小undo块的信息,找到后进行读取。

    5、如果没有比读取时刻的SCN号小的undo信息,那就会报经典错误ORA-1555 snapshoot too old(快照过旧),这样是为了避免幻影读、脏读等现象,保证读一致性的绝对特性

    Redo(在线重做日志)存在的意义就是为了做恢复用的,让数据库在崩溃后才能恢复如初,不丢数据

    redo做恢复需要依靠undo先还原,在恢复

    1.查看当前日志组成员

    SQL> select member from v$logfile;

    2.查看当前日志组状态

    SQL> select group#,members,bytes/1024/1024,status from v$log;

    横纵向对比单位小时内重做日志组的切换次数SQL语句

    SELECT 
    TO_CHAR(FIRST_TIME,'YYYY-MM-DD') DAY,
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'00',1,0)),'99') "00",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'01',1,0)),'99') "01",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'02',1,0)),'99') "02",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'03',1,0)),'99') "03",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'04',1,0)),'99') "04",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'05',1,0)),'99') "05",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'06',1,0)),'99') "06",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'07',1,0)),'99') "07",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'08',1,0)),'99') "0",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'09',1,0)),'99') "09",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'10',1,0)),'99') "10",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'11',1,0)),'99') "11",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'12',1,0)),'99') "12",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'13',1,0)),'99') "13",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'14',1,0)),'99') "14",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'15',1,0)),'99') "15",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'16',1,0)),'99') "16",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'17',1,0)),'99') "17",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'18',1,0)),'99') "18",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'19',1,0)),'99') "19",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'20',1,0)),'99') "20",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'21',1,0)),'99') "21",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'22',1,0)),'99') "22",
    TO_CHAR(SUM(DECODE(TO_CHAR(FIRST_TIME,'HH24'),'23',1,0)),'99') "23"
    FROM
    V$LOG_HISTORY
    GROUP BY 
    TO_CHAR(FIRST_TIME,'YYYY-MM-DD') 
    ORDER BY 1 DESC;
  • 相关阅读:
    Codeforces 868A Bark to Unlock
    poj 3744 Scout (Another) YYF I
    Codeforces 526F Pudding Monsters
    Codeforces 789D Weird journey
    Codeforces 827E Rusty String
    Codeforces 841D Leha and another game about graph
    bzoj 3560 DZY Loves Math V
    Codeforces 833A The Meaningless Game
    Codeforces 839D Winter is here
    Codeforces 839C Journey
  • 原文地址:https://www.cnblogs.com/dll102/p/15798567.html
Copyright © 2020-2023  润新知