show_space 查看segment空间分配的情况

create or replace procedure show_space
/*
   描述:本程序是针对Oracle 920以上版本的
         last updated 2004-12-14 by yaanzy
        
   注意:表的类型(ASSM、MANUAL)一定要输入准确,否则程序报错:
         ORA-10614、ORA-10618,缺省是ASSM
*/

( p_segname_1 in varchar2,
  p_space     in varchar2 default 'MANUAL',
  p_type_1    in varchar2 default 'TABLE' ,
  p_owner_1   in varchar2 default user)
as
    p_segname varchar2(100);
    p_type    varchar2(10);
    p_owner   varchar2(30);

    l_unformatted_blocks    number;
    l_unformatted_bytes     number;
    l_fs1_blocks            number;
    l_fs1_bytes             number;
    l_fs2_blocks            number;
    l_fs2_bytes             number;
    l_fs3_blocks            number;
    l_fs3_bytes             number;
    l_fs4_blocks            number;
    l_fs4_bytes             number;
    l_full_blocks           number;
    l_full_bytes            number;

    l_free_blks             number;
    l_total_blocks          number;
    l_total_bytes           number;
    l_unused_blocks         number;
    l_unused_bytes          number;
    l_LastUsedExtFileId     number;
    l_LastUsedExtBlockId    number;
    l_LAST_USED_BLOCK       number;

    procedure p( p_label in varchar2, p_num in number )
    is
    begin
        dbms_output.put_line( rpad(p_label,40,'.') ||p_num );
    end;
begin
   
    --dbms_output.put_line( '使用说明' );
    --dbms_output.put_line( '========' );
    --dbms_output.put_line( 'exec show_space(SEGMENTNAME,空间管理类型:MANUAL-AUTO,类型:TABLE-INDEX,OWNER:USER)' );
    --dbms_output.put_line( '表的类型(ASSM、MANUAL)一定要输入准确 默认为 MANUAL' );
    --dbms_output.put_line( '如果是ASSM(AUTO) 的话,请自行设置' );
    --dbms_output.put_line( '' );
   

   
    p_segname := upper(p_segname_1); -- rainy changed
    p_owner := upper(p_owner_1);
    p_type := p_type_1;

    if (p_type_1 = 'i' or p_type_1 = 'I') then --rainy changed
        p_type := 'INDEX';
    end if;

    if (p_type_1 = 't' or p_type_1 = 'T') then --rainy changed
        p_type := 'TABLE';
    end if;

    if (p_type_1 = 'c' or p_type_1 = 'C') then --rainy changed
        p_type := 'CLUSTER';
    end if;


    dbms_space.unused_space
    ( segment_owner => p_owner,
      segment_name  => p_segname,
      segment_type  => p_type,
      total_blocks  => l_total_blocks,
      total_bytes   => l_total_bytes,
      unused_blocks => l_unused_blocks,
      unused_bytes  => l_unused_bytes,
      LAST_USED_EXTENT_FILE_ID  => l_LastUsedExtFileId,
      LAST_USED_EXTENT_BLOCK_ID => l_LastUsedExtBlockId,
      LAST_USED_BLOCK => l_LAST_USED_BLOCK );
   
    p( 'Total Blocks', l_total_blocks );
    p( 'Total Bytes', l_total_bytes );
    p( 'Unused Blocks', l_unused_blocks );
    p( 'Unused Bytes', l_unused_bytes );
    p( 'Last Used Ext FileId', l_LastUsedExtFileId );
    p( 'Last Used Ext BlockId', l_LastUsedExtBlockId );
    p( 'Last Used Block', l_LAST_USED_BLOCK );
   
    if p_space = 'MANUAL' or p_space = 'manual' then
        dbms_space.free_blocks
        ( segment_owner => p_owner,
          segment_name => p_segname,
          segment_type => p_type,
          freelist_group_id => 0,
          free_blks => l_free_blks );

        p( 'Free Blocks', l_free_blks );
    end if;

   

    if p_space = 'auto' or p_space = 'AUTO' or p_space = 'assm' or p_space = 'ASSM' then
       dbms_space.space_usage
       (segment_owner => p_owner ,
        segment_name => p_segname ,
        segment_type => p_type ,
        unformatted_blocks => l_unformatted_blocks ,
        unformatted_bytes => l_unformatted_bytes,
        fs1_blocks => l_fs1_blocks,
        fs1_bytes => l_fs1_bytes ,
        fs2_blocks => l_fs2_blocks,
        fs2_bytes => l_fs2_bytes,
        fs3_blocks => l_fs3_blocks ,
        fs3_bytes => l_fs3_bytes,
        fs4_blocks => l_fs4_blocks,
        fs4_bytes => l_fs4_bytes,
        full_blocks => l_full_blocks,
        full_bytes => l_full_bytes);
       
        dbms_output.put_line(rpad(' ',50,'*'));
        dbms_output.put_line('The segment is analyzed');
        p( '0% -- 25% free space blocks', l_fs1_blocks);
        p( '0% -- 25% free space bytes', l_fs1_bytes);
        p( '25% -- 50% free space blocks', l_fs2_blocks);
        p( '25% -- 50% free space bytes', l_fs2_bytes);
        p( '50% -- 75% free space blocks', l_fs3_blocks);
        p( '50% -- 75% free space bytes', l_fs3_bytes);
        p( '75% -- 100% free space blocks', l_fs4_blocks);
        p( '75% -- 100% free space bytes', l_fs4_bytes);
        p( 'Unused Blocks', l_unformatted_blocks );
        p( 'Unused Bytes', l_unformatted_bytes );
        p( 'Total Blocks', l_full_blocks);
        p( 'Total bytes', l_full_bytes);
       
    end if;

end;

SQL>set serveroutput on

MANUAL的表结果如下

SQL> exec show_space('misc_config_anhui')

 

  PL/SQL procedure successfully completed

 

ASSM/AUTO的表结果如下:

表需要分析

SQL> exec show_space('a','AUTO')

Total Blocks............................128
Total Bytes.............................1048576
Unused Blocks...........................111
Unused Bytes............................909312
Last Used Ext FileId....................4
Last Used Ext BlockId...................8
Last Used Block.........................17
 *************************************************
The segment is analyzed
0% -- 25% free space blocks.............0
0% -- 25% free space bytes..............0
25% -- 50% free space blocks............0
25% -- 50% free space bytes.............0
50% -- 75% free space blocks............0
50% -- 75% free space bytes.............0
75% -- 100% free space blocks...........0
75% -- 100% free space bytes............0
Unused Blocks...........................0
Unused Bytes............................0
Total Blocks............................13
Total bytes.............................106496

PL/SQL procedure successfully completed

Total Blocks............................64
  Total Bytes.............................524288
  Unused Blocks...........................48
  Unused Bytes............................393216
  Last Used Ext FileId....................2
  Last Used Ext BlockId...................39161
  Last Used Block.........................8
  Free Blocks.............................3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值