Tablespace Report

简介:

 

 
  1. REM tablespace report 
  2.  
  3.  
  4. set linesize 200 
  5.  
  6.  
  7. select a.tablespace_name, 
  8.        round(a.bytes_alloc / 1024 / 1024) megs_alloc, 
  9.        round(nvl(b.bytes_free, 0) / 1024 / 1024) megs_free, 
  10.        round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024) megs_used, 
  11.        round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_Free, 
  12.        100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_used, 
  13.        round(maxbytes / 1048576) Max 
  14.   from (select f.tablespace_name, 
  15.                sum(f.bytes) bytes_alloc, 
  16.                sum(decode(f.autoextensible, 'YES', f.maxbytes, 'NO', f.bytes)) maxbytes 
  17.           from dba_data_files f 
  18.          group by tablespace_name) a, 
  19.        (select f.tablespace_name, sum(f.bytes) bytes_free 
  20.           from dba_free_space f 
  21.          group by tablespace_name) b 
  22.  where a.tablespace_name = b.tablespace_name(+) 
  23. union all 
  24. select h.tablespace_name, 
  25.        round(sum(h.bytes_free + h.bytes_used) / 1048576) megs_alloc, 
  26.        round(sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / 
  27.              1048576) megs_free, 
  28.        round(sum(nvl(p.bytes_used, 0)) / 1048576) megs_used, 
  29.        round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / 
  30.              sum(h.bytes_used + h.bytes_free)) * 100) Pct_Free, 
  31.        100 - 
  32.        round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / 
  33.              sum(h.bytes_used + h.bytes_free)) * 100) pct_used, 
  34.        round(sum(f.maxbytes) / 1048576) max 
  35.   from sys.v_$TEMP_SPACE_HEADER h, 
  36.        sys.v_$Temp_extent_pool  p, 
  37.        dba_temp_files           f 
  38.  where p.file_id(+) = h.file_id 
  39.    and p.tablespace_name(+) = h.tablespace_name 
  40.    and f.file_id = h.file_id 
  41.    and f.tablespace_name = h.tablespace_name 
  42.  group by h.tablespace_name 
  43.  ORDER BY 1 
  44.  
  45.  
  46.     SELECT d.tablespace_name "Name",  
  47.                 TO_CHAR(NVL(a.bytes / 1024 / 1024, 0),'99,999,990.900'"Size (M)",  
  48.                 TO_CHAR(NVL(t.hwm, 0)/1024/1024,'99999999.999')  "HWM (M)"
  49.                 TO_CHAR(NVL(t.hwm / a.bytes * 100, 0), '990.00'"HWM % " , 
  50.                 TO_CHAR(NVL(t.bytes/1024/1024, 0),'99999999.999'"Using (M)",  
  51.             TO_CHAR(NVL(t.bytes / a.bytes * 100, 0), '990.00'"Using %"  
  52.            FROM sys.dba_tablespaces d,  
  53.                 (select tablespace_name, sum(bytes) bytes from dba_temp_files group by tablespace_name) a, 
  54.                 (select tablespace_name, sum(bytes_cached) hwm, sum(bytes_used) bytes from v$temp_extent_pool group by tablespace_name) t 
  55.           WHERE d.tablespace_name = a.tablespace_name(+)  
  56.             AND d.tablespace_name = t.tablespace_name(+)  
  57.             AND d.extent_management like 'LOCAL'  
  58.             AND d.contents like 'TEMPORARY' 
  59.  
  60.  
  61. ttitle -  
  62.    center  'Database Freespace Summary'  skip 2  
  63.   
  64. comp sum of nfrags totsiz avasiz on report  
  65. break on report  
  66.  
  67. set pages 999 
  68. col tsname  format     a16 justify c heading 'Tablespace'  
  69. col nfrags  format 999,990 justify c heading 'Free|Frags'  
  70. col mxfrag  format 999,999 justify c heading 'Largest|Frag (MB)'  
  71. col totsiz  format 999,999 justify c heading 'Total|(MB)'  
  72. col avasiz  format 999,999 justify c heading 'Available|(MB)'  
  73. col pctusd  format     990 justify c heading 'Pct|Used'  
  74.  
  75. select total.TABLESPACE_NAME tsname, 
  76.        D nfrags, 
  77.        C/1024/1024 mxfrag, 
  78.        A/1024/1024 totsiz, 
  79.        B/1024/1024 avasiz, 
  80.        (1-nvl(B,0)/A)*100 pctusd 
  81. from 
  82.     (select sum(bytes) A, 
  83.             tablespace_name 
  84.             from dba_data_files 
  85.             group by tablespace_name) TOTAL, 
  86.     (select sum(bytes) B, 
  87.             max(bytes) C, 
  88.             count(bytes) D,  
  89.             tablespace_name 
  90.             from dba_free_space 
  91.             group by tablespace_name) FREE 
  92. where  
  93.       total.TABLESPACE_NAME=free.TABLESPACE_NAME(+) 
  94.  
  95.  
  96. SELECT t.tablespace_name, 
  97.        CASE 
  98.          WHEN t.contents = 'TEMPORARY' AND t.extent_management = 'LOCAL' THEN 
  99.           u.bytes 
  100.          ELSE 
  101.           df.user_bytes - NVL(fs.bytes, 0) 
  102.        END / 1024 / 1024 used_mb, 
  103.        CASE 
  104.          WHEN t.contents = 'TEMPORARY' AND t.extent_management = 'LOCAL' THEN 
  105.           df.user_bytes - NVL(u.bytes, 0) 
  106.          ELSE 
  107.           NVL(fs.bytes, 0) 
  108.        END / 1024 / 1024 free_mb, 
  109.        fs.min_fragment / 1024 / 1024 min_fragment_mb, 
  110.        fs.max_fragment / 1024 / 1024 max_fragment_mb, 
  111.        (fs.bytes / 1024 / 1024) / fs.fragments avg_fragment_mb, 
  112.        fs.fragments, 
  113.        t.status, 
  114.        t.contents, 
  115.        t.logging, 
  116.        t.extent_management, 
  117.        t.allocation_type, 
  118.        t.force_logging, 
  119.        t.segment_space_management, 
  120.        t.def_tab_compression, 
  121.        t.retention, 
  122.        t.bigfile 
  123.   FROM dba_tablespaces t, 
  124.        (SELECT tablespace_name, 
  125.                SUM(bytes) bytes, 
  126.                MIN(min_fragment) min_fragment, 
  127.                MAX(max_fragment) max_fragment, 
  128.                SUM(fragments) fragments 
  129.           FROM (SELECT tablespace_name, 
  130.                        SUM(bytes) bytes, 
  131.                        MIN(bytes) min_fragment, 
  132.                        MAX(bytes) max_fragment, 
  133.                        COUNT(*) fragments 
  134.                   FROM dba_free_space 
  135.                  GROUP BY tablespace_name 
  136.                 UNION ALL 
  137.                 SELECT tablespace_name, 
  138.                        SUM(bytes) bytes, 
  139.                        MIN(bytes) min_fragment, 
  140.                        MAX(bytes) max_fragment, 
  141.                        COUNT(*) fragments 
  142.                   FROM dba_undo_extents 
  143.                  WHERE status = 'EXPIRED' 
  144.                  GROUP BY tablespace_name) 
  145.          GROUP BY tablespace_name) fs, 
  146.        (SELECT tablespace_name, SUM(user_bytes) user_bytes 
  147.           FROM dba_data_files 
  148.          GROUP BY tablespace_name 
  149.         UNION ALL 
  150.         SELECT tablespace_name, SUM(user_bytes) user_bytes 
  151.           FROM dba_temp_files 
  152.          GROUP BY tablespace_name) df, 
  153.        (SELECT tablespace_name, SUM(bytes_used) bytes 
  154.           FROM gv$temp_extent_pool 
  155.          GROUP BY tablespace_name) u 
  156.  WHERE t.tablespace_name = df.tablespace_name(+) 
  157.    AND t.tablespace_name = fs.tablespace_name(+) 
  158.    AND t.tablespace_name = u.tablespace_name(+) 

 



     本文转自 珏石头 51CTO博客,原文链接:http://blog.51cto.com/gavinshaw/977589,如需转载请自行联系原作者




相关文章
|
SQL 关系型数据库
ORA-1652: unable to extend temp segment by 128 in tablespace xxx Troubleshootin
当收到告警信息ORA-01652: unable to extend temp segment by 128 in tablespace xxxx 时,如何Troubleshooting ORA-1652这样的问题呢? 当然一般xxx是临时表空间,也有可能是用户表空间。
2045 0
|
机器学习/深度学习 C++ Go
|
SQL Oracle 关系型数据库
MANAGE TABLESPACE
一、官档 BOOK → Database SQL Language Reference → 12 SQL Statements: ALTER TABLE to ALTER TABLESPACE → ALTER TABLESPACE 二、扩容表空间 扩大数据库的第三种方法是手工增大数据文件(datafile)的容量或使表空间(tablespace)内的数据文件容量可以随需动态地增长。
1233 0