12c undo 表空間的管理
阿新 • • 發佈:2019-01-06
1、檢視undo 表空間
開啟所有pdb
[email protected]> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PRODPDB MOUNTED
5 PDB1 MOUNTED
[email protected]> alter pluggable database all open;
Pluggable database altered.
[email protected]> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PRODPDB READ WRITE NO
5 PDB1 READ WRITE NO
檢視所有的undo表空間
[email protected]> select con_id,TABLESPACE_NAME,CONTENTS from cdb_tablespaces where contents='UNDO';
CON_ID TABLESPACE_NAME CONTENTS
---------- ------------------------------ ---------------------
3 UNDOTBS1 UNDO
5 UNDOTBS1 UNDO
1 UNDOTBS1 UNDO
檢視所有undo的資料檔案
[email protected]> col FILE_NAME for a60
[email protected]> select con_id,tablespace_name,file_name from cdb_data_files where tablespace_name='UNDOTBS1';
CON_ID TABLESPACE_NAME FILE_NAME
---------- ------------------------------ ------------------------------------------------------------
3 UNDOTBS1 /u01/app/oracle/oradata/cdb1211/prodpdb/undotbs01.dbf
1 UNDOTBS1 /u01/app/oracle/oradata/cdb1211/undotbs01.dbf
5 UNDOTBS1 /u01/app/oracle/oradata/cdb1211/pdb1/undotbs01.dbf
檢視 undo 相關引數
[email protected]> col FILE_NAME for a60
[email protected]> col name for a20
[email protected]> select con_id,NAME,VALUE,ISINSTANCE_MODIFIABLE, ISPDB_MODIFIABLE from v$parameter where name like 'undo%';
CON_ID NAME VALUE ISINS ISPDB
---------- -------------------- -------------------- ----- -----
1 undo_management AUTO FALSE TRUE
1 undo_tablespace UNDOTBS1 TRUE TRUE
1 undo_retention 900 TRUE TRUE
檢視 CDB 當前 undo 模式
[email protected]> col property_name for a20
[email protected]> col PROPERTY_VALUE for a20
[email protected]> select PROPERTY_NAME,PROPERTY_VALUE from database_properties where PROPERTY_NAME='LOCAL_UNDO_ENABLED';
PROPERTY_NAME PROPERTY_VALUE
-------------------- --------------------
LOCAL_UNDO_ENABLED TRUE
當前環境使用 12cR2 版本,DBCA 建立 cdb1 時,預設勾選了 Use Local Undo tablespace for PDBs
設定 CDB 使用 Shared Undo Mode
關閉例項,startup upgrade 啟動例項
[email protected]> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[email protected]> startup upgrade;
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8798312 bytes
Variable Size 599789464 bytes
Database Buffers 222298112 bytes
Redo Buffers 7974912 bytes
Database mounted.
Database opened.
關閉例項,startup upgrade 啟動例項
[email protected]> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[email protected]> startup upgrade;
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8798312 bytes
Variable Size 599789464 bytes
Database Buffers 222298112 bytes
Redo Buffers 7974912 bytes
Database mounted.
Database opened.
關閉 local undo 模式,使用 shared und
[email protected]> ALTER DATABASE LOCAL UNDO OFF;
Database altered.
[email protected]> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[email protected]> startup
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8798312 bytes
Variable Size 599789464 bytes
Database Buffers 222298112 bytes
Redo Buffers 7974912 bytes
Database mounted.
Database opened.
[email protected]> alter pluggable database all open;
Pluggable database altered.
[email protected]> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PRODPDB READ WRITE NO
5 PDB1 READ WRITE NO
檢視 cdb1 當前 undo 模式
[email protected]> select PROPERTY_NAME,PROPERTY_VALUE from database_properties where PROPERTY_NAME='LOCAL_UNDO_ENABLED';
PROPERTY_NAME PROPERTY_VALUE
-------------------- --------------------
LOCAL_UNDO_ENABLED FALSE
當前使用 Shared Undo Mode,CDB 中所有容器共享使用一個 Undo 表空間
刪除 pdb1 本地 undo 表空間
共享 undo 模式下,oracle 忽略 PDB 本地的 undo 表空間。 可以刪除 PDB 本地的 undo 表空間及資料檔案。
設定客戶端的監聽
pdb1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = enmoedu1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdb1.enmoedu.com)
)
)
登入pdb1
[[email protected] admin]$ sqlplus /nolog
SQL*Plus: Release 12.2.0.1.0 Production on Thu Nov 16 20:37:02 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
@> conn sys/[email protected] as sysdba
Connected.
[email protected]> select tablespace_name,file_name from dba_data_files where tablespace_name='UNDOTBS1';
TABLESPACE_NAME FILE_NAME
------------------------------ ------------------------------------------------------------
UNDOTBS1 /u01/app/oracle/oradata/cdb1211/pdb1/undotbs01.dbf
[email protected]> drop tablespace undotbs1 including contents and datafiles;
Tablespace dropped.
[email protected]> select tablespace_name,file_name from dba_data_files where tablespace_name='UNDOTBS1';
no rows selected
設定 CDB 使用 Local Undo Mode
設定當前 CDB 使用 12.2 版本預設的 Local Undo Mode, 即 CDB 中每個容器使用本地 的 undo 表空間。
[email protected]> select con_id,TABLESPACE_NAME,CONTENTS from cdb_tablespaces where contents='UNDO';
CON_ID TABLESPACE CONTENTS
---------- ---------- ---------------------
3 UNDOTBS1 UNDO
1 UNDOTBS1 UNDO
1 SMALLUNDO UNDO
檢視 CDB 當前 undo 模式
[email protected]> col property_name for a20
[email protected]> col PROPERTY_VALUE for a20
[email protected]> select PROPERTY_NAME,PROPERTY_VALUE from database_properties where PROPERTY_NAME='LOCAL_UNDO_ENABLED';
PROPERTY_NAME PROPERTY_VALUE
-------------------- --------------------
LOCAL_UNDO_ENABLED FALSE
設定 Local Undo Mode
關閉資料庫例項
[email protected]> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
startup upgrade 啟動例項
[email protected]> startup upgrade;
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8798312 bytes
Variable Size 599789464 bytes
Database Buffers 222298112 bytes
Redo Buffers 7974912 bytes
Database mounted.
Database opened.
設定 undo 模式
[email protected]> ALTER DATABASE LOCAL UNDO ON;
Database altered.
[email protected]> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[email protected]> startup
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8798312 bytes
Variable Size 599789464 bytes
Database Buffers 222298112 bytes
Redo Buffers 7974912 bytes
Database mounted.
Database opened.
[email protected]> col property_name for a20
[email protected]> col PROPERTY_VALUE for a20
[email protected]> select PROPERTY_NAME,PROPERTY_VALUE from database_properties where PROPERTY_NAME='LOCAL_UNDO_ENABLED';
PROPERTY_NAME PROPERTY_VALUE
-------------------- --------------------
LOCAL_UNDO_ENABLED TRUE
啟動 PDB
[email protected]> alter pluggable database all open;
Pluggable database altered.
[email protected]> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PRODPDB READ WRITE NO
5 PDB1 READ WRITE NO
[email protected]> show parameter undo
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
temp_undo_enabled boolean FALSE
undo_management string AUTO
undo_retention integer 900
undo_tablespace string SMALLUNDO
[[email protected] ~]$ sqlplus sys/[email protected] as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Thu Nov 16 22:08:26 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[email protected]> show parameter undo
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
temp_undo_enabled boolean FALSE
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDO_1
檢視 CDB 資料庫中所有 undo 表空間
select con_id,TABLESPACE_NAME,CONTENTS from cdb_tablespaces where contents='UNDO';
CON_ID TABLESPACE CONTENTS
---------- ---------- ---------------------
1 UNDOTBS1 UNDO
1 SMALLUNDO UNDO
5 UNDO_1 UNDO
3 UNDOTBS1 UNDO
檢視 undo 表空間對應資料檔案
[email protected]> col FILE_NAME for a60
[email protected]> select con_id,tablespace_name,file_name from cdb_data_files where tablespace_name like '%UNDO%';
CON_ID TABLESPACE FILE_NAME
---------- ---------- ------------------------------------------------------------
1 UNDOTBS1 /u01/app/oracle/oradata/cdb1211/undotbs01.dbf
1 SMALLUNDO /u01/app/oracle/oradata/cdb1211/smallundo01.dbf
5 UNDO_1 /u01/app/oracle/oradata/cdb1211/pdb1/system01_i1_undo.dbf
3 UNDOTBS1 /u01/app/oracle/oradata/cdb1211/prodpdb/undotbs01.dbf
設定 CDB 使用 Local Undo Mode 後,資料庫在每個 PDB 中建立了本地的 undo 表空間