Manage Undo Tablespace

Every session has exclusive transaction which has specified undo segment.

When you have performed some SQL operations,you can refer v$transaction to find some information about the related transaction.

1.Find current session and its TADDR

SELECT SID,SERIAL#,USERNAME,TADDR FROM V$SESSION WHERE USERNAME='[current username]';

2.Find transaction record about current session

SELECT XIDUSN FROM V$TRANSACTION WHERE ADDR='[TADDR IN V$SESSION]';

3.Find which undo segment is current in use.

SELECT * FROM V$ROLLNAME WHERE USN=[XIDUSN IN V$TRANSACTION];

Experiment above proves that every active session(with transaction) has been arranged an undo segment.


What does undo segments function?

1.Read consistency

2.Rollback

3.Flashback Query


I'll demonstrate flashback query here.

Senario:I create a table,insert some records into it and commit.Delete all records from it and commit.Use flashback query to restore all records.

SQL> select * from scott.a;
...
9 rows selected.
SQL> delete from scott.a;
9 rows deleted.
SQL> commit;
Commit complete.
SQL> select * from scott.a;
no rows selected
-----------------------RESTORE------------------------------
SQL> select * from scott.a as of timestamp(sysdate-1/1440);
no rows selected
SQL> select * from scott.a as of timestamp(sysdate-5/1440);
...
9 rows selected.
SQL> insert into scott.a (select * from scott.a as of timestamp(sysdate-5/1440));
9 rows created.
SQL> select * from scott.a;
...
9 rows selected.
SQL> commit;
Commit complete.


Support flashback during required time:

There's a property of undo tablespace calling retention time.If required to support fixed time flashback,adminsitrator should set it.But relevant data in undo tablespace will be overrided still when undo tablespace is not enough.So administrator should adjust appropriate size of undo tablespace and enable 'guarantee' of retention to meet that requirement.

Note:it is not recommended to enable guarantee rentention because transactions will be not allowed to perform when undo tablespace is not enough.


2 typical errors related to undo tablespace:

a)transactions are executed unsucessfully.(caused by undo tablespace)

If someone try to delete a huge table,maybe it returns this error.

Because the dbms should guarantee OLTP is able to rollback,however,if all records you delete cannot be put into undo tablespace for rollback,that cause an error.

solution:

adjust size of undo tablespace.

divide your transaction into several phases and commit after each phase.

b)prompt"snapshot is too old"

If someone try to execute flashback query,maybe it returns this error.

There's an mechanism that it'll rewrite obsolete data in undo tablespace.The data related has been overrided before your query.

solution:

try to execute flashback query of later time.

adjust size of undo tablespace.


Note:adminstrator can use advisor in EM to evaluate proper size of undo tablespace.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章