Oracle数据库碎片整理
段的碎片整理
[日期:2007-05-27]
来源:Linux公社
作者:Linux
[字体:大 中 小]
5、段的碎片整理
我们知道,段由范围组成。在有些情况下,有必要对段的碎片进行整理。要查看段的有关信息,可查看数据字典 dba_segments ,范围的信息可查看数据字典 dba_extents 。如果段的碎片过多, 将其数据压缩到一个范围的最简单方法便是用正确的存储参数将这个段重建,然后将旧表中的数据插入到新表,同时删除旧表。这个过程可以用 Import/Export (输入 / 输出)工具来完成。
Export ()命令有一个(压缩)标志,这个标志在读表时会引发 Export 确定该表所分配的物理空间量,它会向输出转储文件写入一个新的初始化存储参数 -- 等于全部所分配空间。若这个表关闭, 则使用 Import ()工具重新生成。这样,它的数据会放入一个新的、较大的初始段中。例如:
exp user/password file=exp.dmp compress=Y grants=Y indexes=Y
tables=(table1,table2);
若输出成功,则从库中删除已输出的表,然后从输出转储文件中输入表:
imp user/password file=exp.dmp commit=Y buffer=64000 full=Y
这种方法可用于整个数据库。
以上简单分析了 Oracle 数据库碎片的产生、计算方法及整理,仅供参考。数据库的性能优化是一项技术含量高,同时又需要有足够耐心、认真细致的工作。 对数据库碎片的一点探讨,
下面是一种如何自动处理表空间碎片的代码,希望对上大家看上文有用
Coalesce Tablespace Automatically
This technique comes from Sandeep
Naik, a database administrator
for GSXXI, Inc. in New York City, New York
Here is a handy script which can be
scheduled to automatically run
and coalesces the tablespaces.
This script is designed to run in NT
but can be run in any operating system
by slight modifications in the path where the file spools
from the SQLPLUS environment.
It assumes that the user who runs the script
has priviledges to view the data dictionary.
Start of code
--------------------------------------
sqlplus /
prompt this script will coalesce the
tablespace automatically
set verify off;
set termout off;
set head off;
spool c: empcoalesce.log
select alter tablespace
||TABLESPACE_NAME|| coalesce ;
from DBA_FREE_SPACE_COALESCED where
PERCENT_EXTENTS_COALESCED <100
or PERCENT_BLOCKS_COALESCED<100 ;
spool off;
@ c: empcoalesce.log
set head on;
set termout on;
set verify on;
prompt Tablespaces are coalesced successfully