以下是常用脚本,会陆续加入许多。
1.确定跟踪文件:
select
d.value||'/'||lower(rtrim(i.instance, chr(0)))||'_ora_'||p.spid||'.trc' trace_file_name
from
( select
p.spid
from
sys.v_$mystat m,
sys.v_$session s,
sys.v_$process p
where
m.statistic# = 1 and
s.sid = m.sid and
p.addr = s.paddr
) p,
( select
t.instance
from
sys.v_$thread t,
sys.v_$parameter v
where
v.name = 'thread' and
(
v.value = 0 or
t.thread# = to_number(v.value)
)
) i,
( select
value
from
sys.v_$parameter
where
name = 'user_dump_dest'
) d
2.show_space()
create or replace
procedure show_space
( p_segname in varchar2,
p_owner in varchar2 default user,
p_type in varchar2 default 'TABLE' )
as
l_free_blks number;
l_total_blocks number;
l_total_bytes number;
l_unused_blocks number;
l_unused_bytes number;
l_LastUsedExtFileId number;
l_LastUsedExtBlockId number;
l_LAST_USED_BLOCK number;
procedure p( p_label in varchar2, p_num in number )
is
begin
dbms_output.put_line( rpad(p_label,40,'.') ||
p_num );
end;
begin
dbms_space.free_blocks
( segment_owner => p_owner,
segment_name => p_segname,
segment_type => p_type,
freelist_group_id => 0,
free_blks => l_free_blks );
dbms_space.unused_space
( segment_owner => p_owner,
segment_name => p_segname,
segment_type => p_type,
total_blocks => l_total_blocks,
total_bytes => l_total_bytes,
unused_blocks => l_unused_blocks,
unused_bytes => l_unused_bytes,
LAST_USED_EXTENT_FILE_ID => l_LastUsedExtFileId,
LAST_USED_EXTENT_BLOCK_ID => l_LastUsedExtBlockId,
LAST_USED_BLOCK => l_LAST_USED_BLOCK );
p( 'Free Blocks', l_free_blks );
p( 'Total Blocks', l_total_blocks );
p( 'Total Bytes', l_total_bytes );
p( 'Unused Blocks', l_unused_blocks );
p( 'Unused Bytes', l_unused_bytes );
p( 'Last Used Ext FileId', l_LastUsedExtFileId );
p( 'Last Used Ext BlockId', l_LastUsedExtBlockId );
p( 'Last Used Block', l_LAST_USED_BLOCK );
end;
/
3.show_space_assm()
create or replace procedure show_space_assm
(p_segname in varchar2,
p_owner in varchar2 default user,
p_type in varchar2 default 'TABLE')
as
L_fs1_bytes number;
L_fs2_bytes number;
L_fs3_bytes number;
L_fs4_bytes number;
L_fs1_blocks number;
L_fs2_blocks number;
L_fs3_blocks number;
L_fs4_blocks number;
L_full_bytes number;
L_full_blocks number;
L_unformatted_bytes number;
L_unformatted_blocks number;
procedure p(p_label in varchar2, p_num in number)
is
begin
dbms_output.put_line( rpad(p_label,40,'.')||p_num );
end;
begin
dbms_space.space_usage
(segment_owner =>p_owner,
segment_name =>p_segname,
segment_type =>p_type,
unformatted_blocks=>L_unformatted_blocks,
unformatted_bytes=>L_unformatted_bytes,
fs1_blocks=>L_fs1_blocks,
fs1_bytes=>L_fs1_bytes,
fs2_blocks=>L_fs2_blocks,
fs2_bytes=>L_fs2_bytes,
fs3_blocks=>L_fs3_blocks,
fs3_bytes=>L_fs3_bytes,
fs4_blocks=>L_fs4_blocks,
fs4_bytes=>L_fs4_bytes,
full_blocks=>L_full_blocks,
full_bytes=>L_full_bytes);
p('Free spacce 0-25% blocks:',l_fs1_blocks);
p('Free spacce 25-50% Blocks:',l_fs2_blocks);
p('Free spacce 50-75% Blocks:',l_fs3_blocks);
p('Free spacce 75-100% Blocks:',l_fs4_blocks);
p('full blocks:',l_full_blocks);
p('unformatted_blocks',l_unformatted_blocks);
end;
/
4。显示oracle隐含参数
select
x.ksppinm name,
y.ksppstvl value,
y.ksppstdf isdefault,
decode(bitand(y.ksppstvf,7),1,'MODIFIED',4,'SYSTEM_MOD','FALSE') ismod,
decode(bitand(y.ksppstvf,2),2,'TRUE','FALSE') isadj
from
sys.x$ksppi x,
sys.x$ksppcv y
where
x.inst_id = userenv('Instance') and
y.inst_id = userenv('Instance') and
x.indx = y.indx and
x.ksppinm like '%_&par%'
order by
translate(x.ksppinm, ' _', ' ')
/
select
a.ksppinm "Parameter",
a.ksppdesc "Description",
b.ksppstvl "Session Value",
c.ksppstvl "Instance Value"
from
x$ksppi a,
x$ksppcv b,
x$ksppsv c
where a.indx = b.indx
and a.indx = c.indx
and a.ksppinm like '/_%' escape '/'
order by 1
select name
,value
,decode(isdefault, 'TRUE','Y','N') as "Default"
,decode(ISEM,'TRUE','Y','N') as SesMod
,decode(ISYM,'IMMEDIATE', 'I',
'DEFERRED', 'D',
'FALSE', 'N') as SysMod
,decode(IMOD,'MODIFIED','U',
'SYS_MODIFIED','S','N') as Modified
,decode(IADJ,'TRUE','Y','N') as Adjusted
,description
from ( --GV$SYSTEM_PARAMETER
select x.inst_id as instance
,x.indx+1
,ksppinm as name
,ksppity
,ksppstvl as value
,ksppstdf as isdefault
,decode(bitand(ksppiflg/256,1),1,'TRUE','FALSE') as ISEM
,decode(bitand(ksppiflg/65536,3),
1,'IMMEDIATE',2,'DEFERRED','FALSE') as ISYM
,decode(bitand(ksppstvf,7),1,'MODIFIED','FALSE') as IMOD
,decode(bitand(ksppstvf,2),2,'TRUE','FALSE') as IADJ
,ksppdesc as description
from x$ksppi x
,x$ksppsv y
where x.indx = y.indx
and substr(ksppinm,1,1) = '_'
and x.inst_id = USERENV('Instance')
)
order by name
确定重做日志的切换频率
SELECT trunc(first_time) "Date",
to_char(first_time, 'Dy') "Day",
count(1) "Total",
SUM(decode(to_char(first_time, 'hh24'),'00',1,0)) "h0",
SUM(decode(to_char(first_time, 'hh24'),'01',1,0)) "h1",
SUM(decode(to_char(first_time, 'hh24'),'02',1,0)) "h2",
SUM(decode(to_char(first_time, 'hh24'),'03',1,0)) "h3",
SUM(decode(to_char(first_time, 'hh24'),'04',1,0)) "h4",
SUM(decode(to_char(first_time, 'hh24'),'05',1,0)) "h5",
SUM(decode(to_char(first_time, 'hh24'),'06',1,0)) "h6",
SUM(decode(to_char(first_time, 'hh24'),'07',1,0)) "h7",
SUM(decode(to_char(first_time, 'hh24'),'08',1,0)) "h8",
SUM(decode(to_char(first_time, 'hh24'),'09',1,0)) "h9",
SUM(decode(to_char(first_time, 'hh24'),'10',1,0)) "h10",
SUM(decode(to_char(first_time, 'hh24'),'11',1,0)) "h11",
SUM(decode(to_char(first_time, 'hh24'),'12',1,0)) "h12",
SUM(decode(to_char(first_time, 'hh24'),'13',1,0)) "h13",
SUM(decode(to_char(first_time, 'hh24'),'14',1,0)) "h14",
SUM(decode(to_char(first_time, 'hh24'),'15',1,0)) "h15",
SUM(decode(to_char(first_time, 'hh24'),'16',1,0)) "h16",
SUM(decode(to_char(first_time, 'hh24'),'17',1,0)) "h17",
SUM(decode(to_char(first_time, 'hh24'),'18',1,0)) "h18",
SUM(decode(to_char(first_time, 'hh24'),'19',1,0)) "h19",
SUM(decode(to_char(first_time, 'hh24'),'20',1,0)) "h20",
SUM(decode(to_char(first_time, 'hh24'),'21',1,0)) "h21",
SUM(decode(to_char(first_time, 'hh24'),'22',1,0)) "h22",
SUM(decode(to_char(first_time, 'hh24'),'23',1,0)) "h23"
FROM V$log_history
group by trunc(first_time), to_char(first_time, 'Dy')
Order by 1
select start_recid,start_time,end_recid,end_time,minutes
from (select test.*, rownum as rn
from (select b.recid start_recid,to_char(b.first_time,'yyyy-mm-dd
hh24:mi:ss') start_time,
a.recid end_recid,to_char(a.first_time,'yyyy-mm-dd hh24:mi:ss')
end_time,round(((a.first_time-b.first_time)*24)*60,2) minutes
from v$log_history a,v$log_history b where a.recid=b.recid+1 and
b.first_time > sysdate - 1
order by a.first_time desc) test) y where y.rn < 30;
全表扫描
This query provides a list of queries (1,000 characters only) involved in full table scans. The total number of rows and blocks for each table is also displayed so that you can determine whether the full scan is degrading performance. (全表扫描)
select sp.object_owner,sp.object_name, (select sql_text from v$sqlarea sa where sa.address = sp.address and sa.hash_value =sp.hash_value) sqltext, (select executions from v$sqlarea sa where sa.address = sp.address and sa.hash_value =sp.hash_value) no_of_full_scans, (select lpad(nvl(trim(to_char(num_rows)),' '),15,' ')||' | '||lpad(nvl(trim(to_char(blocks)),' '),15,' ')||' | '||buffer_pool from dba_tables where table_name = sp.object_name and owner = sp.object_owner) "rows|blocks|pool" from v$sql_plan sp where operation='TABLE ACCESS' and options = 'FULL' and object_owner IN () order by 1,2;
1. 监控事例的等待
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9599/viewspace-472894/ ,如需转载,请注明出处,否则将追究法律责任。