数据库表空间使用情况脚本,来自metalink-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 3503220
  • 博文数量: 718
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 7790
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-07 08:51
个人简介

偶尔有空上来看看

文章分类

全部博文(718)

文章存档

2024年(4)

2023年(74)

2022年(134)

2021年(238)

2020年(115)

2019年(11)

2018年(9)

2017年(9)

2016年(17)

2015年(7)

2014年(4)

2013年(1)

2012年(11)

2011年(27)

2010年(35)

2009年(11)

2008年(11)

最近访客
相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: oracle

2009-06-15 09:19:54

来自metalink,可能有用

/*
purpose:
========

the purpose of this article is to provide you with a script file that
shows you space usage for a database.


database report - space usage:
==============================


overview:
---------

this script shows the space usage for a database. this script performs the
following functions:
                
  o show the tablespaces, size, and percent used.
  o the total free space still available in each tablespace.
  o the free space blocks in each of the tablespaces.
  o the total free space still available in each tablespace.
  o the usage by each user segment, the inital extent size,
      and the size of the next extents - ordered by segment name.
  o the usage by each user segment, the inital extent size,
      and the size of the next extents - ordered by tablespace name.
  o the usage by each user segment, the inital extent size,
      and the size of the next extents - ordered by segment size.
  o show the size of the entire database.


program notes:
--------------

run it by sys from sql*plus or sql*worksheet.


*** ***
 
the sample program in this article is provided for educational purposes
only and is not supported by oracle support services. however, it has been
tested internally, and works as documented. oracle does not guarantee that
it will work for you, so be sure to test it in your environment before you
rely on it.


program listing:
----------------
*/

-- - - - - - - - code begins here - - - - - - - - -

set linesize 132;
set pagesize 1000;
set long 50;
set echo on;

break on "tbl space" on "total bytes";

/* *************************************************** */
/* block-size */
/* *************************************************** */
column db_block_size new_value block_size
select to_char(value, '9999') db_block_size
       from v$parameter
       where name = 'db_block_size';


/* *************************************************** */
/* date & user_id */
/* *************************************************** */
column today new_value dba_date
select to_char(sysdate, 'mm/dd/yy hh:miam') today
       from dual;

break on instance
column instance new_value instance_name
select substr(name,1,4) instance
      from v$database;

clear breaks
set termout on

set pagesize 60 linesize 132 verify off
set space 2
ttitle left 'date: ' format a18 dba_date -
       center 'space report - ' format a4 instance_name -
       right 'page: ' format 999 sql.pno skip 2

set echo off;

set echo on;


/* *************************************************** */
/* tablespace usage via the dba_data_files */
/* *************************************************** */
set echo off;

select substr(d.tablespace_name, 1, 12) "tbl space",
   substr(to_char(sum(d.bytes), '999,999,999,999'), 1, 16) "total bytes",
   substr(to_char(sum(d.bytes)/1024/1024, '999,999.9'), 1, 10) "tot mbytes",
   substr(to_char(sum(d.bytes)/(z.value), '99,999,999'), 1, 11) "blocks"
from sys.dba_data_files d,
        v$parameter z
where z.name = 'db_block_size'
group by d.tablespace_name, z.value;
              
set echo on;


/* *************************************************** */
/* show tablespace usage */
/* *************************************************** */
set echo off;

select distinct substr(tablespace_name, 1, 12) "tbl space",
  substr(to_char(sum(blocks), '999,999,999'), 1, 12) "tot blks",
     substr(to_char(sum(bytes), '999,999,999,999'), 1, 16) "tot bytes"
from sys.dba_free_space
group by
 tablespace_name;

set echo on;


/* *************************************************** */
/* show tablespace usage */
/* *************************************************** */
set echo off;

break on "tbl space";

select substr(tablespace_name,1,12) "tbl space",
      substr(to_char(file_id, '99'), 1, 4) "id",
    substr(to_char(count(*), '9,999'), 1, 6) "pcs",
   substr(to_char(max(blocks), '9,999,999'), 1, 10) "max blks",
      substr(to_char(min(blocks), '9,999,999'), 1, 10) "min blks",
      substr(to_char(avg(blocks), '9,999,999.9'), 1, 12) "avg blks",
      substr(to_char(sum(blocks), '9,999,999'), 1,10) "sum blks",
      substr(to_char(sum(bytes), '99,999,999,999'), 1, 15) "sum bytes"
