zoukankan      html  css  js  c++  java
  • Script to Detect Tablespace Fragmentation

    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,999
    column "COUNT"                  format 999
    column "TOTAL BYTES"            format 999,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
    /
    example output:
    SQL> @TFSTSFRM
    
    Table created.
    
    PL/SQL procedure successfully completed.
    
                                Contiguous Extents Report
    
    TABLESPACE NAME                CONTIGUOUS BYTES
    ------------------------------ ----------------
    EXAMPLE                              32,768,000
    
                                Contiguous Extents Report
    
    TABLESPACE NAME                CONTIGUOUS BYTES
    ------------------------------ ----------------
    SYSAUX                                3,211,264
    
                                Contiguous Extents Report
    
    TABLESPACE NAME                CONTIGUOUS BYTES
    ------------------------------ ----------------
    SYSTEM                              371,130,368
    SYSTEM                                  393,216
    
                                Contiguous Extents Report
    
    TABLESPACE NAME                CONTIGUOUS BYTES
    ------------------------------ ----------------
    UNDOTBS1                             13,500,416
    UNDOTBS1                                524,288
    UNDOTBS1                                458,752
    UNDOTBS1                                458,752
    UNDOTBS1                                327,680
    UNDOTBS1                                262,144
    UNDOTBS1                                196,608
    UNDOTBS1                                131,072
    UNDOTBS1                                131,072
    UNDOTBS1                                131,072
    UNDOTBS1                                 65,536
    UNDOTBS1                                 65,536
    UNDOTBS1                                 65,536
    UNDOTBS1                                 65,536
    UNDOTBS1                                 65,536
    UNDOTBS1                                 65,536
    UNDOTBS1                                 65,536
    
                                Contiguous Extents Report
    
    TABLESPACE NAME                CONTIGUOUS BYTES
    ------------------------------ ----------------
    USERS                            10,995,367,936
    USERS                                 1,048,576
    USERS                                   393,216
    USERS                                   262,144
    USERS                                   196,608
    
    26 rows selected.
    
                                Contiguous Extents Report
    
    TABLESPACE_NAME                # OF EXTENTS      TOTAL BYTES
    ------------------------------ ------------ ----------------
    EXAMPLE                                   1       32,768,000
    UNDOTBS1                                 17       16,580,608
    USERS                                     7   10,997,268,480
    SYSAUX                                    1        3,211,264
    SYSTEM                                    2      371,523,584
    
    Table dropped.
  • 相关阅读:
    npm 默认创建项目如何自动配置
    VueJS + TypeScript 入门第一课
    实现类数组转化成数组(DOM 操作获得的返回元素值是一个类数组)
    webpack4(4.41.2) 打包出现 TypeError this.getResolve is not a function
    vue-cli 4.0.5 配置环境变量样例
    关于H5页面在微信浏览器中音视频播放的问题
    ant-design-vue 快速避坑指南
    记elementUI一个大坑
    VUE自定义(有限)库存日历插件
    node转发请求 .csv格式文件下载 中文乱码问题 + 文件上传笔记
  • 原文地址:https://www.cnblogs.com/macleanoracle/p/2967235.html
Copyright © 2011-2022 走看看