Beruflich Dokumente
Kultur Dokumente
nimaidba
Welcome to the world of Oracle with Nimai
https://nimaidba.wordpress.com/tag/performance-monitoring-scripts/
1/10
4/27/2014
op6 NUMBER;
op7 NUMBER;
BEGIN
Dbms_Output.Disable;
Dbms_Output.Enable(1000000);
Dbms_Output.Put_Line(TABLE UNUSED BLOCKS TOTAL BLOCKS HIGH WATER MARK);
Dbms_Output.Put_Line( );
FOR cur_rec IN cu_tables LOOP
Dbms_Space.Unused_Space(cur_rec.owner,cur_rec.table_name,TABLE,op1,op2,op3,op4,op5,op6,op7);
Dbms_Output.Put_Line(RPad(cur_rec.table_name,30, ) ||
LPad(op3,15, ) ||
LPad(op1,15, ) ||
LPad(Trunc(op1-op3-1),15, ));
END LOOP;
END;
/
SET VERIFY ON;
To see the server metrics on OS level (Best for RAC)
SELECT Time now is METRIC_NAME,
To_char(sysdate, dd/mm/yyyy hh24:mi:ss) VALUE
FROM DUAL
UNION
SELECT to_char(inst_id) || _ || METRIC_NAME METRIC_NAME,
to_char(VALUE) value
FROM gV$SYSMETRIC
WHERE METRIC_NAME IN (Database CPU Time Ratio,Database Wait Time Ratio)
AND INTSIZE_CSEC = (SELECT MAX(INTSIZE_CSEC) FROM gV$SYSMETRIC where inst_id=1)
and inst_id=1
UNION
SELECT to_char(inst_id) || _ || METRIC_NAME METRIC_NAME,
to_char(VALUE) value
FROM gV$SYSMETRIC
WHERE METRIC_NAME IN (Database CPU Time Ratio,Database Wait Time Ratio)
AND INTSIZE_CSEC = (SELECT MAX(INTSIZE_CSEC) FROM gV$SYSMETRIC where inst_id=2)
and inst_id=2 ;
To see the long running sqls
SELECT s.SQL_TEXT,
vw.inst_id,
vw.username,
vw.osuser
vw.machine ,
https://nimaidba.wordpress.com/tag/performance-monitoring-scripts/
2/10
4/27/2014
3/10
4/27/2014
END MININUM,
CASE METRIC_NAME
WHEN SQL Service Response Time then ROUND((MAXVAL / 100),2)
WHEN Response Time Per Txn then ROUND((MAXVAL / 100),2)
ELSE MAXVAL
END MAXIMUM,
CASE METRIC_NAME
WHEN SQL Service Response Time then ROUND((AVERAGE / 100),2)
WHEN Response Time Per Txn then ROUND((AVERAGE / 100),2)
ELSE AVERAGE
END AVERAGE
FROM GV$SYSMETRIC_SUMMARY
where METRIC_NAME in (CPU Usage Per Sec,
CPU Usage Per Txn,
Database CPU Time Ratio,
Database Wait Time Ratio,
Executions Per Sec,
Executions Per Txn,
Response Time Per Txn,
SQL Service Response Time,
User Transaction Per Sec)
AND INTSIZE_CSEC = (SELECT MAX(INTSIZE_CSEC) FROM GV$SYSMETRIC_SUMMARY
WHERE INST_ID=1)
AND INST_ID=1
UNION
select 2 INST_ID,
CASE METRIC_NAME
WHEN SQL Service Response Time then SQL Service Response Time (secs)
WHEN Response Time Per Txn then Response Time Per Txn (secs)
ELSE METRIC_NAME
END METRIC_NAME,
CASE METRIC_NAME
WHEN SQL Service Response Time then ROUND((MINVAL / 100),2)
WHEN Response Time Per Txn then ROUND((MINVAL / 100),2)
ELSE MINVAL
END MININUM,
CASE METRIC_NAME
WHEN SQL Service Response Time then ROUND((MAXVAL / 100),2)
WHEN Response Time Per Txn then ROUND((MAXVAL / 100),2)
ELSE MAXVAL
END MAXIMUM,
CASE METRIC_NAME
WHEN SQL Service Response Time then ROUND((AVERAGE / 100),2)
WHEN Response Time Per Txn then ROUND((AVERAGE / 100),2)
ELSE AVERAGE
END AVERAGE
https://nimaidba.wordpress.com/tag/performance-monitoring-scripts/
4/10
4/27/2014
FROM GV$SYSMETRIC_SUMMARY
where METRIC_NAME in (CPU Usage Per Sec,
CPU Usage Per Txn,
Database CPU Time Ratio,
Database Wait Time Ratio,
Executions Per Sec,
Executions Per Txn,
Response Time Per Txn,
SQL Service Response Time,
User Transaction Per Sec)
AND INTSIZE_CSEC = (SELECT MAX(INTSIZE_CSEC) FROM GV$SYSMETRIC_SUMMARY
WHERE INST_ID=2)
AND INST_ID=2
ORDER BY 1
Displays segment advice for the specified segment.
SET SERVEROUTPUT ON SIZE 1000000
SET LINESIZE 200
SET VERIFY OFF
DECLARE
l_object_id NUMBER;
l_task_name VARCHAR2(32767) := SEGMENT_ADVISOR;
l_object_type VARCHAR2(32767) := UPPER(&object_type);
l_attr1 VARCHAR2(32767) := UPPER(&object_owner);
l_attr2 VARCHAR2(32767) := UPPER(&object_name);
BEGIN
IF l_attr2 = NULL THEN
l_attr2 := NULL;
END IF;
DBMS_ADVISOR.create_task (
advisor_name => Segment Advisor,
task_name => l_task_name);
DBMS_ADVISOR.create_object (
task_name => l_task_name,
object_type => l_object_type,
attr1 => l_attr1,
attr2 => l_attr2,
attr3 => NULL,
attr4 => null,
attr5 => NULL,
object_id => l_object_id);
https://nimaidba.wordpress.com/tag/performance-monitoring-scripts/
DBMS_ADVISOR.set_task_parameter (
5/10
4/27/2014
DBMS_ADVISOR.set_task_parameter (
task_name => l_task_name,
parameter => RECOMMEND_ALL,
value => TRUE);
DBMS_ADVISOR.execute_task(task_name => l_task_name);
FOR cur_rec IN (SELECT f.impact,
o.type,
o.attr1,
o.attr2,
f.message,
f.more_info
FROM dba_advisor_findings f
JOIN dba_advisor_objects o ON f.object_id = o.object_id AND f.task_name = o.task_name
WHERE f.task_name = l_task_name
ORDER BY f.impact DESC)
LOOP
DBMS_OUTPUT.put_line(..);
DBMS_OUTPUT.put_line(Type : || cur_rec.type);
DBMS_OUTPUT.put_line(Attr1 : || cur_rec.attr1);
DBMS_OUTPUT.put_line(Attr2 : || cur_rec.attr2);
DBMS_OUTPUT.put_line(Message : || cur_rec.message);
DBMS_OUTPUT.put_line(More info : || cur_rec.more_info);
END LOOP;
DBMS_ADVISOR.delete_task(task_name => l_task_name);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line(Error : || DBMS_UTILITY.format_error_backtrace);
DBMS_ADVISOR.delete_task(task_name => l_task_name);
END;
/
Getting current PGA status
SELECT 1 instnum,
pga_aggr /(1024 * 1024 * 1024),
tot_pag_alloc /(1024 * 1024 * 1024),
(tot_pag_used)/ (1024* 1024* 1024)
FROM
(select value tot_pag_used
from gv$pgastat where name = total PGA inuse and inst_id = 1),
(select value tot_pag_alloc
from gv$pgastat where name = total PGA allocated and inst_id = 1 ),
(select value pga_aggr from gv$parameter where UPPER(NAME)=PGA_AGGREGATE_TARGET and
inst_id = 1)
https://nimaidba.wordpress.com/tag/performance-monitoring-scripts/
6/10
4/27/2014
UNION
SELECT 2 instnum,
pga_aggr /(1024 * 1024 * 1024),
tot_pag_alloc /(1024 * 1024 * 1024),
(tot_pag_used)/ (1024* 1024* 1024)
FROM
(select value tot_pag_used
from gv$pgastat where name = total PGA inuse and inst_id = 2),
(select value tot_pag_alloc
from gv$pgastat where name = total PGA allocated and inst_id = 2 ),
(select value pga_aggr from gv$parameter where UPPER(NAME)=PGA_AGGREGATE_TARGET and
inst_id = 2);
Getting current SGA info
select inst_id, ROUND(SUM(BYTES)/1024/1024/1024,2) from gv$sgainfo WHERE RESIZEABLE=Yes
group by inst_id;
To see sessions per node
select count(sid) Total_session,
count(case status when ACTIVE THEN 1 ELSE NULL END) Active_session,
count(case status when INACTIVE THEN 1 ELSE NULL END ) Inactive_Session,
inst_id
from gv$session
WHERE USERNAME IN ( SEFPLLIVE) > Use this clause for particular schemas
AND LOGON_TIME >= SYSDATE INTERVAL 5 MINUTE > use this clause for more current
information
group by inst_id order by 4;
Dictionary hit ratio
SELECT inst_id,
(1 (Sum(getmisses)/(Sum(gets) + Sum(getmisses)))) * 100 Dict_Hit_Ratio
FROM gv$rowcache
group by inst_id;
db_buffer cache hit ratio
SELECT 1 inst_id,
(1 (phys.value / (db.value + cons.value))) * 100 Buff_Cache_Hit_Ratio
FROM gv$sysstat phys,
gv$sysstat db,
gv$sysstat cons
WHERE phys.name = physical reads
AND db.name = db block gets
AND cons.name = consistent gets
and phys.inst_id = 1
https://nimaidba.wordpress.com/tag/performance-monitoring-scripts/
7/10
4/27/2014
and db.inst_id = 1
and cons.inst_id = 1
UNION
SELECT 2 inst_id,
(1 (phys.value / (db.value + cons.value))) * 100 Buff_Cache_Hit_Ratio
FROM gv$sysstat phys,
gv$sysstat db,
gv$sysstat cons
WHERE phys.name = physical reads
AND db.name = db block gets
AND cons.name = consistent gets
and phys.inst_id = 1
and db.inst_id = 1
and cons.inst_id = 1
/
Latch hit ratio
SELECT inst_id,
(1 (Sum(misses) / Sum(gets))) * 100 Latch_Hit_Ratio
FROM gv$latch
group by inst_id;
Displays a list of SQL statements that are using the most resources.
SELECT *
FROM (SELECT Substr(a.sql_text,1,100) sql_text,
NVL(p.username, (PROD)) AS username,
p.osuser,
p.sid,
p.serial#,
Trunc(a.disk_reads/Decode(a.executions,0,1,a.executions)) reads_per_execution,
a.buffer_gets,
a.disk_reads,
a.executions,
a.sorts,
a.address
FROM v$sqlarea a,
v$session p
ORDER BY 2 DESC)
WHERE rownum <= 5;
DB CACHE ADVICE
select inst_id,
SIZE_FOR_ESTIMATE,
BUFFERS_FOR_ESTIMATE,
https://nimaidba.wordpress.com/tag/performance-monitoring-scripts/
8/10
4/27/2014
ESTD_PHYSICAL_READ_FACTOR,
ESTD_PHYSICAL_READS
FROM GV$db_cache_advice
WHERE NAME = DEFAULT
AND BLOCK_SIZE = (SELECT value from V$PARAMETER WHERE name = db_block_size)
AND ADVICE_STATUS = ON
SGA TARGET ADVICE
select inst_id, sga_size, sga_size_factor, estd_db_time, estd_db_time_factor, estd_physical_reads from
gv$sga_target_advice
order by inst_id, sga_size_factor;
TABLESPACE Fragmentation details
SELECT
TABLESPACE_NAME,COUNT(*) FREE_CHUNKS,decode( round((max(BYTES) / 1024000),2),
null,0, round((max(BYTES) / 1024000),2)) largest_chunk,
nvl(round(sqrt(max(BLOCKS)/sum(BLOCKS))*(100/sqrt(sqrt(count(BLOCKS)) )),2), 0) FRAG_INDEX
FROM
SYS.DBA_FREE_SPACE
GROUP BY
TABLESPACE_NAME
ORDER BY 2 DESC, 1;
Thats it. These scripts are few which I use to monitor for one of my project which was on RAC (Real
Application Clusters) (http://www.oracle.com/technetwork/products/clustering/overview/twp-rac11gr2134105.pdf).
You can also follow Tim Hall blog (http://oracle-base.com/dba/scripts.php) for more.
Soon I will be back with some shell scripts which You can you for monitoring.
Thanks & Regards
Nimai Karmakar
Posted in Oracle 10g Administration, Oracle scripts | Tagged oracle, Performance monitoring scripts,
RAC, scripts, technology | Leave a comment
Blog at WordPress.com. | The Misty Lake Theme.
Follow
Follow nimaidba
https://nimaidba.wordpress.com/tag/performance-monitoring-scripts/
9/10
4/27/2014
Powered by WordPress.com
https://nimaidba.wordpress.com/tag/performance-monitoring-scripts/
10/10