EBS R12 Demo 瘦身
Creation Time: 2011-03-05
LastUpdate Date: 2011-03-05
Author: 商云方
—————————————————————————————-
EBS R12 Demo版安装后有236G(linux显示这么大,那么在windows下需要创建约260G 左右的虚拟硬盘),尝试进行瘦身操作,稍微压缩掉一些空间占用。
一 、Demo版中有很多历史数据
2.2 利用 Joanne S. Davis 对EBS数据清理方面的总结,对历史数据进行清理:
2.2.1 FA模块的清理
FA 模块有两类归档和清理程序:
1)批量添加(Mass Additions)
2)折旧和调整事务处理记录(Depreciation and Adjustment Transaction records )
批量添加:
Delete Mass Additions 程序把成批添加信息归档到一个归档表,然后就可以被清除。
标准:Delete Mass Additions 程序会删除”已经删除或已过帐队列“中的成批传输信息,归档到审计跟踪表。
操作指导:
1. (B) Archive
2. Export the archive tables
3. Requery the archive
4. (B) Purge
5. Drop temporary archive tables
这个并发程序实际就是删除 FA.FA_DELETED_MASS_ADDITIONS 表中的数据;
select count(*) from FA_DELETED_MASS_ADDITIONS –507条
select blocks from dba_segments where segment_name=’FA_DELETED_MASS_ADDITIONS’; –16个block
–没必要进一步做碎片整理。因为即便把这些数据全部删除,并做Move, 索引重建后该表占用的block也不会少于16个;
2.2.n) 总帐模块的数据清理
Consolidation Audit Data:当您在审核模式运行巩固Consolidation,总帐模块将维护一个总帐的综合审计报告,未映射的子账户报告,以及失效的父帐户报告的审计线索。在运行这些报告后,您可以清除GL_CONSOLIDATION_AUDIT表中的支持源数据。
select count(*) from GL_CONSOLIDATION_AUDIT , 0 条记录
–GL_CONSOLIDATION_AUDIT 表碎片整理
由于该表空间APPS_TS_INTERFACE的空间管理模式不是ASSM,无法做Shrink,只能用Move tablespace+索引rebuild的方式进行碎片整理:
select count(*) from GL_CONSOLIDATION_AUDIT –0条
select blocks from dba_segments where segment_name=’GL_CONSOLIDATION_AUDIT’; –16个block
alter table GL.Gl_Consolidation_Audit move tablespace user_data;
alter table GL.Gl_Consolidation_Audit move tablespace APPS_TS_INTERFACE;
alter index GL.GL_CONSOLIDATION_AUDIT_N1 rebuild;
alter index GL.GL_CONSOLIDATION_AUDIT_N2 rebuild;
select blocks from dba_segments where segment_name=’GL_CONSOLIDATION_AUDIT’; –16个Block 这16个block是表初始化就有的吗?
2.2.n) OM模块清除订单和报价单
先运行Order Purge Selection ,选择要清除的订单,比如这里选择条件是2007-12-31 前订单,产生一个订单集。然后再运行purge Set清除这个订单集。
–销售订单
select count(*) from oe_order_headers_all –10923
select blocks from dba_segments where segment_name=’OE_ORDER_HEADERS_ALL’; –560
点【Submit Purge】提交请求,进行删除:
–Puge后
select count(*) from oe_order_headers_all –8408
select blocks from dba_segments where segment_name=’OE_ORDER_HEADERS_ALL’; –560
select * from oe_order_headers_all oh where oh.order_number=’207260′ –无记录,说明确实被删除了
select * from oe_order_headers_all oh where oh.order_number=’777809′ –有记录,说明puge set中非“Closed"状态的记录是不会被删除的。
–碎片整理前APPS_TS_TX_DATA的Free Mb=1868:
–进行Order表碎片整理
alter table ONT.OE_ORDER_LINES_ALL shrink space;
alter table ONT.OE_ORDER_HEADERS_ALL shrink space;
–整理后:FreeMB=1879; 释放了11M空间;
select blocks from dba_segments where segment_name=’SO_LINE_APPROVALS’; –16 ,无需整理
select blocks from dba_segments where segment_name=’SO_PICKING_LINES_ALL’; –80,需要整理一下
–进行 SO_PICKING_LINES_ALL 表的碎片整理
整理前:
APPS_TS_ARCHIVE 是ASSM模式的,可以用Shrink整理:
整理:
alter table OE.SO_PICKING_LINES_ALL enable row movement;
alter table OE.SO_PICKING_LINES_ALL shrink space;
alter table OE.SO_PICKING_HEADERS_ALL enable row movement;
alter table OE.SO_PICKING_HEADERS_ALL shrink space;
alter table OE.SO_PICKING_LINE_DETAILS enable row movement;
alter table OE.SO_PICKING_LINE_DETAILS shrink space;
alter table OE.SO_PICKING_BATCHES_ALL enable row movement;
alter table OE.SO_PICKING_BATCHES_ALL shrink space;
整理后:没啥变化,看来原来就没啥碎片;
在订单清除程序中,还有一些跟订单相关的表中数据也会被清除,但估计数据量较小,也没啥碎片。此处略,想了解还有哪些表中的数据被清除可查看OEXPURGE这个package;
总结:本次销售订单清除了2500多条已经Closed的记录,碎片整理后节省11M空间;
如果想进一步清除,就要把系统中现有的可以关闭的销售订单都关闭掉,然后才能进一步清除。
=============
报价单清除:
生成puge set:
只有一条可清除:
submit purge , 成功puge了一条记录:
2.2.n) OM模块清除导入的信贷风险记录
此程序实际是删除 OE_CREDIT_SUMMARIES 表中balance_type =18的记录,目前不存在这样的记录。
2.2.n) OM模块清除订单处理过程中的历史消息
alter table ONT.OE_PROCESSING_MSGS enable row movement;
alter table ONT.OE_PROCESSING_MSGS shrink space;
alter table ONT.OE_PROCESSING_MSGS_TL enable row movement;
alter table ONT.OE_PROCESSING_MSGS_TL shrink space;
整理前:
整理后:
释放了3M空间;
2.2.n) Shipping模块清除例外日志信息
先close 再purge; Purge了7条记录
select blocks from dba_segments where segment_name=’WSH_EXCEPTIONS’ –86 可以整理一下
alter table WSH.WSH_EXCEPTIONS enable row movement;
alter table WSH.WSH_EXCEPTIONS shrink space;
整理后 FreeMB 从1881变成1882,节省了1M空间;
2.2.n) INV模块清除 Transaction(逐个切换一次库存组织运行一次)
此程序删除已经关闭的库存会计期的如下表中的记录:
MTL_MATERIAL_TRANSACTIONS
MTL_MATERIAL_TXN_ALLOCATIONS
MTL_TRANSACTION_LOT_NUMBERS
MTL_UNIT_TRANSACTIONS
MTL_TRANSACTION_ACCOUNTS
查询数据库发现,在已经关闭的会计期中,相应的库存组织中的记录甚少,可能oracle 自己清除过。
清理碎片
alter table INV.MTL_MATERIAL_TRANSACTIONS enable row movement;
alter table INV.MTL_MATERIAL_TRANSACTIONS shrink space;
耗时60分钟:
整理后FreeMB从 1882 M 变成 2179M ,节省空间297M;
select blocks from dba_segments where segment_name=’MTL_UNIT_TRANSACTIONS’; –1344
alter table INV.MTL_UNIT_TRANSACTIONS enable row movement;
alter table INV.MTL_UNIT_TRANSACTIONS shrink space;
MTL_UNIT_TRANSACTIONS 整理后节省5M空间;
MTL_MATERIAL_TXN_ALLOCATIONS 无需整理 , MTL_TRANSACTION_LOT_NUMBERS整理后没有节省空间;
select blocks from dba_segments where segment_name=’MTL_TRANSACTION_ACCOUNTS’; –63408
alter table INV.MTL_TRANSACTION_ACCOUNTS enable row movement;
alter table INV.MTL_TRANSACTION_ACCOUNTS shrink space;
select blocks from dba_segments where segment_name=’MTL_TRANSACTION_ACCOUNTS’; –23440
MTL_TRANSACTION_ACCOUNTS 整理后节省了2496-2184=312M空间;
2.2.n) INV模块清除标准成本历史记录
此程序需要逐个组织运行,比较麻烦;可考虑直接参考清除程序,以脚本清除:
declare
I_UPDATE_ID number;
begin
select max(cost_update_id) into I_UPDATE_ID from cst_cost_updates;
DELETE FROM cst_std_cost_adj_values
WHERE cost_update_id <= I_UPDATE_ID;
DELETE FROM cst_standard_costs C
WHERE cost_update_id <= I_UPDATE_ID;
DELETE FROM cst_elemental_costs
WHERE cost_update_id <= I_UPDATE_ID;
DELETE FROM cst_cost_updates C
WHERE cost_update_id <= I_UPDATE_ID
AND NOT EXISTS (
SELECT ‘X’
FROM cst_standard_costs
WHERE cost_update_id = C.cost_update_id
);
end;
commit;
alter table BOM.CST_STD_COST_ADJ_VALUES move tablespace user_data;
alter table BOM.CST_STD_COST_ADJ_VALUES move tablespace APPS_TS_INTERFACE;
alter index BOM.CST_STD_COST_ADJ_VALUES_N1 rebuild;
alter index BOM.CST_STD_COST_ADJ_VALUES_N2 rebuild;
alter index BOM.CST_STD_COST_ADJ_VALUES_N3 rebuild;
alter index BOM.CST_STD_COST_ADJ_VALUES_N4 rebuild;
节省 368-295=73M
alter table BOM.CST_STANDARD_COSTS enable row movement;
alter table BOM.CST_STANDARD_COSTS shrink space;
节省 2M
alter table BOM.CST_ELEMENTAL_COSTS enable row movement;
alter table BOM.CST_ELEMENTAL_COSTS shrink space;
节省 3M
alter table BOM.CST_COST_UPDATES enable row movement;
alter table BOM.CST_COST_UPDATES shrink space;
节省0M
2.2.n) INV模块清除成本信息
比较麻烦,几十个库存组织,每个组织都有几十种成本类型,全部清除得提交几百次请求,太麻烦了,搞了一个库存组织后就买有再继续搞。
sql>select count(1) from CST_ITEM_COST_DETAILS
sql>158230
===============================
下面这段代码可以清除,所以用户定义的成本类型及其成本信息:
declare
l_sysadmin_userid number;
begin
select fu.user_id into l_sysadmin_userid from fnd_user fu where fu.user_name=’SYSADMIN’;
for cur_cost_type in (select cost_type_id
from CST_COST_TYPES
where FROZEN_STANDARD_FLAG != 1
and created_by != 1
) loop
begin
DELETE FROM CST_RESOURCE_COSTS
WHERE COST_TYPE_ID = cur_cost_type.cost_type_id ;
DELETE FROM CST_RESOURCE_OVERHEADS
WHERE COST_TYPE_ID = cur_cost_type.cost_type_id;
DELETE FROM CST_DEPARTMENT_OVERHEADS
WHERE COST_TYPE_ID = cur_cost_type.cost_type_id;
DELETE FROM CST_COST_TYPE_HISTORY
WHERE COST_TYPE_ID = cur_cost_type.cost_type_id;
DELETE FROM CST_ITEM_COST_DETAILS
WHERE COST_TYPE_ID = cur_cost_type.cost_type_id;
DELETE FROM CST_ITEM_COSTS
WHERE COST_TYPE_ID = cur_cost_type.cost_type_id;
UPDATE CST_COST_TYPES
SET DISABLE_DATE = SYSDATE,
LAST_UPDATE_DATE = SYSDATE,
LAST_UPDATED_BY = l_sysadmin_userid
WHERE COST_TYPE_ID = cur_cost_type.cost_type_id;
end;
end loop;
end;
===========================
数据量比较小,不用清除;
这里有篇文章对成本信息清除讲得比较详细:http://erplife.blog.sohu.com/79729842.html
2.2.n) 系统管理员:删除工作流运行时历史记录:
select count(1) from WF_ACTIVITY_ATTR_VALUES –66725
select count(1) from WF_ACTIVITY_TRANSITIONS –86098
select count(1) from WF_PROCESS_ACTIVITIES –72976
select count(1) from WF_ACTIVITY_ATTRIBUTES_TL –64658
select count(1) from WF_ACTIVITY_ATTRIBUTES –32329
select count(1) from WF_ACTIVITIES_TL –70072
select count(1) from WF_ACTIVITIES –35036
select count(1) from WF_NOTIFICATION_ATTRIBUTES –1592550
select count(1) from wf_comments –145244
select count(1) from WF_NOTIFICATIONS –143924
select count(1) from WF_ITEM_ACTIVITY_STATUSES_H –175769
select count(1) from WF_ITEM_ACTIVITY_STATUSES –902070
select count(1) from WF_ITEM_ATTRIBUTE_VALUES –6232267
select count(1) from WF_ITEMS –171932
select count(1) from WF_LOCAL_USER_ROLES –99055
select count(1) from WF_USER_ROLE_ASSIGNMENTS –99424
select count(1) from WF_LOCAL_USER_ROLES –99055
select count(1) from WF_USER_ROLE_ASSIGNMENTS –99424
select count(1) from WF_LOCAL_ROLES –79131
挑几个大的做shrink:
select blocks from dba_segments where segment_name=’WF_NOTIFICATION_ATTRIBUTES’; –25776
alter table APPLSYS.WF_NOTIFICATION_ATTRIBUTES enable row movement;
alter table APPLSYS.WF_NOTIFICATION_ATTRIBUTES shrink space;
select blocks from dba_segments where segment_name=’WF_NOTIFICATION_ATTRIBUTES’; –23680
select blocks from dba_segments where segment_name=’WF_ITEM_ATTRIBUTE_VALUES’; –100336
alter table APPLSYS.WF_ITEM_ATTRIBUTE_VALUES enable row movement;
alter table APPLSYS.WF_ITEM_ATTRIBUTE_VALUES shrink space;
select blocks from dba_segments where segment_name=’WF_ITEM_ATTRIBUTE_VALUES’; –79408
select blocks from dba_segments where segment_name=’WF_ITEMS’; –1968
alter table APPLSYS.WF_ITEMS enable row movement;
alter table APPLSYS.WF_ITEMS shrink space;
select blocks from dba_segments where segment_name=’WF_ITEMS’; –1536
节省了130M
alter table APPLSYS.WF_ITEM_ACTIVITY_STATUSES enable row movement;
alter table APPLSYS.WF_ITEM_ACTIVITY_STATUSES shrink space;
节省80M
其他小表节省10M
2.2.n)系统管理员:清除并发程序和并发管理器的日志
二、Demo版安装后有些表空间的利用率很低,先查处利用率小于80%的数据文件,进行Resize, Resize后的大小为:已使用大小+ 原大小×10%;
1.1 使用此语句查询后发现,大约有15G的空间可以释放掉。
select sum(大小M),sum(Resizeto) from
(
select 物理文件名,大小M,已使用M, 已使用M/大小M 利用率,已使用M + 大小M*0.1 Resizeto from
(
select
b.file_name 物理文件名,
b.tablespace_name 表空间,
b.bytes/1024/1024 大小M,
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用M
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.bytes
)
where 已使用M/大小M <0.8
)
–生成批量resize的脚本:
select ‘alter database datafile ”’ || 物理文件名 ||”’ resize ‘ || ceil(RESIZEto) || ‘M;’ from
(
select 物理文件名,大小M,已使用M, 已使用M/大小M 利用率,已使用M + 大小M*0.1 Resizeto from
(
select
b.file_name 物理文件名,
b.tablespace_name 表空间,
b.bytes/1024/1024 大小M,
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用M
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.bytes
)
where 已使用M/大小M <0.8
)
Resize 后linux下显示为 209G, windows下 新建虚拟硬盘 220G,把oracle目录复制到新硬盘,复制完成没有错误;但新硬盘可用空间为0;没办法,把虚拟硬盘expand到230G,然后在linux下重新调整分区大小。
[root@syfdemo ~]# fdisk /dev/sdc
The number of cylinders for this disk is set to 30024.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sdc: 246.9 GB, 246960619520 bytes
255 heads, 63 sectors/track, 30024 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 28719 230685336 83 Linux
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sdc: 246.9 GB, 246960619520 bytes
255 heads, 63 sectors/track, 30024 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 28719 230685336 83 Linux
Command (m for help): d
Selected partition 1
Command (m for help): p
Disk /dev/sdc: 246.9 GB, 246960619520 bytes
255 heads, 63 sectors/track, 30024 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-30024, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-30024, default 30024): 30024
Command (m for help): p
Disk /dev/sdc: 246.9 GB, 246960619520 bytes
255 heads, 63 sectors/track, 30024 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 30024 241167748+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@syfdemo ~]# fdisk /dev/sdc
The number of cylinders for this disk is set to 30024.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sdc: 246.9 GB, 246960619520 bytes
255 heads, 63 sectors/track, 30024 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 30024 241167748+ 83 Linux
Command (m for help): q
[root@syfdemo ~]#
[root@syfdemo ~]# resize2fs -p /dev/sdc1 241167748
resize2fs 1.35 (28-Feb-2004)
The containing partition (or device) is only 60291937 (4k) blocks.
You requested a new size of 241167748 blocks.
[root@syfdemo ~]# e2fsck -f /dev/sdc1
e2fsck 1.35 (28-Feb-2004)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdc1: 800563/28835840 files (0.4% non-contiguous), 54814204/57671334 blocks[root@syfdemo ~]# resize2fs -p /dev/sdc1
resize2fs 1.35 (28-Feb-2004)
Resizing the filesystem on /dev/sdc1 to 60291937 (4k) blocks.
Begin pass 1 (max = 80)
Extending the inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/sdc1 is now 60291937 blocks long.
[root@syfdemo ~]# mount /dev/sdc1 /d02
[root@syfdemo ~]#
调整完毕后, EBSR12.1.3 中英文版的vmdk为230G (里面还留有可用空间为大约10G,足以支持并发程序产生的日志之类的需求了,另外有些特殊试验需要扩展表空间也是可以的)。
这样子瘦身其实也就是减小了大约20G,效果并不理想,以后有时间再搞,待续。。。。
其他参考:
1、(如果要看哪些表使用了比较大的空间,可以先进行分析后从数据字典统计):
对所有表和索引进行一次分析收集(过程比较长,大约15小时,试验结果表明即便不分析对于统计所有表和索引所占的空间大小差异也不大,所以也可以不统计)
begin
–分析所有表:analyze table TABLENAME compute statistics
for cur_item in (select owner, table_name from dba_tables where owner<>’SYS’ and last_analyzed < sysdate -1) loop
begin
dbms_stats.gather_table_stats(cur_item.owner,cur_item.table_name);
exception
when others then
dbms_output.put_line(‘Analyze Table Exception:’||sqlerrm);
end;
end loop;
–分析所有索引:analyze index INDEXNAME estimate statistics
for cur_item in (select owner, index_name from dba_indexes where owner<>’SYS’ and last_analyzed < sysdate -1) loop
begin
dbms_stats.gather_index_stats(cur_item.owner,cur_item.index_name);
exception
when others then
dbms_output.put_line(‘Analyze Index Exception:’||sqlerrm);
end;
end loop;
end;
2、Joanne S. Davis 的EBS清理总结文档附件 achieve_and_purge
3、清理后进行碎片整理,方有效果;
整理前:
APPS_TS_TX_DATA
SIZE=58669M
Free=1705M
Userd Mb=56963MB
对销售订单行表碎片整理:
alter table ONT.OE_ORDER_LINES_ALL enable row movement;
alter table ONT.OE_ORDER_LINES_ALL shrink space;
整理后
APPS_TS_TX_DATA
SIZE=58669M
Free=1852M
Userd Mb=56816MB
销售订单行表占用空间自由几十M,但由于以前删除了很多数据,碎片多,整理效果还是很明显的。
alter table GL.GL_BALANCES enable row movement;
alter table GL.GL_BALANCES shrink space;
这个Shrink要900多秒,时间很长;
整理后
APPS_TS_TX_DATA
SIZE=58669M
Free=1869M
Userd Mb=56800MB
GL_BALANCES 表本身很大,占用空间1G多,但由于删除很少,碎片很少,虽然话了15分钟整理,但整理后效果不明显。
总结:瘦身的基本思路是:
1、进行EBS清理,删除不需要的数据。
2、进行表的碎片整理,为Resize做准备。
3、对数据库文件做Resize,缩减空间。
关于作者:
昵称:Jack.shang 档案信息:jack.shang 一位从技术走向管理,再从管理走向市场的普通行者 联系方式:你可以通过syfvb@hotmail.com联系作者 点击查看Jack.shang发表过的所有文章... 本文永久链接: http://blog.retailsolution.cn/archives/2748 |
对本文的评价:
常用SQL :查看表空间的使用率:
select df.tablespace_name “表空间名”,
totalspace “总空间M”,
freespace “剩余空间M”,
round((1 – freespace / totalspace) * 100, 2) “使用率%”
from (select tablespace_name, round(sum(bytes) / 1024 / 1024) totalspace
from dba_data_files
group by tablespace_name) df,
(select tablespace_name, round(sum(bytes) / 1024 / 1024) freespace
from dba_free_space
group by tablespace_name) fs
where df.tablespace_name = fs.tablespace_name;
查看表空间中的可用空间:
select tablespace_name,sum(bytes)/1024/1024 Free空间M, max(bytes)/1024/1024 最大连续空间M ,count(*) from dba_free_space group by tablespace_name;
1、表占用空间:select segment_name, sum(bytes)/1024/1024 Mbytese from dba_segments where segment_type=’TABLE’ group by segment_name;
2、索引占用空间:select segment_name ,sum(bytes)/1024/1024 from dba_segments where segment_type =’INDEX’ group by segment_name;
3、分区表TABLE PARTITION占用空间:select segment_name,sum(bytes)/1024/1024 Mbytes from dba_segments where segment_type=’TABLE PARTITION’ group by segment_name;
转贴::
Shrink space合并表的碎片
一般表里有碎片我们都采用alter table table_name move tablespace_name,或者exp,drop table table_name,imp的2种方式10G给我们其他的方法.下面我来试一吧
用Shrink Space收缩Oracle数据段
在oracle中可以使用alter table table_name shrink space收缩表,使用shrink有两个前提条件:
1、表必须启用row movement
2、表段所在表空间的段空间管理(segment space management)必须为auto
实验如下:
–建立一个segment space management auto表空间
SQL> create tablespace ts_auto datafile ‘d:/oracle/product/10.2.0/oradata/orcl/ts_auto.dbf’ size 100m
extent management local segment space management auto;
表空间已创建。
–建议测试表
SQL> create table table_auto as select * from dba_objects;
表已创建。
–查看shrink前的块数量
SQL> select blocks from dba_segments where segment_name=’table_auto’;
BLOCKS
———-
768
–delete数据后,空间占用没有变化
SQL> delete from table_auto;
已删除50390行。
SQL> commit;
提交完成。
SQL> select blocks from dba_segments where segment_name=’table_auto’;
BLOCKS
———-
768
–直接收缩,提示必须启动row movement选项
SQL> alter table table_auto shrink space;
alter table table_auto shrink space
*
第 1 行出现错误:
ORA-10636: ROW MOVEMENT is not enabled
SQL> alter table table_auto enable row movement;
表已更改。
–收缩成功,空间已经释放
SQL> alter table table_auto shrink space;
表已更改。
SQL> select blocks from dba_segments where segment_name=’table_auto’;
BLOCKS
———-
8
–shrink不能在segment space management manaual的表空间的段上执行