You are on page 1of 5

First thing when there is a Problem is database, we check the server stats and go directly to AWR report.

Did you run the AWR report? Okay, here we go. A number of different statistics are collected by the AWR including wait events, time model statistics, active session history statistics, various system and session level statistics, object usage statistics. AWR consists of number of tables owned by SYS and stored in SYSAUX tablespace. All AWR table names start with identified WR, three different type designations 1) Metadata (WRM$) 2) Historical Data (WRH$) 3) AWR tables related to ad-visor functions (WRI$) In some Oracle technical documents you will see the AWR tables also refereed to as the select workload repository (SWRF) tables. We see the following repository views in the database. V$ACTIVE_SESSION_HISTORY - Displays the active session history (ASH) sampled every second V$METRIC - Displays metric information V$METRICNAME - Displays the metrics associated with each metric group V$METRIC_HISTORY - Displays historical metrics V$METRICGROUP - Displays all metrics groups DBA_HIST_SNAPSHOT - The table holds AWR snapshots information for all snapshots. DBA_HIST_SQLSTAT - The information and statistics in this table are taken from V$SQL with each AWR snapshot, it chooses the top SQL statements from the dynamic view. The number of statements depends on the value of STATISTICS_LEVEL parameter. DBA_HIST_SQL_PLAN - This table is pretty much the same as V$SQL_PLAN. the greatest thing about it is that it keeps execution plans of all statements and the information is not purged when snapshots are deleted. DBA_HIST_SQLTEXT - Same as DBA_HIST_SQL_PLAN but with V$SQL_TEXT. DBA_HIST_SEG_STAT - Same as DBA_HIST_SQLSTAT but with V$SEGMENT_STATISTICS, the columns are slightly different from the V$, the HIST table has a column for each statistic instead of the STATISTIC_NAME column that the V$ has. This table also holds information of the top segments of each snapshot and the number is also controlled by the STATISTIC_LEVEL parameter. DBA_HIST_SYSTEM_EVENT - The HIST of V$SYSTEM_EVENT, holds the wait events information for every snapshot. DBA_HIST_ACTIVE_SESS_HISTORY - The HIST table of V$ACTIVE_SESSION_HISTORY. DBA_HIST_BASELINE - Displays baseline information DBA_HIST_DATABASE_INSTANCE - Displays database environment information

AWR Script Usage awrrpt.sql Displays various statistics for a range of snapshots Ids. awrrpti.sql Displays statistics for a range of snapshot Ids on a specified database and instance. awrsqrpt.sql Displays statistics of a particular SQL statement for a range of snapshot Ids. Run this report to inspect or debug the performance of a particular SQL statement. awrsqrpi.sql Displays statistics of a particular SQL statement for a range of snapshot Ids on a specified SQL. awrddrpt.sql Compares detailed performance attributes and configuration settings between two selected time periods. awrddrpi.sql Compares detailed performance attributes and configuration settings between two selected time periods on a specific database and instance. Interestingly we can use these views in many ways to find the database activities, sometimes we might be interested in what are the top 10 sql's running during that particular period. AWR generates those sql's but you don't want to run the whole AWR to find that. You can run this query to find. Don't forget to change the database id and number of instance in your DB. ttitle center 'AWR Top SQL Report' skip 2 set pagesize 50000 set linesize 300 col snap_id format 9999999 heading "Snap|ID" col tm format a15 heading "Snap|Start|Time" col inst format 90 heading "i|n|s|t|#" col dur format 990.00 heading "Snap|Dur|(m)" col sql_id format a15 heading "SQL|ID" col phv format 99999999999 heading "Plan|Hash|Value" col module format a20 heading "Module" col elap format 999990.00 heading "Elapsed|Time|(s)" col elapexec format 999990.00 heading "Elapsed|Time|per exec|(s)" col cput format 999990.00 heading "CPU|Time|(s)" col clwait format 999999990 heading "Cluster|Wait" col bget format 99999999990 heading "LIO" col dskr format 99999999990 heading "PIO" col rowp format 99999999990 heading "Rows" col exec format 9999990 heading "Exec" col prsc format 999999990 heading "Parse|Count" col pxexec format 9999990 heading "PX|Exec" col pctdbt format 990 heading "DB Time|%" col aas format 990.00 heading "A|A|S" col time_rank format 90 heading "Time|Rank" col sql_text format a40 heading "SQL|Text"

