CleanUp Temporary Segments Occupying Permanent Tablespace

本文介绍如何识别和清理Oracle数据库中永久表空间内的大型临时段。这些临时段可能由DDL操作创建,并占用实际磁盘空间。文章提供了查找这些临时段的SQL查询,并介绍了两种清理方法:使用事件DROP_SEGMENTS和通过标记临时段为损坏再删除。

By Saurabh Sood, July 3, 2009 12:42 pm

 

There are situations when we see “temporary segments” in permanent tablespaces hanging around and not getting cleaned up.

These temporary segments in permanent tablespace can be created by DDL operations like CTAS and “alter index..rebuild” because

the new object is created as a temporary segment in the target tablespace and when the DDL action finishes it will be changed to permanent type.

These temporary segments take actual disk space when SMON fails to perform. its assigned job to cleanup stray temporary segments.

Following query finds out these segments:

 SQL > select tablespace_name, owner, sum(bytes/1024/1024) from dba_segments

where segment_type = 'TEMPORARY' group by tablespace_name, owner;

 

TABLESPACE_NAME     OWNER          SEGMENT_NAME     SUM(BYTES/1024/1024)

------------------- ------------   ------------     --------------------

xxxx_DATA           SYS              123.8365          137706

BDEPST_INDEX        SYS              345.8756            8910

KMRPT_DATA          SYS                345.87       25284.875

BILL_INDEX          SYS                                   .25

DSS_DATA            SYS                                   798

MRKT_INDEX          SYS                                   208

SPCT_DATA           SYS                              69642.25

SPCT_INDEX          SYS                              956.4375

Here we can see that tablespace KMRPT_DATA, SPCT_INDEX and SPCT_DATA have large temporary segments.

To know if any DDL is active which can create temporary segments we can use the following:

SQL> conn / as sysdba

SQL> select owner FROM dba_segments WHERE segment_name='345.87';

SQL> select pid from v$process where username='owner from above query';

SQL> alter session set tracefile_identifier='TEMPORARY_SEGMENTS';

SQL> oradebug setorapid

SQL> oradebug dump errorstack 3

SQL > oradebug tracefile_name

It will give you the tracefile name, open that file and check for the “current sql”

If it is a DDL like CTAS or index rebuild, then wait for the operation to complete. If there is no pid

returned then these segments are “stray segements” and needs to cleaned up manually.

There are two ways to force the drop of temporary segments:

1. Using event DROP_SEGMENTS

2. Corrupting the segments and dropping these corrupted segments.

1. Using DROP_segments:

Find out the tablespace number (ts#) which contains temporary segments:

SQL> select ts# from sys.ts$ where name = 'tablespace name';

 

Suppose it comes out to be 10, use the following command to cleanup temporary segments:

 

SQL> alter session set events 'immediate trace name DROP_SEGMENTS level 11';

 

level is ts#+1 i.e 10+1=11 in this case.

2. Corrupting temporary segments for drop:

For this following procedures are used:

- DBMS_SPACE_ADMIN.TABLESPACE_VERIFY

- DBMS_SPACE_ADMIN.SEGMENT_CORRUPT

- DBMS_SPACE_ADMIN.SEGMENT_DROP_CORRUPT

Verify the tablespace that contains temporary segments (In this case it is KMRPT_DATA)

SQL> exec DBMS_SPACE_ADMIN.TABLESPACE_VERIFY('KMRPT_DATA');

Corrupt the temporary segments in tablespace KMRPT_DATA

SQL> select 'exec DBMS_SPACE_ADMIN.SEGMENT_CORRUPT(' || chr(39) || tablespace_name || chr(39) || ',' || HEADER_FILE || ',' || HEADER_BLOCK || ');'  from dba_segments where SEGMENT_TYPE like 'TEMP%' and tablespace_name = 'KMRPT_DATA';

Drop the corrupted temporary segments

SQL> select 'exec DBMS_SPACE_ADMIN.SEGMENT_DROP_CORRUPT (' || chr(39) || tablespace_name || chr(39) || ',' || HEADER_FILE || ',' || HEADER_BLOCK || ');' from dba_segments where SEGMENT_TYPE like 'TEMP%' and tablespace_name = 'KMRPT_DATA';

Verify the tablespace again to update the new dictionary information:

SQL> EXECUTE DBMS_SPACE_ADMIN.TABLESPACE_VERIFY('KMRPT_DATA');

This will remove temporary segments from permanent tablespace.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10173379/viewspace-623838/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10173379/viewspace-623838/

### Cleanup Tool 的官方版本获取 Cleanup 工具通常用于清理文件、优化磁盘空间以及管理不必要的数据。然而,在提供的引用中并未提及具体的 Cleanup Tool 或其下载方式[^1]。因此,以下是关于如何查找并安全下载此类工具的一般建议: #### 如何确认 Cleanup Tool 的可信来源? 确保从官方网站或其他可信赖的技术平台(如 Ninite、Softpedia 等)下载任何 IT 软件是非常重要的。这些网站会提供经过验证的安全链接,并附带详细的说明文档。 对于特定的 Cleanup Tools,例如 CCleaner 或其他类似的程序,可以从以下位置获得: - **CCleaner**: 可通过 Piriform 官网或者 Avast 收购后的页面访问最新稳定版。 - **Disk Cleanup Utility**: Windows 自带的功能可以通过运行 `cleanmgr` 命令启动,无需额外安装第三方应用。 如果目标是 Linux 平台上的类似功能,则可以考虑使用命令行工具如 `bleachbit` 来实现更深层次的数据清除操作[^4]。 #### 配合 Depot_Tools 使用场景分析 虽然 depot_tools 主要服务于 Chromium 开发环境构建与维护工作流自动化需求,但它并不直接关联到常规意义上的系统垃圾回收类应用程序上。不过借助脚本定制化能力,完全可以编写适合项目需求的小型辅助模块来完成相应任务。 ```bash #!/bin/bash # Example script demonstrating integration possibilities between custom scripts and existing utilities. echo "Running pre-cleanup checks..." rm -rf /path/to/temporary/files/* find . -type f -name "*.tmp" -delete ``` 上述示例展示了如何利用 shell 编程语言创建简易版“cleanup tool”,针对指定目录下的临时文件执行批量删除动作。 #### 关于 Git Mergetool 扩展性讨论 当涉及到源码版本控制过程中产生的冲突解决环节时,合理配置合适的差异比较器显得尤为重要[^3]。尽管 Beyond Compare 是一个非常强大的选项之一,但用户同样可以根据实际偏好替换为其它图形界面友好的解决方案。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值