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

如何編寫(xiě)一鍵統(tǒng)計(jì)數(shù)據(jù)庫(kù)臨時(shí)表空間和阻塞lock信息的Shell腳本

共計(jì) 9729 個(gè)字符,預(yù)計(jì)需要花費(fèi) 25 分鐘才能閱讀完成。

這篇文章給大家介紹如何編寫(xiě)一鍵統(tǒng)計(jì)數(shù)據(jù)庫(kù)臨時(shí)表空間和阻塞 lock 信息的 Shell 腳本,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

今天主要分享一下兩個(gè) shell 腳本,主要是為了查看數(shù)據(jù)庫(kù)的臨時(shí)表空間和阻塞 lock 信息,下面一起來(lái)看看吧~

數(shù)據(jù)庫(kù)連接腳本

use script settdb.sh for DB login details registry

#!/bin/bash tmp_username=$SH_USERNAME tmp_password=$SH_PASSWORD tmp_db_sid=$SH_DB_SID #check $1 and $2 should be mandatory from input if [[ -z $1 ]] || [[ -z $2 ]]; then echo  ***********************************************  echo  WARNING :UserName And PassWord Is Needed!  echo  ***********************************************  exit fi if [[ -z $3 ]]   [[ -z $ORACLE_SID ]];then echo  ***********************************************  echo  WARNING :There is Instance can be used !  echo  ***********************************************  exit fi SH_USERNAME=`echo  $1 |tr  [a-z]   [A-Z] ` SH_PASSWORD=$2 echo  ***********************************************  if [[ -z $3 ]] then SH_DB_SID=$ORACLE_SID echo  Using Default Instance : $ORACLE_SID echo . else SH_DB_SID=`echo  $3 |tr  [a-z]   [A-Z] ` fi if [[ $SH_DB_SID = $tmp_db_sid ]]   [[ $SH_USERNAME = $tmp_username ]]   [[ $SH_PASSWORD = $tmp_password ]];then echo  Instance  $SH_DB_SID  has been connected  echo  ***********************************************  exit fi export SH_USERNAME=$SH_USERNAME export SH_DB_SID=$SH_DB_SID export SH_PASSWORD=$SH_PASSWORD export DB_CONN_STR=$SH_USERNAME/$SH_PASSWORD #echo $DB_CONN_STR listfile=`pwd`/listdb Num=`echo show user | $ORACLE_HOME/bin/sqlplus -s $DB_CONN_STR@$SH_DB_SID| grep -i  USER   | wc -l` if [ $Num -gt 0 ] then ## ok - instance is up echo  Instance  $SH_DB_SID  has been connected  echo -e  --  `date` -- \n-- $SH_USERNAME@$SH_DB_SID  has been connected --\n    listdb echo  ***********************************************  echo  Initalize DB login details registry OK!  echo  Now you can Execution script~  echo  ***********************************************  $SHELL else ## inst is inaccessible echo Instance: $SH_DB_SID Is Invalid Or UserName/PassWord Is Wrong echo  ***********************************************  exit fi del_length=3 tmp_txt=$(sed -n  $=  listdb) echo  ***********************************************  echo  *********   $SH_USERNAME @ $SH_DB_SID  **********  echo  ***********************************************  curr_len=`cat $listfile|wc -l` if [ $curr_len -gt $del_length ]; then echo   There Are Below Sessions Still Alive   echo  ***********************************************  fi sed $((${tmp_txt}-${del_length}+1)),${tmp_txt}d $listfile | tee tmp_listfile mv tmp_listfile $listfile

輸出:./settdb.sh 用戶(hù)名 用戶(hù)密碼

showtsps.sh

#!/bin/bash echo  ================================================== 查看數(shù)據(jù)庫(kù)臨時(shí)表空間 =================================================================  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

輸出:./showtsps.sh

showlock.sh

這里主要是查看阻塞 lock 信息,腳本內(nèi)容如下:

