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

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

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

表空间碎片率

空闲选择a。表空间名称,sqrt(最大块数)/sum(块数))*(100/sqrt(sqrt(计数(块数))))FSFI

fromdba_free_spacea,dba _ tablespacesb

哪里?表空间名=b .表空间名

和SnO tin含量(' TEMPLATE ',' UNDO ')

groupbya.tablespace_name

orderby2

TABLESPACE_NAMEFSFI

-

选择的行。58860 .88888888886

闲置的

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

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

引用官方的一段话:

理想的情况是在表空间中有一个大的空闲区。表空间中的可用空间范围越大,您就越有可能运行

n 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 ON DBA_FREE_SPACE 
REM ------------------------------------------------------------------------ 
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 as the  
REM total amount of free space you have in each tablespace. From  REM    these results you can detect how fragmented your tablespace is.  
REM   
REM    The ideal situation is to have one large free extent in your  
REM    tablespace. The more extents of free space there are in the  
REM    tablespace, the more likely you  will run into fragmentation  
REM    problems. The size of the free extents is also  very important.  
REM    If you have a lot of small extents (too small for any next   REM    extent size) but the total bytes of free space is large, then  REM    you may want to consider defragmentation options.  
REM ------------------------------------------------------------------------ 
REM DISCLAIMER: 
REM    This script is provided for educational purposes only. It is NOT  REM    supported by Oracle World Wide Technical Support. 
REM    The script has been tested and appears to work as intended. 
REM    You should always run new scripts on a test instance initially. 
REM ------------------------------------------------------------------------ 
REM Main text of script follows: 
create table SPACE_TEMP (   
 TABLESPACE_NAME        CHAR(30),   
 CONTIGUOUS_BYTES       NUMBER)   
/   
declare   
  cursor query is select *   
          from dba_free_space   
                  order by tablespace_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);   
     else   
        insert into SPACE_TEMP values (previous_row.tablespace_name,   
               total);   
        total := this_row.bytes;   
     end if;   previous_row := this_row;   
  end loop;   
  insert into SPACE_TEMP values (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;   select tablespace_name, count(*) "# OF EXTENTS",   
         sum(contiguous_bytes) "TOTAL BYTES"    from space_temp   
group by tablespace_name;   spool off   
drop 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.首选shrink

SQL> 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 t1 disable row movement; --关闭行移动1234567891011

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

2.导入导出

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

3.CATS技术

  1. create table newtable as select * from old_table

  2. drop old_table

  3. rename table newtable to old_table

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

4.move tablespace

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

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

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/81849.html

(0)

相关推荐

  • 配置python环境中遇到的一些问题

    技术配置python环境中遇到的一些问题 配置python环境中遇到的一些问题这是个人第一次发博客,想分享一下在配置python中出现的一些问题。
    在cmd或Anaconda命令行中操作的。
    pip使用

    礼包 2021年12月20日
  • Python解压可迭代对象赋值给多个变量的示例分析

    技术Python解压可迭代对象赋值给多个变量的示例分析今天就跟大家聊聊有关Python解压可迭代对象赋值给多个变量的示例分析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有

    攻略 2021年12月4日
  • 租用香港服务器的优点香港服务器

    技术租用香港服务器的优点香港服务器对于一些网站所有者来说,虽然云服务器和VPS能够提供更为廉价的租用方案但是如果要求性能和数据的私密性很多用户还是会选择将网站或者数据部署在物理服务器上。以很多海外站长最经常使用的香港服务

    礼包 2021年10月22日
  • QT5中怎么使用SQLite

    技术QT5中怎么使用SQLite本篇内容介绍了“QT5中怎么使用SQLite”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成

    攻略 2021年11月30日
  • 社保局什么时候上班,社保局几点上班

    技术社保局什么时候上班,社保局几点上班上午11:30和下午5:30 社保局什么时候上班。社会保险 (Social Insurance) 是一种为丧失劳动能力、暂时失去劳动岗位或因健康原因造成损失的人口提供收入或补偿的一种

    生活 2021年10月26日
  • Spring Boot 分层打包 Docker 镜像实践及分析

    技术Spring Boot 分层打包 Docker 镜像实践及分析 Spring Boot 分层打包 Docker 镜像实践及分析Spring Boot 分层打包 Docker 镜像实践及分析
    1. 准

    礼包 2021年12月10日