查看當前使用的undo表空間信息:
SQL> show parameter undo_tablespace NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ undo_tablespace string UNDOTBS1
1 SQL> col FILE_NAME format a100 2 SQL> select tablespace_name, file_id, file_name,round (bytes / (1024 * 1024), 0) total_space from dba_data_files where tablespace_name='UNDOTBS1'; 3 4 TABLESPACE_NAME FILE_ID FILE_NAME TOTAL_SPACE 5 -------------------- ---------- ---------------------------------------------------------------------------------------------------- ----------- 6 UNDOTBS1 4 /u01/app/oracle/oradata/orcl/undotbs01.dbf 220
1、數據庫狀態靜止時(無DML操作期間)執行UNDO表空間切換(由UNDOTBS1切換為UNDOTBS2)
(1)創建新的undo表空間UNDOTBS2
1 SQL> create undo tablespace UNDOTBS2 datafile '/u01/app/oracle/oradata/orcl/undotbs02.dbf' size 10M; 2 3 Tablespace created.
(2)切換UNDOTBS2為新的undo表空間
1 SQL> alter system set undo_tablespace = undotbs2 scope=both; 2 3 System altered.
(3)此時數據庫處於靜止狀態,無任何DML操作,查看UNDOTBS1已經處於OFFLINE狀態
1 SQL> select tablespace_name , status , count(*) from dba_rollback_segs group by tablespace_name , status; 2 3 TABLESPACE_NAME STATUS COUNT(*) 4 -------------------- ---------------- ---------- 5 UNDOTBS1 OFFLINE 10 6 SYSTEM ONLINE 1 7 UNDOTBS2 ONLINE 11
(4)檢查確認UNDOTBS1中沒有ONLINE的segment
1 SQL> select status,segment_name from dba_rollback_segs where status not in ('OFFLINE') and tablespace_name='UNDOTBS1'; 2 3 no rows selected
(5)刪除舊的UNDOTBS1
1 SQL> Drop tablespace UNDOTBS1 including contents and datafiles; 2 3 Tablespace dropped.
(6)至此,undo表空間由UNDOTBS1成功切換為UNDOTBS2.
2、數據庫中有DML操作期間,切換UNDO表空間步驟(由UNDOTBS2切換為UNDOTBS1)
復制代碼
1 SQL> create undo tablespace UNDOTBS1 datafile '/u01/app/oracle/oradata/orcl/undotbs01.dbf' size 220M; 2 3 Tablespace created. 4 5 SQL> select tablespace_name, file_id, file_name,round (bytes / (1024 * 1024), 0) total_space from dba_data_files; 6 7 TABLESPACE_NAME FILE_ID FILE_NAME TOTAL_SPACE 8 -------------------- ---------- ---------------------------------------------------------------------------------------------------- ----------- 9 SYSTEM 1 /u01/app/oracle/oradata/orcl/system01.dbf 10 SYSAUX 3 /u01/app/oracle/oradata/orcl/sysaux01.dbf 11 USERS 6 /u01/app/oracle/oradata/orcl/users01.dbf 12 UNDOTBS2 11 /u01/app/oracle/oradata/orcl/undotbs02.dbf 13 UNDOTBS1 12 /u01/app/oracle/oradata/orcl/undotbs01.dbf
(1)設置UNDOTBS1為默認undo表空間
1 SQL> alter system set undo_tablespace = undotbs1 scope=both; 2 3 System altered.
(2)此時檢查UNDOTBS1處於ONLINE狀態
復制代碼
1 SQL> select tablespace_name , status , count(*) from dba_rollback_segs group by tablespace_name , status; 2 3 TABLESPACE_NAME STATUS COUNT(*) 4 -------------------- ---------------- ---------- 5 UNDOTBS1 ONLINE 6 SYSTEM ONLINE 7 UNDOTBS2 OFFLINE
(3)刪除
1 SQL> select status,segment_name from dba_rollback_segs where status not in ('OFFLINE') and tablespace_name='UNDOTBS2'; 2 3 no rows selected 4 5 SQL> Drop tablespace UNDOTBS2 including contents and datafiles; 6 7 Tablespace dropped. 8 9 SQL> show parameter undo 10 11 NAME TYPE VALUE 12 ------------------------------------ ----------- ------------------------------ 13 temp_undo_enabled boolean FALSE 14 undo_management string AUTO 15 undo_retention integer 900 16 undo_tablespace string UNDOTBS1
(4)至此,undo表空間由UNDOTBS2又成功切換為UNDOTBS1