首页 > 其他分享 >SHOW_SPACE

SHOW_SPACE

时间:2023-06-25 14:32:20浏览次数:28  
标签:blocks SHOW -- space bytes number free SPACE


      这是Oracle大神TOM写的一个好工具SHOW_SPACE;它实际上就是一个存储过程,这个存储过程可以很高效的分析空间使用情况,有了此工具,就不用再通过写SQL语句来看每条记录或表占用表空间的大小了,使用起来非常方便。

一、创建存储过程


create or replace procedure show_space
( p_segname_1 in varchar2,
p_owner_1 in varchar2 default user,
p_type_1 in varchar2 default 'TABLE',
p_space in varchar2 default 'AUTO',
p_analyzed in varchar2 default 'Y'
)
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
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 );
 
if p_space = 'MANUAL' or (p_space <> 'auto' and p_space <> 'AUTO') 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;
 
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 the segment is analyzed */
if p_analyzed = 'Y' 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> create table test01 as select * from all_objects;

Table created.

SQL> set serveroutput on;

SQL> exec show_space('TEST01');

Total Blocks............................1280
Total Bytes.............................10485760
Unused Blocks...........................38
Unused Bytes............................311296
Last Used Ext FileId....................5
Last Used Ext BlockId...................610304
Last Used Block.........................90
*************************************************
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............................1214
Total bytes.............................9945088

PL/SQL procedure successfully completed.



SQL> delete from TEST01;

85054 rows deleted.

SQL> exec show_space('TEST01');
Total Blocks............................1280
Total Bytes.............................10485760
Unused Blocks...........................38
Unused Bytes............................311296
Last Used Ext FileId....................5
Last Used Ext BlockId...................610304
Last Used Block.........................90
*************************************************
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...........1214
75% -- 100% free space bytes............9945088
Unused Blocks...........................0
Unused Bytes............................0
Total Blocks............................0
Total bytes.............................0

PL/SQL procedure successfully completed.


SQL> alter table TEST01 move;

Table altered.

SQL> exec show_space('TEST01');
Total Blocks............................8
Total Bytes.............................65536
Unused Blocks...........................5
Unused Bytes............................40960
Last Used Ext FileId....................5
Last Used Ext BlockId...................609168
Last Used Block.........................3
*************************************************
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............................0
Total bytes.............................0

PL/SQL procedure successfully completed.

SQL>





标签:blocks,SHOW,--,space,bytes,number,free,SPACE
From: https://blog.51cto.com/prudentwoo/6545738

相关文章

  • 容器基础-- namespace,Cgoup 和 UnionFS
    Namespace什么是Namespace?这里的"namespace"指的是Linuxnamespace技术,它是Linux内核实现的一种隔离方案。简而言之,Linux操作系统能够为不同的进程分配不同的namespace,每个namespace都具有独立的资源分配,从而实现了进程间的隔离。如果你的Linux安装了GCC,可以通过......
  • 快讯 | ShowMeBug入选人力资源智享会《TPG红宝书》
    近日,ShowMeBug入选人力资源智享会《2022-2023 HR年度采购指南暨智享会人力资源供应商价值大奖分类榜单》,亦被称为《ThepurchasingGuide》,简称《TPG红宝书》(以下简称《红宝书》)。《红宝书》由人力资源智享会编写并发布,目的在于成为HR采购人力资源相关服务和产品的工具书,有效帮......
  • 环境隔离-namespace
    Nacos中服务存储和数据存储的最外层都是一个名为namespace的东西,用来做最外层隔离group:分组1、在nacos控制台新建命名空间,用来隔离不同环境【命名空间id】2、修改order-service的application.yml,添加namespace:【命名空间id】 Nacos环境隔离1、每个namespace都有唯一i......
  • ctfshow web入门
    CTFshowweb入门命令执行web29<?php/*#-*-coding:utf-8-*-#@Author:h1xa#@Date:2020-09-0400:12:34#@LastModifiedby:h1xa#@LastModifiedtime:2020-09-0400:26:48#@email:[email protected]#@link:https://ctfer.com*/error_reporting(0......
  • ctfshow 极限命令执行
    极限命令执行1第一关<?php//本题灵感来自研究一直没做出来的某赛某题时想到的姿势,太棒啦~。//flag在根目录flag里,或者直接运行根目录getflagerror_reporting(0);highlight_file(__FILE__);if(isset($_POST['ctf_show'])){$ctfshow=$_POST['ctf_show'];if(......
  • Nashorn引擎导致metaspace oom
       从报错内容很清楚是Metaspace区域oom了大部分情况下,程序运行中不会出现过多的类加载数量的变动,先导入dump文件检查是否有异常的classLoader或者有异常动态生成的class发现了下面这个classLoader数量异常,项目中用到nashorn这块js引擎来做动态js脚本执行通过查阅nas......
  • ShowMeBug与极狐(GitLab)战略合作,推动DevOps人才高效甄选
    近日,ShowMeBug与领先的开放式一体化安全DevOps平台提供商极狐(GitLab)达成深度合作协议,双方将致力于共同打造具有行业强认可度以及高实用性的DevOps岗位题型,助力企业通过更为专业、标准的技术笔试题型,提升DevOps岗位人才筛选效率。极狐GitLab是面向中国市场的开放式一体化安全Dev......
  • BUUCTF:[WUSTCTF2020]spaceclub
    题目地址:https://buuoj.cn/challenges#[WUSTCTF2020]spaceclub一个txt用记事本打开的话,什么都看到确有4kb的大小,联想题目名字spaceclub,使用ctrl+a全选就看清楚了notepad这样全选可能还是不太直观,我这里用sublime打开然后全选一开始以为是摩斯密码,后来发现是每一行的长短对应一个......
  • 生态合作 | ShowMeBug入驻集简云平台,多招聘系统管理更便捷
    近日,ShowMeBug入驻无代码集成与AI人工智能平台——集简云。两者的联合,拓展了技术招聘的可能性,让技术招聘更省时省力。集简云是一款超级软件连接器,无需开发,无需代码知识就可以轻松打通数百款软件之间的数据连接,构建自动化与智能化的业务流程。完成入驻后,企业可以在集简云平台......
  • ETCD连接报错:database space exceeded
    ETCD连接报错:databasespaceexceeded一:背景此etcd不是k8s集群中的etcd,是kuboard中使用etcd报错,kuboard稳定运行了一年多,上周还正常访问,今天上班访问kuboard报错,然后顺着排查发现kuboard中使用了etcd(之前一直没注意),查看kuboard日志,发现如下报错信息:二:报错分析:大致意思就是kubo......