Saturday, June 18, 2011

How to color (mark) SQL for AWR snapshots

Are all SQL statements you’re looking for in your AWR repository ? If not, there is a simple way to ‘ask’ Oracle to include list of SQL_ID in every snapshot. All you need to do is color it. No, not using marker on the screen with Grid Control Performance tab but using DBMS_WORKLOAD_REPOSITORY. ADD_COLORED_SQL  procedure. Since you mark sql_id as colored it will be included in every AWR snapshot even if it is not one of the top SQL's.
All colored sql_id together with creation date could be checked in the following view - DBA_HIST_COLORED_SQL. After all work there is a simple way to uncolor sql_id (make it white ? ). There is a procedure called DBMS_WORKLOAD_REPOSITORY.REMOVE_COLORED_SQL.

Simple example:
- script used to display SQL statistics from AWR repository
$ cat sql_stats.sql
col exetime format 99999999999.99
col begin_interval_time format a30
select begin_interval_time, PLAN_HASH_VALUE, ELAPSED_TIME_DELTA/EXECUTIONS_DELTA exetime, EXECUTIONS_DELTA, CPU_TIME_DELTA, ELAPSED_TIME_DELTA, DISK_READS_DELTA from dba_hist_sqlstat ss, dba_hist_snapshot s where s.snap_id = ss.snap_id and sql_id = '&SQL_ID' and s.snap_id > (select max(snap_id)-96 from dba_hist_snapshot) and EXECUTIONS_DELTA<>0 order by s.snap_id, sql_id;
Checking AWR repository for particular SQL_ID.
SQL> @sql_stats.sql
Enter value for sql_id: 6zfggtprazcvb
old   2: where s.snap_id = ss.snap_id and sql_id = '&SQL_ID' and s.snap_id > (select max(snap_id)-96 from dba_hist_snapshot) and EXECUTIONS_DELTA<>0 order by s.snap_id, sql_id
new   2: where s.snap_id = ss.snap_id and sql_id = '6zfggtprazcvb' and s.snap_id > (select max(snap_id)-96 from dba_hist_snapshot) and EXECUTIONS_DELTA<>0 order by s.snap_id, sql_id
BEGIN_INTERVAL_TIME            PLAN_HASH_VALUE         EXETIME EXECUTIONS_DELTA CPU_TIME_DELTA ELAPSED_TIME_DELTA DISK_READS_DELTA 
------------------------------ --------------- --------------- ---------------- -------------- ------------------ ---------------- 
16-JUN-11 04.00.43.639 PM            927619989     90627544.40               20       12879044         1812550888           125728 
16-JUN-11 04.15.51.312 PM            927619989    282777061.76              151      279247551         4.2699E+10            72065 
16-JUN-11 04.30.57.081 PM           1587981875      1308903.00                7         203969            9162321             1894 
16-JUN-11 09.46.00.195 PM           1587981875       889464.06               16         760882           14231425             2463 
17-JUN-11 12.45.49.596 AM           1587981875      1390759.44               16         778881           22252151             2973 
17-JUN-11 04.45.38.168 AM           1587981875       621587.94               16         682897            9945407             2320 
17-JUN-11 06.45.18.396 AM           1587981875       415950.50               16         692895            6655208             1774 
17-JUN-11 07.45.35.975 AM           1587981875       865986.07               15         642901           12989791             1228 

8 rows selected.
SQL has been executed in last hour a few times but was not included in AWR snapshot
SQL> select sample_time, session_id, sql_id, sql_plan_hash_value, sql_child_number  from v$active_session_history where sql_id = '6zfggtprazcvb' and sample_time > sysdate - 1/24 order by sample_time;

SAMPLE_TIME                   SESSION_ID SQL_ID        SQL_PLAN_HASH_VALUE SQL_CHILD_NUMBER
----------------------------- ---------- ------------- ------------------- ----------------
17-JUN-11 03.21.43.399 PM           1711 6zfggtprazcvb          1587981875               10
17-JUN-11 03.21.44.399 PM           1711 6zfggtprazcvb          1587981875               10
17-JUN-11 03.21.45.399 PM           1711 6zfggtprazcvb          1587981875               10
17-JUN-11 03.21.46.399 PM           1711 6zfggtprazcvb          1587981875               10
17-JUN-11 03.21.47.409 PM           1711 6zfggtprazcvb          1587981875               10
17-JUN-11 03.21.48.409 PM           1711 6zfggtprazcvb          1587981875               10
17-JUN-11 03.21.49.409 PM           1711 6zfggtprazcvb          1587981875               10
17-JUN-11 03.21.50.409 PM           1711 6zfggtprazcvb          1587981875               10
17-JUN-11 03.21.51.409 PM           1711 6zfggtprazcvb          1587981875               10
17-JUN-11 03.21.52.419 PM           1711 6zfggtprazcvb          1587981875               10
17-JUN-11 03.33.42.862 PM            474 6zfggtprazcvb          1587981875               10
17-JUN-11 03.33.43.862 PM            474 6zfggtprazcvb          1587981875               10
17-JUN-11 03.33.44.862 PM            474 6zfggtprazcvb          1587981875               10
17-JUN-11 03.49.37.819 PM           1724 6zfggtprazcvb          1587981875               10
17-JUN-11 03.49.38.819 PM           1724 6zfggtprazcvb          1587981875               10
SQL_ID has been colored (marked) using DBMS_WORKLOAD_REPOSITORY procedure
SQL> exec dbms_workload_repository.add_colored_sql('6zfggtprazcvb');

