白天和黑夜只交替没交换无法想像对方的世界
分类: oracle
2013-06-19 16:07:12
关于回滚段的问题,之前也小整理过一个,参考:
roger同学昨天整理了一个更加详细的说明,转帖过来。 roger 的原文链接如下:
某些情况下,我们需要手动去清除一些有问题的回滚段,如果该回滚段中包含活动事务,那么使用正常的方式将无法drop,所以此时你dropundo tablespace 也将失败。
可能就会遇到如下的错误:
sql> drop tablespace undotbs1 includingcontents and datafiles;
drop tablespace undotbs1 including contentsand datafiles
*
error at line 1:
ora-01561: failed to remove all objects inthe tablespace specified
sql> show parameter undo
name type value
----------------------------------------------- ------------------------------
undo_management string auto
undo_retention integer 900
undo_tablespace string undotbs1
sql> create undo tablespace undotbs2datafile '/oracle/product/oradata/roger/undotbs2.dbf'
2 size 50m autoextend off;
tablespace created.
sql> create undo tablespace undotbs3datafile '/oracle/product/oradata/roger/undotbs3.dbf'
2 size 50m autoextend off;
tablespace created.
sql>
sql> conn roger/roger
connected.
sql> create table ht_01 as select * fromdba_objects where rownum <10;
table created.
sql> delete from ht_01 where rownum<5;
4 rows deleted.
sql> -----不提交
sql> selectowner,segment_name,segment_id,file_id,block_id,status
2 ,tablespace_name from dba_rollback_segs;
owner segment_name segment_id file_id block_id status tablespace_name
------ -------------- ---------- -------------------- -------- ---------------
sys system 0 1 9 online system
public _syssmu1$ 1 2 9 online undotbs1
public _syssmu2$ 2 2 25 online undotbs1
public _syssmu3$ 3 2 41 online undotbs1
public _syssmu4$ 4 2 57 online undotbs1
public _syssmu5$ 5 2 73 online undotbs1
public _syssmu6$ 6 2 89 online undotbs1
public _syssmu7$ 7 2 105 online undotbs1
public _syssmu8$ 8 2 121 online undotbs1
public _syssmu9$ 9 2 137 online undotbs1
public _syssmu10$ 10 2 153 online undotbs1
public _syssmu11$ 11 6 9 offline undotbs2
public _syssmu12$ 12 6 25 offline undotbs2
public _syssmu13$ 13 6 41 offline undotbs2
public _syssmu14$ 14 6 57 offline undotbs2
public _syssmu15$ 15 6 73 offline undotbs2
public _syssmu16$ 16 6 89 offline undotbs2
public _syssmu17$ 17 6 105 offline undotbs2
public _syssmu18$ 18 6 121 offline undotbs2
public _syssmu19$ 19 6 137 offline undotbs2
public _syssmu20$ 20 6 153 offline undotbs2
public _syssmu21$ 21 7 9 offline undotbs3
public _syssmu22$ 22 7 25 offline undotbs3
public _syssmu23$ 23 7 41 offline undotbs3
public _syssmu24$ 24 7 57 offline undotbs3
public _syssmu25$ 25 7 73 offline undotbs3
public _syssmu26$ 26 7 89 offline undotbs3
public _syssmu27$ 27 7 105 offline undotbs3
public _syssmu28$ 28 7 121 offline undotbs3
public _syssmu29$ 29 7 137 offline undotbs3
public _syssmu30$ 30 7 153 offline undotbs3
31 rows selected.
sql> selectxidusn,xidslot,xidsqn,ubablk,ubafil,ubarec from v$transaction;
xidusn xidslot xidsqn ubablk ubafil ubarec
---------- ---------- ---------- -------------------- ----------
9 13 299 439 2 47
sql> selectusn,name from v$rollname where usn=9;
usn name
------------------------------------------------------------
9 _syssmu9$
--确定当前正在使用的回滚段
sql>
sql>c/file_name/file_name,tablespace_name
1*select file_id,file_name,tablespace_name from dba_data_files order by 1
sql> /
file_idfile_name tablespace_name
--------------------------------------------------------- ---------------
1 /oracle/product/oradata/roger/system01.dbf system
2 /oracle/product/oradata/roger/undotbs01.dbf undotbs1
3 /oracle/product/oradata/roger/sysaux01.dbf sysaux
4 /oracle/product/oradata/roger/users01.dbf users
5 /oracle/product/oradata/roger/roger01.dbf roger
6 /oracle/product/oradata/roger/undotbs2.dbf undotbs2
7 /oracle/product/oradata/roger/undotbs3.dbf undotbs3
7 rows selected.
sql>
sql> show parameter undo
name type value
----------------------------------------------- -------------------
undo_management string auto
undo_retention integer 900
undo_tablespace string undotbs1
sql> alter system setundo_tablespace=undotbs2;
system altered.
sql> alter database datafile 2 offline;
database altered.
sql>
sql> shutdown abort;
oracle instance shut down.
sql>
sql>
sql> startup
oracle instance started.
total system global area 167772160 bytes
fixed size 1266392 bytes
variable size 104860968 bytes
database buffers 58720256 bytes
redo buffers 2924544 bytes
database mounted.
database opened.
sql> drop tablespace undotbs1 includingcontents and datafiles;
drop tablespace undotbs1 including contentsand datafiles
*
error at line 1:
ora-01548: activerollback segment '_syssmu9$' found, terminate dropping tablespace
sql> ---我们看到报错了 意思是说该回滚段中还有活动事务
sql> conn roger/roger
connected.
sql> show parameter undo
name type value
----------------------------------------------- ------------------------------
_collect_undo_stats boolean true
_gc_dissolve_undo_affinity boolean false
_gc_initiate_undo_affinity boolean true
_gc_undo_affinity boolean true
_gc_undo_affinity_locks boolean true
_in_memory_undo boolean true
_kcl_undo_grouping integer 32
_kcl_undo_locks integer 128
_optimizer_undo_changes boolean false
_optimizer_undo_cost_change string 10.2.0.4
_smon_undo_seg_rescan_limit integer 10
_undo_autotune boolean true
_undo_debug_mode integer 0
_undo_debug_usage integer 0
_verify_undo_quota boolean false
undo_management string auto
undo_retention integer 900
undo_tablespace string undotbs2
sql>
sql> alter system set"_smu_debug_mode" = 4;
system altered.
sql> alter rollback segment"_syssmu9$" offline;
alter rollback segment"_syssmu9$" offline
*
error at line 1:
ora-01598: rollback segment '_syssmu9$' isnot online
sql> drop rollback segment"_syssmu9$";
drop rollback segment "_syssmu9$"
*
error at line 1:
ora-01545: rollback segment '_syssmu9$'specified not available
sql> selectowner,segment_name,segment_id,file_id,block_id,status
2 from dba_rollback_segs wheresegment_name='_syssmu9$';
owner segment_name segment_id file_id block_id status
------ -------------------- -------------------- ---------- ----------------
public _syssmu9$ 9 2 137 needs recovery
sql>
用如下隐含参数:
_offline_rollback_segments=(_syssmu9$)
_corrupted_rollback_segments=(_syssmu9$)
讲参数添加到pfile里,在启动
sql> startup mountpfile='/oracle/pfile.ora';
oracle instance started.
total system global area 167772160 bytes
fixed size 1266392 bytes
variable size 104860968 bytes
database buffers 58720256 bytes
redo buffers 2924544 bytes
database mounted.
sql> alter database open;
database altered.
sql> selectowner,segment_name,segment_id,file_id,block_id,status
2 from dba_rollback_segs wheresegment_name='_syssmu9$';
owner segment_name segment_id file_id block_id status
------ -------------------- -------------------- ---------- ----------------
public _syssmu9$ 9 2 137 needs recovery
sql> drop rollbacksegment "_syssmu9$";
rollback segment dropped.
sql>
sql> drop tablespace undotbs1 includingcontents and datafiles;
tablespace dropped.
sql>
sql> select count(*) from ht_01;
count(*)
----------
5 ---数据丢失
这里可能有人会问上面的_undo_debug_mode参数为啥不管用?其实不是没效果,是针对这种情况下,没用而已,对于自动undo管理模式,可以使用该参数来手工删除某个回滚段,前提是该回滚段无活动事务。
sql> show parameter undo
name type value
----------------------------------------------- ------------------------------
undo_management string auto
undo_retention integer 900
undo_tablespace string undotbs3
sql> conn roger/roger
connected.
sql> select count(*) from ht_01;
count(*)
----------
3
sql> delete from ht_01where rownum <2;
1 row deleted.
sql> ---不提交
sql> selectxidusn,xidslot,xidsqn,ubablk,ubafil,ubarec from v$transaction;
xidusn xidslot xidsqn ubablk ubafil ubarec
---------- ---------- ---------- -------------------- ----------
2 5 310 345 7 6
sql> select usn,name from v$rollname whereusn=2;
usnname
------------------------------------------------------------
2_syssmu2$
sql> alter system setundo_tablespace=undotbs4;
system altered.
sql> alter database datafile 7 offline;
database altered.
sql>
sql> shutdown abort;
oracle instance shut down.
sql> startup
oracle instance started.
total system global area 167772160 bytes
fixed size 1266392 bytes
variable size 104860968 bytes
database buffers 58720256 bytes
redo buffers 2924544 bytes
database mounted.
database opened.
sql> drop tablespace undotbs3 includingcontents and datafiles;
drop tablespace undotbs3 including contentsand datafiles
*
error at line 1:
ora-01548: active rollback segment'_syssmu2$' found, terminate dropping tablespace
sql> select ts# fromts$ where name='undotbs3';
ts#
----------
7
sql> select file#,block#,type#,ts# fromseg$ where ts#=7;
file# block# type# ts#
---------- ---------- ---------- ----------
7 9 10 7
7 25 10 7
7 41 10 7
7 57 10 7
7 73 10 7
7 89 10 7
7 105 10 7
7 121 10 7
7 137 10 7
7 153 10 7
7 265 3 7
7 281 10 7
12 rows selected.
sql> selectowner,segment_name,segment_id,file_id,block_id,status
2 from dba_rollback_segs wherefile_id=7;
owner segment_name segment_id file_id block_id status
------ ------------- ---------- -------------------- ----------------
public _syssmu2$ 2 7 281 needs recovery
--这里281 不是offline
public _syssmu21$ 21 7 9 offline
public _syssmu22$ 22 7 25 offline
public _syssmu23$ 23 7 41 offline
public _syssmu24$ 24 7 57 offline
public _syssmu25$ 25 7 73 offline
public _syssmu26$ 26 7 89 offline
public _syssmu27$ 27 7 105 offline
public _syssmu28$ 28 7 121 offline
public _syssmu29$ 29 7 137 offline
public _syssmu30$ 30 7 153 offline
11 rows selected.
sql>
sql> update seg$set type# = 3 where ts#=7 and file#=7 and block#=281;
1 row updated.
sql> commit;
commit complete.
sql> shutdown immediate;
database closed.
database dismounted.
oracle instance shut down.
sql> startup
oracle instance started.
total system global area 167772160 bytes
fixed size 1266392 bytes
variable size 104860968 bytes
database buffers 58720256 bytes
redo buffers 2924544 bytes
database mounted.
database opened.
sql> select us# ,name,file#,block# fromundo$ where file#=7;
us# name file# block#
---------- --------------- ------- ----------
1 _syssmu1$ 7 265
2 _syssmu2$ 7 281
21 _syssmu21$ 7 9
22 _syssmu22$ 7 25
23 _syssmu23$ 7 41
24 _syssmu24$ 7 57
25 _syssmu25$ 7 73
26 _syssmu26$ 7 89
27 _syssmu27$ 7 105
28 _syssmu28$ 7 121
29 _syssmu29$ 7 137
30 _syssmu30$ 7 153
12 rows selected.
sql>
sql> delete from undo$where ts#=7 and us#=2;
1 row deleted.
sql> delete from seg$ where ts#=7 andfile#=7 and block#=281;
1 row deleted.
sql>
sql> commit;
commit complete.
sql> drop rollback segment"_syssmu2$";
drop rollback segment "_syssmu2$"
*
error at line 1:
ora-01545: rollback segment '_syssmu2$'specified not available
由于我们已经从几个数据字典表中将该段清除了,所以需要用包检查下
sql> execute hcheck.full
pl/sql procedure successfully completed.
sql> drop rollback segment"_syssmu2$";
rollback segment dropped.
sql>
sql> drop tablespace undotbs3 includingcontents and datafiles;
drop tablespace undotbs3 including contentsand datafiles
*
error at line 1:
ora-01561: failed to remove all objects inthe tablespace specified
对于该错误,处理起来就非常容易了,如下:
sql> update seg$ set type# = 3 wherets#=7;
11 rows updated.
sql> commit;
commit complete.
sql> shutdown immediate;
database closed.
database dismounted.
oracle instance shut down.
sql> startup
oracle instance started.
total system global area 167772160 bytes
fixed size 1266392 bytes
variable size 104860968 bytes
database buffers 58720256 bytes
redo buffers 2924544 bytes
database mounted.
database opened.
sql> drop tablespace undotbs3 includingcontents and datafiles;
tablespace dropped.
sql> ----drop tablespace 成功
简单的总结下,其实我们只要通过如下步骤就能轻易的删除:
1. 将回滚段更改为临时段
2. 重启实例
3. 从seg$中删除记录
4. 从undo$中删除记录
需要注意一下的是,如果不使用hcheck.full,那么直接drop tablespace可能遇到如下错误:
sql> drop tablespace undotbs2 includingcontents and datafiles;
drop tablespace undotbs2 including contentsand datafiles
*
error at line 1:
ora-00600: internal error code, arguments:[ktssdrp1], [5], [6], [25], [], [], [], []
sql> purge recyclebin;
recyclebin purged.
sql> create table ht01 as selectowner,object_name,object_id
2 from dba_objects whereobject_id <100;
table created.
sql> select count(*) from ht01;
count(*)
----------
98
sql> delete from ht01where object_id <10;
8 rows deleted.
sql> ----不提交
sql> show parameter undo
name type value
----------------------------------------------- ------------------------------
undo_management string auto
undo_retention integer 900
undo_tablespace string undotbs4
sql> selectowner,segment_name,segment_id,file_id,block_id,status
2 from dba_rollback_segs wheretablespace_name='undotbs4';
owner segment_name segment_id file_id block_id status
------ ------------- ---------- -------------------- ----------------
public _syssmu1$ 1 2 169 online
public _syssmu2$ 2 2 185 online
public _syssmu3$ 3 2 9 offline
public _syssmu4$ 4 2 25 offline
public _syssmu5$ 5 2 41 offline
public _syssmu6$ 6 2 57 offline
public _syssmu7$ 7 2 73 offline
public _syssmu8$ 8 2 89 offline
public _syssmu10$ 10 2 105 offline
public _syssmu11$ 11 2 121 offline
public _syssmu12$ 12 2 137 offline
public _syssmu31$ 31 2 153 offline
12 rows selected.
sql> selectxidusn,xidslot,xidsqn,ubablk,ubafil,ubarec from v$transaction;
xidusn xidslot xidsqn ubablk ubafil ubarec
---------- ---------- ---------- -------------------- ----------
2 9 3 191 2 10
sql> select usn,name from v$rollnamewhere usn=2;
usn name
------------------------------------------------------------
2 _syssmu2$
sql> select file_id,file_name,statusfrom dba_data_files order by 1;
file_id file_name status
--------------------------------------------------------- ---------
1 /oracle/product/oradata/roger/system01.dbf available
2 /oracle/product/oradata/roger/undotbs4.dbf available
3 /oracle/product/oradata/roger/sysaux01.dbf available
4 /oracle/product/oradata/roger/users01.dbf available
5 /oracle/product/oradata/roger/roger01.dbf available
6 /oracle/product/oradata/roger/undotbs5.dbf available
6 rows selected.
sql> alter system setundo_tablespace=undotbs5;
system altered.
sql> alter database datafile 2 offline;
database altered.
sql>
sql> selectowner,segment_name,segment_type,header_file,header_block
2 from dba_segments wheresegment_name='_syssmu2$';
owner segment_name segment_type header_fileheader_block
----------- -------------------------------------- ----------- ------------
sys _syssmu2$ type2 undo 2 185
sql>
单纯的通过修改undo$的status$字典是无法drop的,如下:
sql> update undo$ set status$=4 wherefile#=2 and block#=185;
1 row updated.
sql> commit;
commit complete.
sql> select us#,name,file# ,block#,status$ from undo$;
us# name file# block# status$
---------- ---------------- ---------- ---------- ----------
0 system 1 9 3
1 _syssmu1$ 2 169 2
2 _syssmu2$ 2 185 4
3 _syssmu3$ 2 9 2
4 _syssmu4$ 2 25 2
5 _syssmu5$ 2 41 2
6 _syssmu6$ 2 57 2
7 _syssmu7$ 2 73 2
8 _syssmu8$ 2 89 2
9 _syssmu9$ 2 137 1
10 _syssmu10$ 2 105 2
11 _syssmu11$ 2 121 2
12 _syssmu12$ 2 137 2
13 _syssmu13$ 6 41 2
14 _syssmu14$ 6 57 2
15 _syssmu15$ 6 73 2
16 _syssmu16$ 6 89 2
17 _syssmu17$ 6 105 2
18 _syssmu18$ 6 121 2
19 _syssmu19$ 6 137 2
20 _syssmu20$ 6 153 2
21 _syssmu21$ 6 9 3
22 _syssmu22$ 6 25 3
23 _syssmu23$ 6 41 3
24 _syssmu24$ 6 57 3
25 _syssmu25$ 6 73 3
26 _syssmu26$ 6 89 3
27 _syssmu27$ 6 105 3
28 _syssmu28$ 6 121 3
29 _syssmu29$ 6 137 3
30 _syssmu30$ 6 153 3
31 _syssmu31$ 2 153 2
32 rows selected.
sql>
sql> drop rollback segment"_syssmu2$";
drop rollback segment "_syssmu2$"
*
error at line 1:
ora-01545: rollback segment '_syssmu2$'specified not available
sql> alter system set"_smu_debug_mode" = 4;
system altered.
sql> drop rollback segment"_syssmu2$";
drop rollback segment "_syssmu2$"
*
error at line 1:
ora-01545: rollback segment '_syssmu2$'specified not available
下面我们通过bbed来修改元数据,也就是直接修改回滚段的状态,将其修改为offline。
sql> selectdbms_rowid.rowid_relative_fno(rowid) file#,dbms_rowid.rowid_block_number(rowid)blk#
2 from undo$ where file#=2 andblock#=185;
file# blk#
---------- ----------
1 106
sql>
bbed> set file 1 block106
file# 1
block# 106
bbed> p kdbr
sb2 kdbr[0] @86 8079
sb2 kdbr[1] @88 5234
sb2 kdbr[2] @90 4754
sb2 kdbr[3] @92 6654
sb2 kdbr[4] @94 7860
sb2 kdbr[5] @96 7805
sb2 kdbr[6] @98 6818
sb2 kdbr[7] @100 5123
sb2 kdbr[8] @102 5068
sb2 kdbr[9] @104 5940
sb2 kdbr[10] @106 7525
sb2 kdbr[11] @108 5013
sb2 kdbr[12] @110 4858
sb2 kdbr[13] @112 6053
sb2 kdbr[14] @114 7309
sb2 kdbr[15] @116 7255
sb2 kdbr[16] @118 7201
sb2 kdbr[17] @120 7146
sb2 kdbr[18] @122 7091
sb2 kdbr[19] @124 5885
sb2 kdbr[20] @126 6981
sb2 kdbr[21] @128 5290
sb2 kdbr[22] @130 5780
sb2 kdbr[23] @132 5726
sb2 kdbr[24] @134 5672
sb2 kdbr[25] @136 5618
sb2 kdbr[26] @138 5564
sb2 kdbr[27] @140 5509
sb2 kdbr[28] @142 5454
sb2 kdbr[29] @144 5399
sb2 kdbr[30] @146 5344
sb2 kdbr[31] @148 4803
bbed> p *kdbr[2]
rowdata[0]
----------
ub1 rowdata[0] @4822 0x2c
bbed>
bbed>
bbed> x /1rnnnnnnnnnnnnnn
rowdata[0] @4822
----------
:0x2c (kdrhfl, kdrhff, kdrhfh)
:0x00
: 17
col 0[2] @4825: 2
col 1[9] @4828: -0
col 2[2] @4838: 1
col 3[2] @4841: 2
col 4[3] @4844: 185
col 5[1] @4848: 0
col 6[1] @4850: 0
col 7[1] @4852: 0
col 8[1] @4854: 0
col 9[1] @4856: 0
col 10[2] @4858: 4
col 11[2] @4861: 8
col 12[0] @4864: *null*
col 13[0] @4865: *null*
col 14[0] @4866: *null*
col 15[0] @4867: *null*
col 16[2] @4868: 1
bbed> modify /x 02 offset 4860
file: /oracle/product/oradata/roger/system01.dbf(1)
block: 106 offsets: 4860 to 5371 dba:0x0040006a
------------------------------------------------------------------------
0202c109 ffffffff 02c1022c 001102c1 200a5f535953534d 55333124 02c10202
c10303c2 023604c3 53491901 8002c103 02c102018002c103 02c109ff ffffff02
c1022c00 1102c10d 0a5f5359 53534d55 31322402c10202c1 0303c202 2604c353
49250180 02c10302 c1020180 02c10302 c109ffffffff02c1 022c0011 02c1200a
5f535953 534d5533 312402c1 0202c103 03c2023601800180 01800180 018002c1
0402c109 ffffffff 02c1022c 001102c1 0d0a5f535953534d 55313224 02c10202
c10303c2 02260180 01800180 01800180 02c10402c109ffff ffff02c1 022c0011
02c10c0a 5f535953 534d5531 312402c1 0202c10303c20216 04c35349 1b018002
c10802c1 04018002 c10302c1 09ffffff ff02c1022c001102 c109095f 53595353
4d553824 02c10202 c10302c1 5a04c353 491d018003c20345 03c2033e 018002c1
0302c109 ffffffff 02c1022c 001102c1 08095f535953534d 55372402 c10202c1
0302c14a 04c35349 27018003 c2036403 c2052801 8002c10302c109ff ffffff02
c1023c01 1102c103 095f5359 53534d55 322402c10202c108 03c20352 04c34a3a
1b018003 c2036403 c2031601 8002c106 02c108ffffffff02 c1022c00 1102c102
095f5359 53534d55 312402c1 0202c103 03c2024604c35351 51018003 c2033003
c2035101 8002c103 02c109ff ffffff02 c1022c011102c116 0a5f5359 53534d55
bbed> sum apply
check value for file 1, block 106:
current = 0x32cb, required = 0x32cb
bbed> verify
dbverify - verification starting
file = /oracle/product/oradata/roger/system01.dbf
block = 106
dbverify - verification complete
total blocks examined : 1
total blocks processed (data) : 1
total blocks failing (data) : 0
total blocks processed (index): 0
total blocks failing (index): 0
total blocks empty : 0
total blocks marked corrupt : 0
total blocks influx : 0
bbed>
sql> startup
oracle instance started.
total system global area 167772160 bytes
fixed size 1266392 bytes
variable size 104860968 bytes
database buffers 58720256 bytes
redo buffers 2924544 bytes
database mounted.
database opened.
sql> select us#,name,file# ,block#,status$ from undo$ where file#=2;
us# name file# block# status$
---------- ------------------ -------------------- ----------
1 _syssmu1$ 2 169 2
2 _syssmu2$ 2 185 1
3 _syssmu3$ 2 9 2
4 _syssmu4$ 2 25 2
5 _syssmu5$ 2 41 2
6 _syssmu6$ 2 57 2
7 _syssmu7$ 2 73 2
8 _syssmu8$ 2 89 2
9 _syssmu9$ 2 137 1
10 _syssmu10$ 2 105 2
11 _syssmu11$ 2 121 2
12 _syssmu12$ 2 137 2
31 _syssmu31$ 2 153 2
13 rows selected.
sql> drop rollbacksegment "_syssmu2$";
rollback segment dropped.
sql> ---成功drop回滚段。
sql> conn roger/roger
connected.
sql> select count(*) from ht01;
count(*)
----------
90
-------------------------------------------------------------------------------------------------------
blog: http://blog.csdn.net/tianlesoftware
email: dvd.dba@gmail.com
dba1 群:62697716(满); dba2 群:62697977(满) dba3 群:62697850(满)
dba 超级群:63306533(满); dba4 群: 83829929 dba5群: 142216823
dba6 群:158654907 聊天 群:40132017 聊天2群:69087192
--加群需要在备注说明oracle表空间和数据文件的关系,否则拒绝申请