How to Release the Temp LOB Space and Avoid Hitting ORA-1652 (文档 ID 802897.1)

APPLIES TO:

Oracle Database - Enterprise Edition - Version 8.1.5.0 and later
Information in this document applies to any platform.

GOAL

How to release Temp LOB Segment that has been created explicitly or implicitly by Oracle for intermediate stages of database processing.

SOLUTION

Prior to 10.2.0.4 
=============

Actually we have different kinds of Temporary Segments. Oracle often requires temporary work space for intermediate stages of database processing. There are different kinds of temporary segments in the database. Some of them are created explicitly by the users. The others are created and accessed for the user by the system.

Use the view V$TEMPORARY_LOBS in conjunction with DBA_SEGMENTS or V$SORT_SEGMENT to determine how much space is being used by temporary lobs. We can create an explicit temporary BLOB or CLOB and its corresponding index in the user‘s default tablespace calling DBMS_LOB.CREATETEMPORARY procedure, and free them by calling DBMS_LOB.FREETEMPORARY.

When calling DBMS_LOB.CREATETEMPORARY, TWO temporary extents are allocated to store LOB_DATA and one temporary extent to store LOB_INDEX in 8i. So, a total of three temporary extents are allocated in 8i. However, in 9i (Release 2) and up, only one temporary extent is allocated .

DBMS_LOB.CREATETEMPORARY can be used with limited success prior to 10.2.0.4.

The only true solution prior to 10.2.0.4 and the setting of the event (as discussed below) is to terminate the session that created the temporary lob.

10.2.0.4 and above 
===============

Two approaches are available:

1- You can use DBMS_LOB.FREETEMPORARY where the LOB locator that was freed is marked as invalid.

DBMS_LOB.FREETEMPORARY frees space from temp tablespace and it is available to that same session, but the temp segment is not released and made available to other sessions. So if the session creates another temp lob after freetemporary, the space is reused by that session.
The space is not released until the session exits. That can easily lead to an ORA-1652 error when multiple concurrent sessions are doing a huge LOB operations and not exiting, thus the freed space by DBMS_LOB.FREETEMPORARY is only available within the calling session but not for the other sessions.

-- ========
-- Session1
-- ========
-- SQL*Plus: Release 10.2.0.4.0 - Production on Tue Apr 7 09:06:31 2009

-- Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

-- Connected to:
-- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
-- With the Partitioning, OLAP, Data Mining and Real Application Testing options

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;
/

-- PL/SQL procedure successfully completed.

select u.tablespace, u.contents, u.segtype, u.extents, u.blocks, round(((u.blocks*P.VALUE)/1024/1024),2) MB
from v$session s, v$sort_usage u, SYS.V_$SYSTEM_PARAMETER P
where s.saddr = u.session_addr 
AND UPPER(P.NAME)=‘DB_BLOCK_SIZE‘
order by MB DESC;

TABLESPACE                      CONTENTS  SEGTYPE      EXTENTS     BLOCKS         MB
------------------------------- --------- --------- ---------- ---------- ----------
TEMP                            TEMPORARY LOB_DATA          48       6144         48
TEMP                            TEMPORARY LOB_DATA          48       6144         48
TEMP                            TEMPORARY LOB_INDEX          1        128          1
TEMP                            TEMPORARY LOB_INDEX          1        128          1

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;
/

-- PL/SQL procedure successfully completed.

select u.tablespace, u.contents, u.segtype, u.extents, u.blocks, round(((u.blocks*P.VALUE)/1024/1024),2) MB
from v$session s, v$sort_usage u, SYS.V_$SYSTEM_PARAMETER P
where s.saddr = u.session_addr
and    UPPER(P.NAME)=‘DB_BLOCK_SIZE‘
order by MB DESC;

TABLESPACE                      CONTENTS  SEGTYPE      EXTENTS     BLOCKS         MB
------------------------------- --------- --------- ---------- ---------- ----------
TEMP                            TEMPORARY LOB_DATA          48       6144         48
TEMP                            TEMPORARY LOB_DATA          48       6144         48
TEMP                            TEMPORARY LOB_INDEX          1        128          1
TEMP                            TEMPORARY LOB_INDEX          1        128          1

<<<<<<<<<<<<< Only 4 rows selected >>>>>>>>>>>>>>>>

-- =========
-- session2
-- =========

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;
/

-- PL/SQL procedure successfully completed.

select u.tablespace, u.contents, u.segtype, u.extents, u.blocks, round(((u.blocks*P.VALUE)/1024/1024),2) MB
from v$session s, v$sort_usage u, SYS.V_$SYSTEM_PARAMETER P
where s.saddr = u.session_addr
and    UPPER(P.NAME)=‘DB_BLOCK_SIZE‘
order by MB DESC;

TABLESPACE                      CONTENTS  SEGTYPE      EXTENTS     BLOCKS         MB
------------------------------- --------- --------- ---------- ---------- ----------
TEMP                            TEMPORARY LOB_DATA          48       6144         48
TEMP                            TEMPORARY LOB_DATA          48       6144         48
TEMP                            TEMPORARY LOB_DATA          48       6144         48
TEMP                            TEMPORARY LOB_INDEX          1        128          1
TEMP                            TEMPORARY LOB_INDEX          1        128          1
TEMP                            TEMPORARY LOB_INDEX          1        128          1