PL/SQL procedure successfully completed.

SQL> select * from DBA_HIST_COLORED_SQL;

      DBID SQL_ID        CREATE_TIME
---------- ------------- -------------------
1878812188 6zfggtprazcvb 2011-06-17 15:55:45
Now this SQL_ID has been included in AWR snapshot even if it has been executed once - see last row
SQL> @sql_stats.sql
Enter value for sql_id: 6zfggtprazcvb
old   2: where s.snap_id = ss.snap_id and sql_id = '&SQL_ID' and s.snap_id > (select max(snap_id)-96 from dba_hist_snapshot) and EXECUTIONS_DELTA<>0 order by s.snap_id, sql_id
new   2: where s.snap_id = ss.snap_id and sql_id = '6zfggtprazcvb' and s.snap_id > (select max(snap_id)-96 from dba_hist_snapshot) and EXECUTIONS_DELTA<>0 order by s.snap_id, sql_id

BEGIN_INTERVAL_TIME            PLAN_HASH_VALUE         EXETIME EXECUTIONS_DELTA CPU_TIME_DELTA ELAPSED_TIME_DELTA DISK_READS_DELTA 
------------------------------ --------------- --------------- ---------------- -------------- ------------------ ---------------- 
16-JUN-11 04.00.43.639 PM            927619989     90627544.40               20       12879044         1812550888           125728 
16-JUN-11 04.15.51.312 PM            927619989    282777061.76              151      279247551         4.2699E+10            72065 
16-JUN-11 04.30.57.081 PM           1587981875      1308903.00                7         203969            9162321             1894 
16-JUN-11 09.46.00.195 PM           1587981875       889464.06               16         760882           14231425             2463 
17-JUN-11 12.45.49.596 AM           1587981875      1390759.44               16         778881           22252151             2973 
17-JUN-11 04.45.38.168 AM           1587981875       621587.94               16         682897            9945407             2320 
17-JUN-11 06.45.18.396 AM           1587981875       415950.50               16         692895            6655208             1774 
17-JUN-11 07.45.35.975 AM           1587981875       865986.07               15         642901           12989791             1228 
17-JUN-11 03.45.11.552 PM           1587981875      1818946.00                1          12998            1818946              226 
At the end of this example SQL_ID has been uncolored (unmarked).
SQL> exec dbms_workload_repository.remove_colored_sql('6zfggtprazcvb');

PL/SQL procedure successfully completed.

SQL> select * from DBA_HIST_COLORED_SQL;

no rows selected

SQL>

Friday, June 10, 2011

Rolling partition and global index - do we need to rebuild ?

Some time ago (arrghhh - three month ago) I blogged about partition dropping when table has a global index - see. There was a example based on my tests. Now it is time to show some real figures. Both examples are sharing same scenario - about 2 years without touching indexes, 7 partitions are drop once per week. Partition drop is taking up to 6 - 7 hours. This time coalesce was not a option due to free up space requirement but it should help in future to avoid similar situations.
Example number 1
Table has around 562.000.000 rows and one partition has around 13.000.000 rows. Primary key index based on one number column growth to 140 GB and has been rebuilt to 13.9 GB. It is around 10 times less.
Example number 2 - bigger scale
Table has around 2.130.000.000 rows and one partition has around 45.000.000 rows.Primary key index based on one number column growth to 360 GB and has been rebuilt to 40 GB. It is 9 times less.
I put both examples here to show you that running coalesce for global indexes after partition drop can save you a lot of space and if done regularly prevent you from more resource consuming index rebuild.To be honest this is one of a few situations when I have seen any improvement (space wise this time) after index rebuild. But keep in mind that this is a special situation and for most of other cases you don't need to rebuild you indexes - if you think you need read Niall or Richard blog first.
regards,
Marcin

Saturday, May 7, 2011

Pivot tables and Active Session History in Oracle 11g

