Oracle dba常用指令碼

來源:互聯網
上載者:User

以下為Oracle dba常用的指令碼

1、檢查資料緩衝區和共用區命中率 

  1. declare   
  2. reads_value number(15);  
  3. direct_value number(15);  
  4. lob_value number(15);  
  5. consical_value number(15);  
  6. db_value number(15);  
  7. x number;  
  8. y number;  
  9. z number;  
  10. begin   
  11.   select value into reads_value from v$sysstat where name ='physical reads';   
  12.    select value into direct_value from v$sysstat where name ='physical reads direct';   
  13.   select value into lob_value from v$sysstat where name ='physical reads direct (lob)';   
  14.    select value into consical_value from v$sysstat where name ='consistent gets';   
  15.   select value into db_value from v$sysstat where name = 'db block gets';   
  16.   x:=direct_value+lob_value;  
  17.     
  18.   y:=1-(reads_value-x)/(consical_value+db_value-x);  
  19.   dbms_output.put_line('資料緩衝區命中率是:'||y);  
  20.   if(y>=0.9) then  
  21.    dbms_output.put_line('命中率大於0.9資料緩衝大小比較合適');  
  22.   else   
  23.     dbms_output.put_line('資料快取命中率小於0.9,請調試db_cache_size大小');  
  24.   end if;  
  25.   select sum(pinhits-reloads)/sum(pins) into z from v$librarycache;  
  26.   dbms_output.put_line('共用區命中率是:'||z);  
  27.   if(z>=0.9) then  
  28.    dbms_output.put_line('共用區命中率大於0.9大小比較合適');  
  29.   else   
  30.     dbms_output.put_line('共用區命中率小於0.9,請調試db_cache_size大小');  
  31.   end if;  
  32. end;  

2、檢查資料表空間的是使用方式 

  1.  select a.tablespace_name,total,free,(total-free)/total used from  
  2. (select tablespace_name,sum(bytes)/1024/1024 total from dba_data_files group by tablespace_name) a,   
  3. (select tablespace_name,sum(bytes)/1024/1024 free from dba_free_space group by tablespace_name) b  
  4. where a.tablespace_name=b.tablespace_name;  

3、檢查和資料表空間產生語句

  1. --資料表空間產生語句,請在sql表單中執行  
  2. select dbms_metadata.get_ddl('TABLESPACE',tablespace_name) from dba_tablespaces;  
  3. --表產生語句  
  4. select dbms_metadata.get_ddl('TABLE',upper('&TABLE_NAME'),upper('&USER_NAME')) from dual;  

4、找出系統中cpu消耗和io比較大的語句

  1. select SQL_TEXT,SQL_FULLTEXT from v$sql a where a.HASH_VALUE   
  2. in (select hash_value from v$sqlarea where buffer_gets>1000000  
  3. or disk_reads>1000000/*order by buffer_gets+disk_reads desc*/);  

5、找出當前系統中比較慢的sql

     ①aix中通過topas命令找出cpu系統比較大的pid

     ②通過sql語句方法找出具體語句 

  1. --spid為進程號  
  2. select SQL_TEXT,SQL_FULLTEXT,FIRST_LOAD_TIME from v$sql where ADDRESS=(select SQL_ADDRESS from v$session where   
  3. PADDR=(select ADDR from v$process where spid=&&spid));  

6、找出比較多的資料表空間片段 

  1. select tablespace_name,  
  2. count(*) chunks ,  
  3. max(bytes/1024/1024) max_chunk  
  4.   from dba_free_space  
  5. group by tablespace_name;  

說明:得分越高,資料表空間的片段越大

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.