Oracle中undo表空間的切換


查看操作系統:

SQL>  !cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.4 (Maipo)
查看數據庫版本:

SQL> set linesize 400
SQL> select * from v$version;

BANNER                                                                                                   CON_ID
---------------------------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production                                  0
PL/SQL Release 12.1.0.2.0 - Production                                                                        0
CORE    12.1.0.2.0      Production                                                                            0
TNS for Linux: Version 12.1.0.2.0 - Production                                                                0
NLSRTL Version 12.1.0.2.0 - Production                                                                        0

查看當前使用的undo表空間信息:

SQL> show parameter undo_tablespace

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace                      string      UNDOTBS1
SQL> col FILE_NAME  format a100
SQL> select tablespace_name, file_id, file_name,round (bytes / (1024 * 1024), 0) total_space from dba_data_files where tablespace_name='UNDOTBS1';

TABLESPACE_NAME         FILE_ID FILE_NAME                                                                                            TOTAL_SPACE
-------------------- ---------- ---------------------------------------------------------------------------------------------------- -----------
UNDOTBS1                      4 /u01/app/oracle/oradata/orcl/undotbs01.dbf                                                                   220

1、數據庫狀態靜止時(無DML操作期間)執行UNDO表空間切換(由UNDOTBS1切換為UNDOTBS2)

(1)創建新的undo表空間UNDOTBS2

SQL> create undo tablespace UNDOTBS2 datafile '/u01/app/oracle/oradata/orcl/undotbs02.dbf' size 10M;

Tablespace created.

(2)切換UNDOTBS2為新的undo表空間

SQL> alter system set undo_tablespace = undotbs2 scope=both;

System altered.

(3)此時數據庫處於靜止狀態,無任何DML操作,查看UNDOTBS1已經處於OFFLINE狀態

SQL> select tablespace_name , status , count(*) from dba_rollback_segs group by tablespace_name , status;

TABLESPACE_NAME      STATUS             COUNT(*)
-------------------- ---------------- ----------
UNDOTBS1             OFFLINE                  10
SYSTEM               ONLINE                    1
UNDOTBS2             ONLINE                   11

(4)檢查確認UNDOTBS1中沒有ONLINE的segment

SQL> select status,segment_name from dba_rollback_segs where status not in ('OFFLINE') and tablespace_name='UNDOTBS1';

no rows selected

(5)刪除舊的UNDOTBS1

SQL> Drop tablespace UNDOTBS1 including contents and datafiles;

Tablespace dropped.

(6)至此,undo表空間由UNDOTBS1成功切換為UNDOTBS2.

 

2、數據庫中有DML操作期間,切換UNDO表空間步驟(由UNDOTBS2切換為UNDOTBS1)

SQL> create undo tablespace UNDOTBS1 datafile '/u01/app/oracle/oradata/orcl/undotbs01.dbf' size 220M;

Tablespace created.

SQL> select tablespace_name, file_id, file_name,round (bytes / (1024 * 1024), 0) total_space from dba_data_files;

TABLESPACE_NAME         FILE_ID FILE_NAME                                                                                            TOTAL_SPACE
-------------------- ---------- ---------------------------------------------------------------------------------------------------- -----------
SYSTEM                        1 /u01/app/oracle/oradata/orcl/system01.dbf                                                                    790
SYSAUX                        3 /u01/app/oracle/oradata/orcl/sysaux01.dbf                                                                    730
USERS                         6 /u01/app/oracle/oradata/orcl/users01.dbf                                                                       5
UNDOTBS2                     11 /u01/app/oracle/oradata/orcl/undotbs02.dbf                                                                    10
UNDOTBS1                     12 /u01/app/oracle/oradata/orcl/undotbs01.dbf                                                                   220

(1)設置UNDOTBS1為默認undo表空間

SQL> alter system set undo_tablespace = undotbs1 scope=both;

System altered.

(2)此時檢查UNDOTBS1處於ONLINE狀態

SQL> select tablespace_name , status , count(*) from dba_rollback_segs group by tablespace_name , status;

TABLESPACE_NAME      STATUS             COUNT(*)
-------------------- ---------------- ----------
UNDOTBS1             ONLINE                   11
SYSTEM               ONLINE                    1
UNDOTBS2             OFFLINE                  11

(3)刪除

SQL> select status,segment_name from dba_rollback_segs where status not in ('OFFLINE') and tablespace_name='UNDOTBS2';

no rows selected

SQL> Drop tablespace UNDOTBS2 including contents and datafiles;

Tablespace dropped.

SQL> show parameter undo

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
temp_undo_enabled                    boolean     FALSE
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      UNDOTBS1
SQL> 

 

(4)至此,undo表空間由UNDOTBS2又成功切換為UNDOTBS1


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM