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

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

  1. [转载]——Automatic Tuning of Undo_retention Causes Space Problems (文档 ID 420525.1)

    Automatic Tuning of Undo_retention Causes Space Problems (文档 ID 420525.1) 转到底部 In this Document   Sy ...

  2. Database Initialization Parameters for Oracle E-Business Suite Release 12 (文档 ID 396009.1)

    In This Document Section 1: Common Database Initialization Parameters For All Releases Section 2: Re ...

  3. 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 Configurati ...

  4. VS2010 release编译下进行调试,“当前不会命中任何断点,还没有为文档加载”问题解决方案

    在release模式下调试程序,经常出现"当前不会命中任何断点,还没有为文档加载"的问题,可尝试以下方法: 1. 属性 → 配置属性 → C/C++ → 常规 → 调试信息格式:选 ...

  5. release环境下,当前不会命中断点,还没有为该文档加载任何符号

    今天在release编译环境下出现了如标题所说的问题“ 当前不会命中断点,还没有为该文档加载任何符号”,在网上找了几个方法都没有解决我的问题,咨询了一下师傅,解决了,很简单,方法如下:右键--属性-- ...

  6. Spring Boot 2.2.2.RELEASE 版本中文参考文档【3.1】

    使用Spring Boot 本节将详细介绍如何使用Spring Boot.它涵盖了诸如构建系统,自动配置以及如何运行应用程序之类的主题.我们还将介绍一些Spring Boot最佳实践.尽管Spring ...

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

    Spring Boot 2.2.2.RELEASE版本中文文档持续更新中~如有需要获取参考文档文件,关注公众号JavaSo,回复“参考文档”即可. 3.2 结构化代码 Spring Boot不需要任何 ...

  8. Spring Framework 4.3.22.RELEASE Reference文档目录

    <Spring Framework Reference Documentation 4.3.22.RELEASE> https://docs.spring.io/spring/docs/4 ...

  9. ORA-01652: 无法通过 128 (在表空间 TEMP 中) 扩展 temp 段(EXP-00056: 遇到 ORACLE 错误 1652 ORA-01652: unable to extend temp segment by 128 in tablespace TEMP)

    数据库报 ORA-01652: 无法通过 128 (在表空间 TEMP 中) 扩展 temp 段 两种解决方式: 第一种) sql>select * from v$tempfile; 发现tem ...

随机推荐

  1. C#.NET vs2010中使用IrisSkin4.dll轻松实现WinForm窗体换肤功能

    IrisSkin2.dll是一款很不错的免费皮肤控件,利用它可以轻松的实现WinForm窗体换肤 然而IrisSkin2.dll只能在.NET Faremwork 4.0以及之前的版本使用,所以要在V ...

  2. memcached windowns 安装使用

    到csdn下载安装包吧,要不找我要,1033536868 安装: memcached -d install memcached -d start net start "Memcached S ...

  3. javascript util.js

    //根据Id获得页面元素 function $(para) {    return document.getElementById(para);} //创建一个新的元素function createE ...

  4. [web] 200 OK (from cache) 与 304 Not Modified

    为什么有的缓存是 200 OK (from cache),有的缓存是 304 Not Modified 呢?很简单,看运维是否移除了 Entity Tag.移除了,就总是 200 OK (from c ...

  5. ShopEX 4.8.5.81822 前台Getshell

    ShopEX 4.8.5.81822 前台Getshell 作者:unhonker   发布:2014-06-23 00:12   分类:漏洞公布   被撸:8,179次   抢沙发     利用方式 ...

  6. PHP使用1个crontab管理多个crontab任务

    http://www.binarytides.com/php-manage-multiple-cronjobs-with-a-single-crontab-entry/ In many php app ...

  7. 【jmeter】ANT批量执行Jmeter脚本

    一.环境准备: 1.Jdk1.6或以上:命令行输入:java -version,出现如下提示说明安装成功 2.ANT下载:http://ant.apache.org/bindownload.cgi 命 ...

  8. bzoj1173: [Balkan2007]Point

    Description 给出N个三维空间上的点. 问有多少条直线,这些直线上至少有三个点. Input 第一行给出数字N,N在[4,1000] 下面N行,每行三个数字,用于描述点的坐标,其值在[-10 ...

  9. bzoj4316: 小C的独立集

    Description 图论小王子小C经常虐菜,特别是在图论方面,经常把小D虐得很惨很惨. 这不,小C让小D去求一个无向图的最大独立集,通俗地讲就是:在无向图中选出若干个点,这些点互相没有边连接,并使 ...

  10. c# 对话框交换数据

    本例是一个管理联系人信息的小程序,程序有两个窗体,一个主窗体,在listview控件中显示联系人信息列表,一个对话框窗体,用来显示和修改 某个联系人的信息.通过主窗体的菜单命令,可以打开对话框,并把主 ...