from
  sys.dba_free_space
group by
    tablespace_name,file_id
order by 1, 4;

set echo on;


/* *************************************************** */
/* show tablespace usage */
/* *************************************************** */
set echo off;

select
     distinct substr(tablespace_name,1,12) "tbl space",
    substr(to_char(sum(blocks), '999,999,999'), 1, 12) "sum blks",
 substr(to_char(sum(bytes)/(1024*1024), '999,999.999'), 1, 16) "sum mbytes"
from
     sys.dba_free_space
group by
     tablespace_name;

set echo on;
/* *************************************************** */
/* show tablespace segments - order by segment */
/* *************************************************** */
set echo off;

break on "segment" on "type";

select substr(segment_name, 1, 20) "segment",
       substr(segment_type,1,7) "type",
       substr(tablespace_name,1,8) "tbl space",
       substr(to_char(sum(bytes)/(1024*1024), '999,999.999'), 1, 11)
                                                            "sum mb",
      /* substr(to_char(sum(blocks), '999,999'), 1, 8) "sum blks", */
       substr(to_char(extents, '999'), 1, 4) "extents",
       substr(to_char((initial_extent/(1024*1024)), '99,999.999'), 1, 10)
                                                             "ini (mb)",
       substr(to_char((next_extent/(1024*1024)), '999.999'), 1, 8) "nxt (mb)"
from user_segments
group by segment_name,
         segment_type,
         tablespace_name,
         bytes,
         blocks,
         extents,
         initial_extent,
         next_extent
order by 1, 2;

set echo on;


/* *************************************************** */
/* show tablespace segments - order by tablespace */
/* *************************************************** */
set echo off;

break on "tbl space" on "segment" on "type";

select substr(tablespace_name,1,12) "tbl space",
       substr(segment_name, 1, 20) "segment",
    /* substr(segment_type,1,7) "type", */
       substr(to_char(sum(bytes)/(1024*1024), '999,999.999'), 1, 12)
                                                              "sum mb",
    /* substr(to_char(sum(blocks), '9,999,999'), 1, 10) "sum blks", */
       substr(to_char(extents, '999'), 1, 4) "exts",
       substr(to_char(initial_extent/(1024*1024), '999.999'), 1, 8)
                                                              "ini mb",
       substr(to_char(next_extent/(1024*1024), '999.999'), 1, 8)
                                                              "nxt mb"
from user_segments
group by segment_name,
         segment_type,
         tablespace_name,
         bytes,
         blocks,
         extents,
         initial_extent,
         next_extent
order by 1, 2;
       
set echo on;


/* *************************************************** */
/* show tablespace segments - order by bytes */
/* *************************************************** */
set echo off;

break on "sum bytes" on "segment" on "type";

select substr(to_char(sum(bytes)/(1024*1024), '999,999.999'), 1, 11)
                                                              "sum mb",
       substr(segment_name, 1, 20) "segment",
       substr(tablespace_name,1,12) "tbl space",
       /*substr(to_char(sum(blocks), '9,999,999'), 1, 10) "sum blks",*/
       substr(to_char(extents, '999'), 1, 4) "exts",
       substr(to_char(initial_extent/(1024*1024), '9,999.999'), 1, 10)
                                                              "ini mb",
       substr(to_char(next_extent/(1024*1024), '999.999'), 1, 8)
                                                              "nxt mb"
from user_segments
group by segment_name,
         segment_type,
         tablespace_name,
         bytes,
         blocks,
         extents,
         initial_extent,
         next_extent
order by 1, 2;

set echo on;


/* *************************************************** */
/* show size of database */
/* *************************************************** */
set echo off;

select substr(to_char(sum(bytes)/1024/1024, '999,999,999.99'), 1, 15) "tot mbytes",
        substr(to_char(sum(bytes)/1024/1024/1024, '999,999.99'), 1, 11) "tot gbytes"
from sys.dba_data_files;
      
undefine block_size;
set echo off;

set long 80;


--- - - - - - code ends here - - - - - - - - -

阅读(2177) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图