#!/bin/bash sqlplus -S $DB_CONN_STR@$SH_DB_SID  EOF set pages 500 set feedback off set verify off set echo on set linesize 1000 col object_name format a25 col osuser format a10 col machine format a12 col program format a20 --col object_type format a10 col state format a10 col status format a10 col oracle_username format a12 col sid_serial format a12 col sec_wait format 99999999 col lock_type format a5 col mode_held format a10 prompt Current Locks prompt ------------------------------------------------------------------------------------------------------ select ses.sid|| , ||ses.serial# sid_serial,loc.oracle_username,object_name, --object_type, ses.LOGON_TIME,ses.SECONDS_IN_WAIT sec_wait,ses.osuser,ses.machine,ses.program,ses.state,ses.status, decode(d.type,  MR ,  Media Recovery ,  RT ,  Redo Thread ,  UN ,  User Name ,  TX ,  Transaction ,  TM ,  DML ,  UL ,  PL/SQL User Lock ,  DX ,  Distrib Xaction ,  CF ,  Control File ,  IS ,  Instance State ,  FS ,  File Set ,  IR ,  Instance Recovery ,  ST ,  Disk Space Transaction ,  TS ,  Temp Segment ,  IV ,  Library Cache Invalidation ,  LS ,  Log Start or Switch ,  RW ,  Row Wait ,  SQ ,  Sequence Number ,  TE ,  Extend Table ,  TT ,  Temp Table , d.type) lock_type, decode(d.lmode, 0,  None , /* Mon Lock equivalent */ 1,  Null , /* N */ 2,  Row-S (SS) , /* L */ 3,  Row-X (SX) , /* R */ 4,  Share , /* S */ 5,  S/Row-X (SSX) , /* C */ 6,  Exclusive , /* X */ to_char(d.lmode)) mode_held from v\$locked_object loc,v\$session ses,dba_objects obj,v\$lock d where loc.object_id=obj.object_id and loc.session_id=ses.sid and obj.object_id=d.id1 and ses.sid=d.sid order by oracle_username,seconds_in_wait desc ; set head off SELECT  There are also  ||count(*)||  transaction locks  FROM v\$transaction_enqueue; prompt ------------------------------------------------------------------------------------------------------ set head on set linesize 1000 pagesize 1000 col  進(jìn)程 SID for 99999 trunc col  鎖類(lèi)型  format a10 col SQL 語(yǔ)句  format a60 col  等待事件  format a20 col  鎖時(shí)間  format a20 col  鎖角色  format a15 col  阻塞會(huì)話(huà) SID format a30 prompt prompt Blocking Session Details prompt ------------------------------------------------------------------------------------------------------ SELECT mm.inst_id  實(shí)例 ID , mm.sid  進(jìn)程 SID , mm.TYPE  鎖類(lèi)型 , mm.id1  事務(wù)號(hào) ID1 , mm.id2  事務(wù)號(hào) ID2 , LPAD(TRUNC(mm.ctime / 60 / 60), 3) ||   Hour   || LPAD(TO_CHAR(TRUNC(mm.ctime / 60) - TRUNC(mm.ctime / 60 / 60) * 60,  fm09 ), 2) ||   Min   || LPAD(TO_CHAR(mm.ctime - TRUNC(mm.ctime / 60) * 60,  fm09 ), 2) ||   Sec   鎖時(shí)間 , CASE WHEN mm.block = 1 AND mm.lmode != 0 THEN  holder  WHEN mm.block = 0 AND mm.request != 0 THEN  waiter  ELSE NULL END  鎖角色 , CASE WHEN ee.blocking_session IS NOT NULL THEN  waiting for SID   || ee.blocking_session ELSE NULL END  阻塞會(huì)話(huà) SID , dd.sql_text  SQL 語(yǔ)句 , cc.event  等待事件  FROM gv\$lock mm, gv\$session ee, gv\$sqlarea dd, gv\$session_wait cc WHERE mm.sid IN (SELECT nn.sid FROM (SELECT tt.*, COUNT(1) OVER (PARTITION BY tt.TYPE, tt.id1, tt.id2) cnt, MAX(tt.lmode) OVER (PARTITION BY tt.TYPE, tt.id1, tt.id2) lmod_flag, MAX(tt.request) OVER (PARTITION BY tt.TYPE, tt.id1, tt.id2) request_flag FROM gv\$lock tt) nn WHERE nn.cnt   1 AND nn.lmod_flag != 0 AND nn.request_flag != 0) AND mm.sid = ee.sid (+) AND ee.sql_id = dd.sql_id (+) AND mm.sid = cc.sid (+) AND ((mm.block = 1 AND mm.lmode != 0) OR (mm.block = 0 AND mm.request != 0)) ORDER BY mm.TYPE, mm.id1, mm.id2, mm.lmode DESC, mm.ctime DESC; exit EOF

輸出:./showlock.sh

關(guān)于如何編寫(xiě)一鍵統(tǒng)計(jì)數(shù)據(jù)庫(kù)臨時(shí)表空間和阻塞 lock 信息的 Shell 腳本就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

正文完
 
丸趣
版權(quán)聲明:本站原創(chuàng)文章,由 丸趣 2023-07-17發(fā)表,共計(jì)9729字。
轉(zhuǎn)載說(shuō)明:除特殊說(shuō)明外本站除技術(shù)相關(guān)以外文章皆由網(wǎng)絡(luò)搜集發(fā)布,轉(zhuǎn)載請(qǐng)注明出處。
評(píng)論(沒(méi)有評(píng)論)
主站蜘蛛池模板: 日土县| 丰县| 乐亭县| 陵川县| 自贡市| 白玉县| 六枝特区| 岫岩| 广德县| 扎鲁特旗| 金坛市| 伊川县| 高碑店市| 准格尔旗| 错那县| 竹北市| 肃北| 惠安县| 延庆县| 冷水江市| 历史| 铜陵市| 斗六市| 东城区| 广河县| 五华县| 平昌县| 盐津县| 金坛市| 天峻县| 墨江| 项城市| 洞口县| 织金县| 冷水江市| 大连市| 平顶山市| 玛曲县| 平谷区| 上饶市| 永兴县|