Ò» ΪÁ˸üÇå³þµÄ¿´³ö2ÕßÇø±ð£¬Çë¿´ÏÂ±í£º
UNDO REDO
| Record of |
How to undo a change |
How to reproduce a change |
| Used for |
Rollback, Read-Consistency |
Rolling forward DB Changes |
| Stored in |
Undo segments |
Redo log files |
| Protect Against |
Inconsistent reads in multiuser systems |
Data loss |
¼òµ¥¿´À´£¬UNDOÖ÷Òª¼Ç¼ÈçºÎ³·ÏúÊÂÎñºÍ±£Ö¤¶ÁÒ»ÖÂÐÔ£»REDOÔòÊǸºÔð
Êý¾Ý¿âǰ¹ö£¨ÖØ×ö£©£¬±£»¤Êý¾Ý²»¶ªÊ§¡£
¶þ ÏÂÃæÎÒÃÇÀ´Í¨¹ýʵÀý˵Ã÷undo ºÍ redoµÄ¹ØÏµ£º
1 ÎÒÃǽ«Ö¤Ã÷ÒÔÏÂÊÂʵ£º
- oracle ÖÐredo°üº¬undo£»
- checkpoint »áµ¼ÖÂÔàÊý¾ÝдÈëdatafile£»
- buffers »á±»Ð´È뵱ǰµÄundo ±í¿Õ¼ä
2 ²Ù×÷²½Ö裺
- ´´½¨1¸öundo±í¿Õ¼ä£ºundotbs2 - ´´½¨1¸ö±í¿Õ¼ä£ºtest_undo - ÔÚ±í¿Õ¼ätest_undo´´½¨±í£ºtest_undo_tab £¨txt char(1000)£© - Ïò±ítest_undo_tab²åÈë2Ìõ¼Ç¼txt ¨C teststring1, teststring2£¬Ö´ÐÐÊÖ¹¤checkpoint²Ù×÷ - ÊÖ¹¤ÈÕÖ¾Çл»¡¢Çл»undo ±í¿Õ¼ä - ¸üÐÂteststring1Ϊteststring_uncommitted²¢ÇÒ²»Ìá½» - пªÒ»¸ösession ¸üРteststring2Ϊteststring_uncommitted²¢ÇÒÌá½» - ¼ì²éupdateǰºóµÄÖµ¶¼±»¼Ç¼ÔÚµ±Ç°redo logÖÐ - ¼ì²éundo ±í¿Õ¼ä²»°üº¬¸üÐÂ֮ǰµÄÖµ - ½øÐÐÊÖ¹¤checkpoint£¬ÕâÑùundoÐÅÏ¢½«±»Ð´Èë´ÅÅÌ - ¼ì²éundo ±í¿Õ¼ä°üº¬¸üÐÂǰµÄÖµ
3 ¾ßÌåʵÏÖ£º
- ²éÕÒµ±Ç°undo±í¿Õ¼ä
SQL> show parameter undo_tablespace
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS1
- ´´½¨Undo±í¿Õ¼ä undotbs2£º
SQL> create undo tablespace undotbs2 datafile '/u01/app/oracle/undotbs2.dbf'
2 size 100m;
Tablespace created.
- ´´½¨±í¿Õ¼ä test_undo
SQL> create tablespace test_undo datafile '/u01/app/oracle/test_undo.dbf'
2 size 128k;
Tablespace created.
- ´´½¨²âÊÔ±í test_undo_tab£º
SQL> create table test_undo_tab(txt char(1000)) tablespace test_undo;
Table created.
SQL> insert into test_undo_tab values ('teststring1');
1 row created.
SQL> insert into test_undo_tab values ('teststring2');
1 row created.
SQL> commit;
- Ö´ÐÐÊÖ¹¤¼ì²éµã£¬½«ÒÔÉϸıäдÈëÊý¾ÝÎļþ£º
SQL> alter system checkpoint;
System altered.
- ÉèÖÃundotbs2Ϊµ±Ç°undo±í¿Õ¼ä£º
SQL> alter system set undo_tablespace=undotbs2;
System altered.
SQL> show parameter undo_tablespace;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS2
- ½øÐÐÈÕÖ¾Çл»Ê¹µ±Ç°ÈÕÖ¾²»°üº¬×Ö·û´®teststring
SQL> alter system switch logfile;
System altered.
- ²éÕÒµ±Ç°ÈÕÖ¾
SQL> col member for a30
SQL> select member, l.status from v$log l, v$logfile f
2 where l.group# = f.group#
3 and l.status = 'CURRENT';
MEMBER STATUS
------------------------------ ----------------
/u01/app/oracle/oradata/orcl/r CURRENT
edo02.log
- ¸üвâÊÔ±íÖÐÒ»Ðв¢ÇÒ²»Ìá½»
SQL> update test_undo_tab set txt = 'teststring_uncommitted'
2 where txt = 'teststring1';
1 row updated.
- пªÒ»¸ösession ¸üÐÂÁíÍâÒ»Ðв¢ÇÒÌá½»
SQL> update test_undo_tab set txt = 'teststring_committed'
where txt = 'teststring2';
commit;
- ²é¿´ÕâʱºòµÄredo logÓ¦¸Ã°üº¬redo ºÍ undo £¨Ìá½»µÄºÍδÌá½»µÄÊý¾ÝÐÅÏ¢£©
[oracle@dylan ~]$ strings /u01/app/oracle/oradata/orcl/redo02.log | grep teststring
teststring_uncommitted
teststring1
teststring_committed
teststring2
- ¼ì²éµ±Ç°Êý¾ÝÎļþÓ¦¸ÃÊDz»°üº¬¸üкóµÄÊýÖµ£¨Ö»ÓиüÐÂǰÊý¾Ý£©ÒòΪ»¹Î´´¥·¢¼ì²éµã
[oracle@dylan ~]$ strings /u01/app/oracle/test_undo.dbf | grep teststring
teststring2
teststring1
- ´Ëʱ´¥·¢¼ì²éµã
SQL> alter system checkpoint;
- Ôٴμì²éÊý¾ÝÎļþ·¢ÏÖÊý¾ÝÒÑΪ×îÐÂÖµ£¨Ìá½»µÄºÍδÌá½»µÄÖµ£©
[oracle@dylan ~$ strings /u01/app/oracle/test_undo.dbf|grep teststring
teststring_committed ,
teststring_uncommitted
- ×îºó¼ì²éUndotbs2±í¿Õ¼ä·¢ÏÖ°üº¬¸üÐÂǰµÄÊýÖµ
[oracle@dylan ~]$ strings /u01/app/oracle/undotbs2.dbf | grep teststring
te