6 rows selected.

-- When we disconnect session 2 now and run the same query from session 1 again we will get 4 rows only

select u.tablespace, u.contents, u.segtype, u.extents, u.blocks, round(((u.blocks*P.VALUE)/1024/1024),2) MB
from v$session s, v$sort_usage u, SYS.V_$SYSTEM_PARAMETER P
where s.saddr = u.session_addr
and UPPER(P.NAME)=‘DB_BLOCK_SIZE‘
order by MB DESC;

TABLESPACE                      CONTENTS  SEGTYPE      EXTENTS     BLOCKS         MB
------------------------------- --------- --------- ---------- ---------- ----------
TEMP                            TEMPORARY LOB_DATA          48       6144         48
TEMP                            TEMPORARY LOB_DATA          48       6144         48
TEMP                            TEMPORARY LOB_INDEX          1        128          1
TEMP                            TEMPORARY LOB_INDEX          1        128          1

2-Exiting the session where are the TEMP segments will be freed completely.

10.2.0.4 and above
===============

In addition to the above approaches For 10.2.0.4 and above a new event 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. You can set this using alter system in the system level also.

alter session set events ‘60025 trace name context forever‘;

时间: 2024-08-06 03:01:55

How to Release the Temp LOB Space and Avoid Hitting ORA-1652 (文档 ID 802897.1)的相关文章

ORA-600 [729] &quot;UGA Space Leak&quot; (文档 ID 31056.1)

Note: For additional ORA-600 related information please read Note:146580.1PURPOSE:              This article discusses the internal error "ORA-600 [729]", what   it means and possible actions. The information here is only applicable   to the ver

Deploying JRE (Native Plug-in) for Windows Clients in Oracle E-Business Suite Release 12 (文档 ID 393931.1)

In This Document Section 1: Overview Section 2: Pre-Upgrade Steps Section 3: Upgrade and Configuration Section 4: Post-installation Steps Section 5: Known Issues Section 6: Appendices This document covers the procedure to upgrade the version of the J

Oracle Database Release Lifetime (文档 ID 742060.1)

Release Roadmap Release 12.2: New releases will be annual and the version will be the last two digits of the release year. The release originally planned as 12.2.0.2 will now be release 18, and the release originally planned as 12.2.0.3 will be relea

Oracle Database Release Update Introduction and FAQ (文档 ID 2285040.1)

Overview Beginning in July 2017, Oracle has transitioned to a more flexible and responsive strategy for the database software release process.  These changes only affect Database and Grid Infrastructure release 12.2 or later.  The primary goals of th

Spring Boot 2.2.2.RELEASE 版本中文参考文档【3.2 - 3.10】

Spring Boot 2.2.2.RELEASE版本中文文档持续更新中~如有需要获取参考文档文件,关注公众号JavaSo,回复“参考文档”即可. 3.2 结构化代码 Spring Boot不需要任何特定的代码布局即可工作.但是,有一些最佳做法会有所帮助. 3.2.1 使用“default”包 当一个类不包含引入包声明时,将其视为在默认包中.通常不建议使用默认包,应避免这种情况.对于使用@ ComponentScan,@ ConfigurationPropertiesScan,@ EntityS

Spring Framework 4.3.22.RELEASE Reference文档目录

<Spring Framework Reference Documentation 4.3.22.RELEASE> part I Spring Framework概述part II Spring Framework4.x的新特性part III 核心技术 7.IoC容器 8.Resources资源 9.校验.数据绑定.类型转换Validation, Data Binding, and Type Conversion 10.spring的EL表达式 11.spring AOP面向切面编程 12.

向量空间模型实现文档查询(Vector space model to realise document query)

xml中文档(query)的结构: <topic> <number>CIRB010TopicZH006</number> <title>科索沃難民潮</title> <question> 查詢科索沃戰爭中的難民潮情況,以及國際間對其採取的援助. </question> <narrative> 相關文件內容包括科省難民湧入的地點.人數,受安置的狀況,難民潮引發的問題,參與救援之國家與國際組織,其援助策略與行動內容

Codis 3.0 Release (密码验证) 群集部署文档

前言: Codis 3.x 由以下组件组成: Codis Server:基于 redis-2.8.21 分支开发.增加了额外的数据结构,以支持 slot 有关的操作以及数据迁移指令.具体的修改可以参考文档 redis 的修改. Codis Proxy:客户端连接的 Redis 代理服务, 实现了 Redis 协议. 除部分命令不支持以外(不支持的命令列表),表现的和原生的 Redis 没有区别(就像 Twemproxy). 对于同一个业务集群而言,可以同时部署多个 codis-proxy 实例:

关于临时表空间,在日常生产中会遇到的问题

Oracle临时表空间主要用来做查询和存放一些缓冲区数据.临时表空间消耗的主要原因是需要对查询的中间结果进行排序.在某些Oracle一体机,可能会进行大量的运算和排序,产生大量的缓冲区数据.这个时候就会对临时表空间产生压力,可能我们去看的时候查到临时表空间的使用率还远远没有到百分之百,但这些缓冲区数据的堆放不紧凑,高水位线这时候已经很高了,新的缓冲区数据进不来,应用程序会有错误. 查看临时表空间高水位线: SELECT d.tablespace_name "Name", TO_CHAR