环境:
OS:linux
DB:10.2.0.4
引子:最近的数据库时不时的报临时表空间的满的警告,后来跟踪代码,发现是做CLOB操作时,导致的。
测试代码:
先建一个临时表空间,文件大小为100M, 开三个session, 依次在每个session里跑下面的代码:
declare
clb clob;
ch varchar2(32767);
k number;
begin
dbms_lob.createtemporary(clb,true,dbms_lob.call);
for i in 1..1500
loop
ch:=lpad('o',32767,'Y');
dbms_lob.writeappend(clb,length(ch),ch);
end loop;
k:=dbms_lob.getlength(clb);
dbms_lob.freetemporary(clb);
dbms_output.put_line('the clob length: '||k);
end;
跑完代码之后,相应的session不退出来,当在第三个session里跑上面代码时,就报:
ERROR at line 1:
ORA-01652: unable to extend temp segment by 128 in tablespace TEMP11
ORA-06512: at "SYS.DBMS_LOB", line 833
ORA-06512: at line 9
如果dbms_lob.freetemporary能够free相应的tempoary lob的话,按理不会出现上面的错误。
后来确定这是一个bug:
Bug 5723140 (which is included in 10.2.0.4) introduced event 60025 where when set if there are no active temp lobs in the session (ie: both cache temp lob and no-cache temp lobs used are zero) then the temp segment itself will also be freed releasing the space for other sessions to use. Note that this change is disabled by default.
See Note 5723140.8 "Bug 5723140 - Temp LOB space not released after commit" and Note 750209.1 "Temp LOB space not released after
commit: ora-1652 being hit"
alter session set events '60025 trace name context forever';
解决方法:
对于版本10.2.0.3,打补丁5723140。
对于版本10.2.0.4的话,建一个trigger,在测试中,建完trigger,重新测试上面的情况,tempory lob彻底释放了。
create or replace trigger login_db after logon on database
begin
execute immediate 'alter session set events ''60025 trace name context forever''';
end;
/
另一个解决方法,断开temporary LOB操作的session,但在生产环境里,不具有可操作性和可行性。
[@more@]