Oracle監控Sql指令碼

2021-08-24 17:19:50 字數 3603 閱讀 6198

spool d:/10-10.log

prompt 192.168.10.10 wcm03 分析

prompt 分析時間

select sysdate from dual;

prompt 資料庫例項

select name from v$database;

prompt 檢查資料檔案的狀態記錄狀態不是"online"的資料檔案

select file_name

from dba_data_files

where status='offline';

prompt 檢查表空間的使用情況 如果表空間使用超過80%,新增新的資料檔案或者加大資料檔案的大小

select tablespace_name,

to_char(100*sum_free_m/sum_m, '99.99') || '%' as pct_free,

max_m,

count_blocks free_blk_cnt,

sum_free_m

from ( select tablespace_name,

sum(bytes)/1024/1024 as sum_m

from dba_data_files

group by tablespace_name),

(select tablespace_name as fs_ts_name,

max(bytes)/1024/1024 as max_m,

count(blocks) as count_blocks,

sum(bytes/1024/1024) as sum_free_m

from dba_free_space

group by tablespace_name )

where tablespace_name = fs_ts_name;

prompt 統計資料庫的剩餘的使用空間

select tablespace_name,

trunc ( sum (bytes ) / (1024*1024) ) as free_m,

sum ( blocks ) as free_blk ,

max ( bytes ) / (1024) as big_chunk_k,

count (*) as num_chunks

from dba_free_space

group by tablespace_name ;

prompt 檢查無效的資料庫物件

select owner||' '||object_name||' '||object_type

from dba_objects

where status='invalid';

prompt 檢查不起作用的約束

select owner||' '||constraint_name||' '||table_name||' '||constraint_type||' '||status

from dba_constraints

where status = 'disabled'

and constraint_type = 'p';

prompt 檢查無效的trigger

select owner||' '||trigger_name||' '||table_name||' '|| status

from dba_triggers

where status = 'disabled';

prompt 自由範圍的碎片

column fsfi format 999,99

select tablespace_name,

sqrt(max(blocks)/sum(blocks))*(100/sqrt(sqrt(count(blocks)))) fsfi

from dba_free_space

group by tablespace_name

order by 1;

prompt 資料緩衝命中率

select a.value + b.value logical_reads,

c.value phys_reads,

round(100*(1-c.value/(a.value+b.value)),4) hit_ratio

from v$sysstat a,

v$sysstat b,

v$sysstat c

where a.name='db block gets'

and b.name='consistent gets'

and c.name='physical reads' ;

prompt 語句的過載率

select sum(pins) total_pins,

sum(reloads) total_reloads,

sum(reloads)/sum(pins)*100 libcache_reload_ratio

from v$librarycache;

prompt 使用者鎖狀態

select /*+ rule */ s.username,

decode(l.type,'tm','table lock', 'tx','row lock',null) lock_level,

o.owner,

o.object_name,

o.object_type,

s.sid,

s.serial#,

s.terminal,

s.machine,

s.program,

s.osuser

from v$session s,

v$lock l,

dba_objects o

where l.sid = s.sid

and l.id1 = o.object_id(+)

and s.username is not null ;

prompt 資料字典快取記憶體

select (1-(sum(getmisses)/(sum(gets)+sum(getmisses))))*100

from v$rowcache;

prompt 物理檔案的使用頻率

select name||' '||phyrds||'/'||phywrts

from v$datafile df,

v$filestat fs

where df.file# =fs.file#;

prompt 排程程序的競爭

select network,

sum(busy)/sum(busy)+sum(idle)

from v$dispatcher

group by network;

prompt 減少free list競爭

select class,

count

from v$waitstat

where class='free list';

select sum(value)

from v$sysstat

where name in ('db block gets','consistent gets');

spool off

Oracle常用指令碼 監控DDL

create table db ddl ddl time varchar2 30 session id number,os user varchar2 200 ip address varchar2 200 terminal varchar2 200 host varchar2 200 user n...

oracle匯出sql指令碼

大體的分為三種方法 一 可以通過toad plsql develop等第三方工具進行匯出dll操作,用這種辦法的好處在於操作簡單方便,但需要安裝,下面簡單介紹一下用這兩個工具獲得dll語句的操作。二 直接通過exp imp工具 oracle提供的最原始最實用的匯入匯出工具,我們大體上可以分為三種辦法...

mysql 監控指令碼 監控mysql狀態指令碼

監控mysql狀態,發現宕後,自動重啟,每秒檢查一次。check.sh bin bash while true do bin sleep 1 sh mysql status.sh done chengkill bin sh pid kill thread for chenglee if filefo...