久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

如何通過shell腳本查看數據庫表空間使用情況

144次閱讀
沒有評論

共計 3539 個字符,預計需要花費 9 分鐘才能閱讀完成。

這篇文章主要介紹如何通過 shell 腳本查看數據庫表空間使用情況,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

腳本如下:
sqlplus -s $DB_CONN_STR@$SH_DB_SID   EOF
set echo off heading on underline on;
column inst_num  heading Inst Num  new_value inst_num  format 99999;
column inst_name heading Instance  new_value inst_name format a12;
column db_name   heading DB Name   new_value db_name   format a12;
column dbid      heading DB Id     new_value dbid      format 9999999999 just c;

prompt
prompt Current Instance
prompt ~~~~~~~~~~~~~~~~

select d.dbid            dbid
     , d.name            db_name
     , i.instance_number inst_num
     , i.instance_name   inst_name
  from v\$database d,
       v\$instance i;
       
set term on feedback off lines 130 pagesize 999 tab off trims on
column MB format 999,999,999  heading Total MB
column free format 9,999,999 heading Free MB
column used format 99,999,999 heading Used MB
column Largest format 999,999 heading LrgstMB
column tablespace_name format a20 heading Tablespace
column status format a3 truncated
column max_extents format 99999999999 heading MaxExt
col extent_management           for a1 trunc   head M
col allocation_type             for a1 trunc   head A
col Ext_Size for a4 trunc head Init
column pfree format a3 trunc heading %Fr

break on report
compute sum of MB on report
compute sum of free on report
compute sum of used on report

select  
  d.tablespace_name, 
  decode(d.status, 
    ONLINE , OLN ,
    READ ONLY , R/O ,
    d.status) status,
  d.extent_management, 
  decode(d.allocation_type,
    USER , ,
    d.allocation_type) allocation_type,
  (case 
    when initial_extent 1048576 
    then lpad(round(initial_extent/1024,0),3)|| K  
    else lpad(round(initial_extent/1024/1024,0),3)|| M  
  end) Ext_Size,
  NVL (a.bytes / 1024 / 1024, 0) MB,
  NVL (f.bytes / 1024 / 1024, 0) free, 
  (NVL (a.bytes / 1024 / 1024, 0) – NVL (f.bytes / 1024 / 1024, 0)) used,
  NVL (l.large / 1024 / 1024, 0) largest, 
  d.MAX_EXTENTS ,
  lpad(round((f.bytes/a.bytes)*100,0),3) pfree,
  (case when round(f.bytes/a.bytes*100,0) = 20 then else * end) alrt
FROM sys.dba_tablespaces d,
  (SELECT   tablespace_name, SUM(bytes) bytes
   FROM dba_data_files
   GROUP BY tablespace_name) a,
  (SELECT   tablespace_name, SUM(bytes) bytes
   FROM dba_free_space
   GROUP BY tablespace_name) f,
  (SELECT   tablespace_name, MAX(bytes) large
   FROM dba_free_space
   GROUP BY tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
  AND d.tablespace_name = f.tablespace_name(+)
  AND d.tablespace_name = l.tablespace_name(+)
  AND NOT (d.extent_management LIKE LOCAL AND d.contents LIKE TEMPORARY)
UNION ALL
select 
  d.tablespace_name, 
  decode(d.status, 
    ONLINE , OLN ,
    READ ONLY , R/O ,
    d.status) status,
  d.extent_management, 
  decode(d.allocation_type,
    UNIFORM , U ,
    SYSTEM , A ,
    USER , ,
    d.allocation_type) allocation_type,
  (case 
    when initial_extent 1048576 
    then lpad(round(initial_extent/1024,0),3)|| K  
    else lpad(round(initial_extent/1024/1024,0),3)|| M  
  end) Ext_Size,
  NVL (a.bytes / 1024 / 1024, 0) MB,
  (NVL (a.bytes / 1024 / 1024, 0) – NVL (t.bytes / 1024 / 1024, 0)) free,
  NVL (t.bytes / 1024 / 1024, 0) used, 
  NVL (l.large / 1024 / 1024, 0) largest, 
  d.MAX_EXTENTS ,
  lpad(round(nvl(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,100),0),3) pfree,
  (case when nvl(round(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,0),100) = 20 then else * end) alrt
FROM sys.dba_tablespaces d,
  (SELECT   tablespace_name, SUM(bytes) bytes
   FROM dba_temp_files
   GROUP BY tablespace_name order by tablespace_name) a,
  (SELECT   tablespace_name, SUM(bytes_used  ) bytes
   FROM v\$temp_extent_pool
   GROUP BY tablespace_name) t,
  (SELECT   tablespace_name, MAX(bytes_cached) large
   FROM v\$temp_extent_pool
   GROUP BY tablespace_name order by tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
  AND d.tablespace_name = t.tablespace_name(+)
  AND d.tablespace_name = l.tablespace_name(+)
  AND d.extent_management LIKE LOCAL
  AND d.contents LIKE TEMPORARY
  ORDER by 1
/
prompt
exit
EOF

運行結果相對比較簡單,也很清晰。

以上是“如何通過 shell 腳本查看數據庫表空間使用情況”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注丸趣 TV 行業資訊頻道!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-24發表,共計3539字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 晴隆县| 德江县| 二连浩特市| 湘潭市| 太康县| 韩城市| 寿阳县| 从江县| 淮北市| 高邑县| 湟源县| 肇源县| 泽库县| 桓仁| 吉首市| 石柱| 宝清县| 博罗县| 江孜县| 庆安县| 珲春市| 涪陵区| 聂拉木县| 兴和县| 德清县| 开封市| 湘乡市| 淮安市| 永和县| 满洲里市| 承德县| 阜康市| 海晏县| 湖南省| 盐源县| 庆云县| 西藏| 同心县| 万宁市| 平和县| 八宿县|