select * from ( select sqt.snap_id snap_id, TO_CHAR(sqt.tm,'YY/MM/DD HH24:MI') tm, sqt.inst inst, sqt.dur dur, sqt.sql_id sql_id, sqt.phv phv, to_clob(decode(sqt.module, null, null, sqt.module)) module, nvl((sqt.elap), to_number(null)) elap, nvl((sqt.elapexec), to_number(null)) elapexec, nvl((sqt.cput), to_number(null)) cput, sqt.clwait clwait, sqt.bget bget, sqt.dskr dskr, sqt.rowp rowp, sqt.exec exec, sqt.prsc prsc, sqt.pxexec pxexec, sqt.aas aas, sqt.time_rank time_rank , nvl(st.sql_text, to_clob('** SQL Text Not Available **')) sql_text -- PUT/REMOVE COMMENT TO HIDE/SHOW THE SQL_TEXT from ( select snap_id, tm, inst, dur, sql_id, phv, module, elap, elapexec, cput, clwait, bget, dskr, rowp, exec, prsc, pxexec, aas, time_rank from ( select s0.snap_id snap_id, s0.END_INTERVAL_TIME tm, s0.instance_number inst, round(EXTRACT(DAY FROM s1.END_INTERVAL_TIME s0.END_INTERVAL_TIME) * 1440 + EXTRACT(HOUR FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) * 60 + EXTRACT(MINUTE FROM s1.END_INTERVAL_TIME s0.END_INTERVAL_TIME) + EXTRACT(SECOND FROM s1.END_INTERVAL_TIME s0.END_INTERVAL_TIME) / 60, 2) dur, e.sql_id sql_id, e.plan_hash_value phv, max(e.module) module, sum(e.elapsed_time_delta)/1000000 elap, decode((sum(e.executions_delta)), 0, to_number(null), ((sum(e.elapsed_time_delta)) /

(sum(e.executions_delta)) / 1000000)) elapexec, sum(e.cpu_time_delta)/1000000 cput, sum(e.clwait_delta)/1000000 clwait, sum(e.buffer_gets_delta) bget, sum(e.disk_reads_delta) dskr, sum(e.rows_processed_delta) rowp, sum(e.executions_delta) exec, sum(e.parse_calls_delta) prsc, sum(px_servers_execs_delta) pxexec, (sum(e.elapsed_time_delta)/1000000) / ((round(EXTRACT(DAY FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) * 1440 + EXTRACT(HOUR FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) * 60 + EXTRACT(MINUTE FROM s1.END_INTERVAL_TIME s0.END_INTERVAL_TIME) + EXTRACT(SECOND FROM s1.END_INTERVAL_TIME s0.END_INTERVAL_TIME) / 60, 2))*60) aas, DENSE_RANK() OVER ( PARTITION BY s0.snap_id ORDER BY e.elapsed_time_delta DESC) time_rank from dba_hist_snapshot s0, dba_hist_snapshot s1, dba_hist_sqlstat e where s0.dbid = 3615614091 -- CHANGE THE DBID HERE! AND s1.dbid = s0.dbid and e.dbid = s0.dbid AND s0.instance_number in (1,2,3,4,5) -- CHANGE THE INSTANCE_NUMBER HERE! AND s1.instance_number = s0.instance_number and e.instance_number = s0.instance_number AND s1.snap_id = s0.snap_id + 1 and e.snap_id = s0.snap_id + 1 group by s0.snap_id, s0.END_INTERVAL_TIME, s0.instance_number, e.sql_id, e.plan_hash_value, e.elapsed_time_delta, s1.END_INTERVAL_TIME s0.END_INTERVAL_TIME ) where time_rank <= 10 -- GET TOP 5 SQL ACROSS SNAP_IDs... YOU CAN ALTER THIS TO HAVE MORE DATA POINTS ) sqt, dba_hist_sqltext st where st.sql_id(+) = sqt.sql_id and st.dbid(+) = 3615614091 -- CHANGE THE DBID HERE!

-- AND TO_CHAR(tm,'D') = 1 -- Day of week: 1=Sunday 7=Saturday -- AND TO_CHAR(tm,'D') <= 7 -- AND TO_CHAR(tm,'HH24MI') = 0900 -- Hour -- AND TO_CHAR(tm,'HH24MI') <= 1800 --AND tm >= TO_DATE('2013-apr-08 12:00:00','yyyy-mon-dd hh24:mi:ss') -- Data range --AND tm <= TO_DATE('2013-apr-10 12:00:09','yyyy-mon-dd hh24:mi:ss') -- AND snap_id in (338,339) -- AND snap_id = 335 and snap_id <= 339 -- AND snap_id = 3172 and sqt.sql_id in ('42pk03umxrfqa', '3dhz8tx744mh5', 'ah322609g2yrt', '5md8gkw13s2qx', '49a9zwxzc1rh4', 'gqa75mwncy0h3', '3p9nzusr2j2jd', '3xktjahmc1ava') -- AND lower(st.sql_text) like 'select%' -- AND lower(st.sql_text) like 'insert%' -- AND lower(st.sql_text) like 'update%' -- AND lower(st.sql_text) like 'merge%' -- AND pxexec 0 -- AND aas .5 order by -- snap_id -- TO GET SQL OUTPUT ACROSS SNAP_IDs SEQUENTIALLY AND ASC nvl(sqt.elap, -1) desc, sqt.sql_id -- TO GET SQL OUTPUT BY ELAPSED TIME ) -- where rownum <= 20 ;

You might also like