UNDO表空间

oracle226



UNDO表空间
查看PPT
SQL > showparameter undo ;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO --自动管理
undo_retention integer 900 --inactive的undo块数据保持时间,设置为最长的select时间
undo_tablespace string UNDOTBS1 --默认的undo表空间

SQL > selectdt.tablespace_name ,dt.block_size ,dt.contents ,dt.retention fromdba_tablespaces dt wheredt.contents = 'UNDO' ;
TABLESPACE_NAME BLOCK_SIZE CONTENTS RETENTION
------------------------------ ---------- --------- -----------查询表空间
UNDOTBS1 8192 UNDO GUARANTEE
--下面是查询某个表空间对应的数据文件
SQL > selectddf.file_name ,ddf.tablespace_name ,ddf.blocks ,ddf.online_status fromdba_data_files ddf whereddf.tablespace_name = 'UNDOTBS1' ;
FILE_NAME TABLESPACE_NAME BLOCKS ONLINE_STATUS
-------------------------------------------------------------------------------- ------------------------------ ---------- -------------
/u01 /app /oracle /oradata /jiagulun /undotbs01.dbf UNDOTBS1 78720 ONLINE

SQL >
SQL > create undo tablespaceundotbs2 datafile '/u01/app/oracle/oradata/jiagulun/undotbs02.dbf' size 10m
2 autoextend on ; --创建undo表空间
Tablespacecreated

SQL > selectddf.file_name ,ddf.tablespace_name ,ddf.blocks ,ddf.online_status fromdba_data_files ddf whereddf.tablespace_name = 'UNDOTBS2' ;
FILE_NAME TABLESPACE_NAME BLOCKS ONLINE_STATUS
-------------------------------------------------------------------------------- ------------------------------ ---------- -------------
/u01 /app /oracle /oradata /jiagulun /undotbs02.dbf UNDOTBS2 1280 ONLINE

SQL > alter tablespaceundotbs2 add datafile '/u01/app/oracle/oradata/jiagulun/undotbs03.dbf' size 10m autoextend on ;
Tablespacealtered --为某个undo表空间添加数据文件

SQL > selectdt.tablespace_name ,dt.block_size ,dt.contents ,dt.retention fromdba_tablespaces dt wheredt.contents = 'UNDO' ;
TABLESPACE_NAME BLOCK_SIZE CONTENTS RETENTION
------------------------------ ---------- --------- -----------
UNDOTBS1 8192 UNDO GUARANTEE
UNDOTBS2 8192 UNDO NOGUARANTEE

SQL >
SQL > alter systemundo_tablespace = 'UNDOTBS2' ;
alter systemundo_tablespace = 'UNDOTBS2'
ORA - 02065 :非法的 ALTER SYSTEM选项

SQL > alter system SETundo_tablespace = 'UNDOTBS2' ;
Systemaltered --修改系统使用的表空间

SQL > showparameter undo_tablespace ;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS2

SQL > selectdt.tablespace_name ,dt.block_size ,dt.contents ,dt.retention fromdba_tablespaces dt wheredt.contents = 'UNDO' ;
TABLESPACE_NAME BLOCK_SIZE CONTENTS RETENTION
------------------------------ ---------- --------- -----------
UNDOTBS1 8192 UNDO GUARANTEE
UNDOTBS2 8192 UNDO NOGUARANTEE

SQL > alter tablespaceundotbs1 retention guarantee ;
;
Tablespacealtered

SQL >
SQL > selectdt.tablespace_name ,dt.block_size ,dt.contents ,dt.retention fromdba_tablespaces dt wheredt.contents = 'UNDO' ;
TABLESPACE_NAME BLOCK_SIZE CONTENTS RETENTION
------------------------------ ---------- --------- -----------
UNDOTBS1 8192 UNDO GUARANTEE
UNDOTBS2 8192 UNDO NOGUARANTEE
SQL > alter tablespaceundotbs2 retention guarantee ;
Tablespacealtered

SQL > selectdt.tablespace_name ,dt.block_size ,dt.contents ,dt.retention fromdba_tablespaces dt wheredt.contents = 'UNDO' ;
TABLESPACE_NAME BLOCK_SIZE CONTENTS RETENTION
------------------------------ ---------- --------- -----------
UNDOTBS1 8192 UNDO GUARANTEE
UNDOTBS2 8192 UNDO GUARANTEE

SQL >
SQL > alter tablespaceundotbs2 retention noguarantee ;
Tablespacealtered

SQL > selectdt.tablespace_name ,dt.block_size ,dt.contents ,dt.retention fromdba_tablespaces dt wheredt.contents = 'UNDO' ;
TABLESPACE_NAME BLOCK_SIZE CONTENTS RETENTION
------------------------------ ---------- --------- -----------
UNDOTBS1 8192 UNDO GUARANTEE
UNDOTBS2 8192 UNDO NOGUARANTEE

SQL > selectto_char (us.BEGIN_TIME , 'yyyy-mm-dd :hh24:mi:ss' ),
to_char (us.END_TIME , 'yyyy-mm-dd hh24:mi:ss' ),
us.UNDOBLKS ,us.TXNCOUNT fromv$undostat us ;
--查询undo状态信息:undoblks表示在这段时间内使用块大小
--txncount:表示这段时间的事务多少
TO_CHAR (US.BEGIN_TIME , 'YYYY-MM TO_CHAR(US.END_TIME,'YYYY -MM -D UNDOBLKS TXNCOUNT
------------------------------ ------------------------------ ---------- ----------
TO_CHAR (US.BEGIN_TIME , 'YYYY-MM TO_CHAR(US.END_TIME,'YYYY -MM -D UNDOBLKS TXNCOUNT
------------------------------ ------------------------------ ---------- ----------
2015 - 01 - 20 : 16 : 49 : 54 2015 - 01 - 20 16 : 59 : 54 308 185
2015 - 01 - 20 : 16 : 39 : 54 2015 - 01 - 20 16 : 49 : 54 193 139
2015 - 01 - 20 : 16 : 29 : 54 2015 - 01 - 20 16 : 39 : 54 201 120
2015 - 01 - 20 : 16 : 19 : 54 2015 - 01 - 20 16 : 29 : 54 279 614
2015 - 01 - 20 : 16 : 09 : 54 2015 - 01 - 20 16 : 19 : 54 246 179
25 rowsselected

SQL >




















你可能感兴趣的:(undo)