Oracle introduced a pivot tables in version 11g. If you want to use it there is still some limitation but as least it gave us a nice tool to display Active Session History information in various way. Please find one of possible example below - database CPU utilization for 5 minutes period with waits split into percent across wait classes
col "Administrative" format 999.99
col "Application" format 999.99
col "Cluster" format 999.99
col "Commit" format 999.99
col "Concurrency" format 999.99
col "Configuration" format 999.99
col "Network" format 999.99
col "Other" format 999.99
col "SYSTEM I/O" format 999.99
col "USER I/O" format 999.99
col "CPU" format 999.99
col Scheduler format 999.99
col Queueing format 999.99
col AAS format 999.99

select to_char(to_date(ts*300,'SSSSS'),'HH24:MI') sample_time, AAS,
nvl("'ON CPU'",0) "CPU",
nvl("'Scheduler'",0) Scheduler ,
nvl("'User I/O'",0) "USER I/O" ,
nvl("'System I/O'",0) "SYSTEM I/O" ,
nvl("'Concurrency'",0) Concurrency ,
nvl("'Application'",0) Application ,
nvl("'Commit'",0) Commit,
nvl("'Configuration'",0) Configuration,
nvl("'Administrative'",0) Administrative ,
nvl("'Network'",0) Network ,
nvl("'Queueing'",0) Queueing ,
nvl("'Cluster'",0) "CLUSTER",
nvl("'Other'",0) Other 
from (
 select trunc(to_char(sample_time, 'SSSSS')/300) ts,
 decode(session_state,'WAITING',wait_class,'ON CPU') wait_class, 
 count(*) cnt, 
 sum(count(*)) over (partition by trunc(to_char(sample_time, 'SSSSS')/300)) sum, 
 sum(count(*)) over (partition by trunc(to_char(sample_time, 'SSSSS')/300))/300 AAS 
 from v$active_session_history 
 group by trunc(to_char(sample_time, 'SSSSS')/300),
          decode(session_state,'WAITING',wait_class,'ON CPU') 
 order by 1
) 
pivot (
   sum(round(cnt/sum*100,2)) 
   for (wait_class) in    
   ('Administrative','Application','Cluster','Commit','Concurrency',
    'Configuration','Network','Other','Queueing','Scheduler','System I/O',
    'User I/O','ON CPU'
   )
) order by 1;

SAMPLE_TIME          AAS     CPU SCHEDULER USER I/O SYSTEM I/O CONCURRENCY APPLICATION  COMMIT CONFIGURATION ADMINISTRATIVE NETWORK QUEUEING CLUSTER   OTHER
---------------- ------- ------- --------- -------- ---------- ----------- ----------- ------- ------------- -------------- ------- -------- ------- -------
2011-05-06 14:58    3.38    6.40       .00    38.42        .49         .00         .00     .00           .00          54.68     .00      .00     .00     .00
2011-05-06 14:59    3.67    4.55       .00    44.09        .00         .00         .00     .00           .00          51.36     .00      .00     .00     .00
2011-05-06 15:00    2.98    5.59       .00    29.05        .56         .00         .00     .00           .00          64.80     .00      .00     .00     .00
2011-05-06 15:01    2.53    7.89       .00    16.45        .00         .00         .00     .00           .00          75.66     .00      .00     .00     .00
2011-05-06 15:02    2.62    7.64       .00    21.66        .00         .00         .00     .00           .00          70.70     .00      .00     .00     .00
2011-05-06 15:03    2.32    9.35       .00    11.51        .00         .00         .00     .00           .00          79.14     .00      .00     .00     .00
2011-05-06 15:04    2.37    6.34       .00    30.99        .70         .00         .00     .00           .00          61.97     .00      .00     .00     .00
2011-05-06 15:05    2.93   10.80       .00     6.25        .00         .00         .00     .00           .00          82.95     .00      .00     .00     .00
2011-05-06 15:06    3.28   12.69       .00    14.72       1.02         .00         .00     .00           .00          71.07     .00      .00     .00     .51
2011-05-06 15:07    4.57   10.58       .00     8.39        .00         .00         .00     .00           .00          81.02     .00      .00     .00     .00
2011-05-06 15:08    4.72    5.30       .00    13.78        .00         .00         .00     .00           .00          80.92     .00      .00     .00     .00
2011-05-06 15:09    4.80    6.25       .00    15.28        .00         .00         .00     .00           .00          78.47     .00      .00     .00     .00
2011-05-06 15:10    4.42    8.30       .00     7.92        .00         .00         .00     .00           .00          83.77     .00      .00     .00     .00
2011-05-06 15:11    4.65    6.45       .00    12.19        .00         .00         .00     .00           .00          81.36     .00      .00     .00     .00
2011-05-06 15:12    4.48    7.06       .00     9.67        .00         .00         .00     .00           .00          83.27     .00      .00     .00     .00
2011-05-06 15:13    4.58    9.09       .00    13.09        .00         .00         .00     .00           .00          77.82     .00      .00     .00     .00
2011-05-06 15:14    4.40   10.61       .00     7.20        .00         .00         .00     .00           .00          82.20     .00      .00     .00     .00
2011-05-06 15:15    4.00    7.92       .00      .00        .00         .00         .00     .00           .00          92.08     .00      .00     .00     .00
2011-05-06 15:16    4.33    8.46       .00     6.15        .00         .00         .00     .00           .00          85.00     .38      .00     .00     .00
2011-05-06 15:17    4.60    5.07       .00     9.42        .00         .00         .00     .00           .00          85.51     .00      .00     .00     .00
2011-05-06 15:18    4.80    4.86       .00    15.97        .00         .00         .00     .00           .00          79.17     .00      .00     .00     .00
2011-05-06 15:19    4.27    5.08       .00     5.08        .00         .00         .00     .00           .00          89.84     .00      .00     .00     .00
2011-05-06 15:20    4.00    2.92       .00      .00        .00         .00         .00     .00           .00          97.08     .00      .00     .00     .00
2011-05-06 15:21    4.37    3.05       .00     8.02        .00         .00         .00     .00           .00          88.93     .00      .00     .00     .00
2011-05-06 15:22    7.23   17.05       .00    32.03        .00         .00         .00     .00           .00          50.92     .00      .00     .00     .00
2011-05-06 15:23     .55    6.06       .00     3.03        .00         .00         .00     .00           .00          90.91     .00      .00     .00     .00

