ORACLE中表空间和表碎片的示例分析

网友投稿 378 2024-01-05

ORACLE中表空间和表碎片的示例分析

这篇文章主要为大家展示了“ORACLE中表空间和表碎片的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“ORACLE中表空间和表碎片的示例分析”这篇文章吧。

表空间碎片率

idle> select a.tablespace_name,sqrt(max(a.blocks)/sum(a.blocks))*(100/sqrt(sqrt(count(a.blocks)))) FSFIfrom dba_free_space a,dba_tablespaces b wherea.tablespace_name=b.tablespace_name and b.contents not in (TEMPORARY,UNDO) group by a.tablespace_name  order by 2; TABLESPACE_NAME                      FSFI ------------------------------ ---------- EAM2.57604251ALM                            20.1734462SYSAUX                         22.2842767SYSTEM                         23.7809729USERS                           53.439579RECCAT                                100ARCH                                  1007rows selected. idle>123456789101112131415161718192021

ORACLE中表空间和表碎片的示例分析

数字越小,表空间碎片较多,当小于30%的时候说明碎片程度很可观了。

按照表空间显示连续的空闲时间

引用官方的一段话:

The ideal situation is to have one large free extent in your tablespace. The more extents of free space there are in the tablespace, the more likely you will run into fragmentation problems. The size of the free extents is also very important. If you have a lot of small extents (too small for any next extent size) but the total bytes of free space is large, then you may want to consider defragmentation options.

脚本中统计了连续空间及对连续空间求和,当表中的总的free空间很大时,但有很多小块,说明碎片化越严重。

======== Script : tfstsfgm ========SET ECHO off  REM NAME:TFSTSFRM.SQL REM USAGE:"@path/tfstsfgm" REM ------------------------------------------------------------------------ REM REQUIREMENTS:  REM    SELECT ONDBA_FREE_SPACEREM ------------------------------------------------------------------------  REM PURPOSE:  REM    The following is a script that will determine how many extents  REM    of contiguous free space you have in Oracle as well astheREM total amount of free space you have in each tablespace. From  REMthese results you can detect how fragmented yourtablespace is.   REM    REM    The ideal situation is to have one large free extent in your   REMtablespace. The more extentsof free space there are in the   REM    tablespace, the more likely you  will run into fragmentation   REMproblems. Thesize of the free extents is also  very important.   REM    If you have a lot ofsmall extents (too smallfor any next   REM    extent size) but the total bytes of free space is largethen  REM    you may want to considerdefragmentation options.REM ------------------------------------------------------------------------  REMDISCLAIMER:REM    This script is provided for educational purposes only. It is NOT  REM    supported by OracleWorld Wide Technical Support.REM    The script has been tested and appears to work as intended.  REM    You should always run newscriptson a test instance initially.  REM ------------------------------------------------------------------------ REM Main text of script followscreate table SPACE_TEMP (     TABLESPACE_NAME        CHAR(30),     CONTIGUOUS_BYTESNUMBER)    /    declare      cursor query is select *              from dba_free_space                      order bytablespace_name, block_id;      this_row        query%rowtype;      previous_row    query%rowtype;    total           number;begin      open query;      fetch query into this_row;      previous_row := this_row;      total := previous_row.bytes;      loop     fetch query into this_row;         exit when query%notfound;         if this_row.block_id = previous_row.block_id + previous_row.blocks then            total := total + this_row.bytes;insert into SPACE_TEMP (tablespace_name)                      values(previous_row.tablespace_name);         elseinsert into SPACE_TEMP values(previous_row.tablespace_name,                   total);            total := this_row.bytes;end if;   previous_row := this_row;      end loop;      insert intoSPACE_TEMPvalues (previous_row.tablespace_name,                               total);   end;   .    /set pagesize 60   set newpage 0   set echo off    ttitle center Contiguous Extents Report  skip 3   break on "TABLESPACE NAME" skip page duplicate    spool contig_free_space.lis    rem    column "CONTIGUOUS BYTES"       format 999,999,999   column "COUNT"                  format 999   column "TOTAL BYTES"            format 999,999,999   column "TODAY"   noprint new_value new_today format a1    rem    select TABLESPACE_NAME  "TABLESPACE NAME",           CONTIGUOUS_BYTES "CONTIGUOUS BYTES"   from SPACE_TEMP    where CONTIGUOUS_BYTES is not null   order by TABLESPACE_NAME, CONTIGUOUS_BYTES desc;   selecttablespace_name,count(*) "# OF EXTENTS",             sum(contiguous_bytes) "TOTAL BYTES"    from space_temp    group bytablespace_name;   spool offdrop table SPACE_TEMP    /   1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798

表空间级别整理方法

对于ASSM管理的表空间,一般都是由smon进程自动整理,前提是表空间的pctincrease值为非0,可以将表空间的缺省存储参数pctincrease改为非0,一般将其设为1。如修改temp表空间的pctincrease属性:alter tablespace temp default storage(pctincrease 1); 这样就可以自动整理表空间级别的碎片整理了。

如果对于字典管理的表空间,可以用下面的命令进行整理: 

sql> alter tablespace <表空间名> collesce;

表级别碎片整理方法

1.首选shrinkSQL> alter table t1 enable row movement; --打开行移动表已更改。  SQL>alter table t1 shrink space cascade; --压缩表及相关数据段并下调HWMSQL> alter table t1 shrink space compact; --只压缩不下调HWMSQL> alter table t1 shrink space ; --下调HWMSQL> alter table t1disable row movement; --关闭行移动1234567891011

只能在ASSM、本地管理的表空间进行,完成这些之后不需要进行索引的重建,但统计信息最好重新收集下,脚本参加本博客上上篇。^_^

2.导入导出

用exp/imp导出后,重新导入重建,在重新创建索引和重新收集统计信息。

3.CATS技术

create table newtable as select * from old_table

drop old_table

rename table newtable to old_table

重建索引,收集统计信息。

4.move tablespacesql> alter table <表名> move tablespace <表空间名> 重建索引,收集统计信息。123

以上是“ORACLE中表空间和表碎片的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:怎么从db2数据库查询表结构
下一篇:SQL查询语句怎么写
相关文章

 发表评论

暂时没有评论,来抢沙发吧~