That query can be easily change by adding filtering condition for sessions or sample time. Unfortunately list of values for pivot table can't be generated dynamically without XML output so it is required to hard coded number of wait class into this code. 



regards,
Marcin

Wednesday, April 27, 2011

MySQLPerformance Schema - is this introduction of Oracle event based monitoring in MySQL ?

Today I read presentation about MySQL performance MySQL Essentials part 8  recommended by @surachart and I learned that Performance Schema has been introduced - see documentation.
After basic review it looks like introduction of well know Oracle wait interface and statistics. I'm going to download MySQL version 5.5 shortly and check it out. I have a lot of concerns what happen to MySQL after Oracle acquisition but at least this is step in good direction.

regards,
Marcin

Sunday, April 3, 2011

SASH visualization using Excel

OraSASH is a free implementation of Oracle Active Session History mechanism but it is providing only raw tables with data. To help other people use that functionality and inspired by Charles Hooper blog I have created a Excel based simple GUI interface for SASH. It is providing historical and real time view based on repository. It has been tested on Windows 7 64 bit with 32 bit Excel 2007. To make it running it is necessary to install and configure Oracle ODAC 11.2.0.2. Zip file can be downloaded from SourceForge repository. Please be aware that this is alpha stage of this Excel sheet and it can contain errors. Read only access is needed to OraSASH repository. Macros have to be enabled in Excel as all functionality is based on Visual Basic.

Setup sheet
Fill out repository user and tns alias name on Setup sheet and click Start button.


Historic data should be read from repository for whole available period of time and available instances list will be fill out as well. When all data will be collected active sheet will be switched to Graph sheet.
Graph sheet

There are two charts on Graph sheet – upper one is displaying Average Active Session - for AAS concept see John Beresniewicz presentation or Kyle Hailey blog.
Chart on the right side is displaying SQL activity for selected period of time. Percent of activity is calculated against number of all samples from that time. This same activity percent can be seen on OEM performance tab. SQL details like query text and plan will be displayed in Detail SQL view when chart bar for appropriate SQL ID will be clicked.
Historic view
To change period displayed on screen change start and stop date and then click Refresh Historic View button. 
Real time view
To see current database activity switch radio button to Real Time refresh. Refresh rate can be change on this same sheet in Refresh Rate field. It take one full refresh cycle to pick up a refresh new value.
Detail SQLsheet

Separate sheet for every SQL query. Sheet name is SQL_ID and detail available information about query text and plan will be displayed there. In addition to that detail information about wait event and CPU utilization will be displayed as well.

If you have any comments or questions please feel free to contact me.
regards,
Marcin

Saturday, April 2, 2011

Oracle XE 11g - beta release

Hello,

Good news Oracle XE 11g has been released. Right now it is a beta version but we can expect production release soon. I was waiting for that release as my idea was to use it a repository database for S-ASH. I'm going to check if all new 11g functionality like PIVOT functions will be working fine.


regards,
Marcin

Friday, April 1, 2011

New version of S-ASH

Hello,

I'm pleased to inform you that new version of Simulate ASH has been published.
You can download it from ASH Masters website or from Source Forge project site.

If you have any questions or ideas how to improve it please feel free to contact me


regards,
Marcin