Working with Oracle’s Time Model Data 3

In the previous article in this series, we created a structured view of the V$SYS_TIME_MODEL view:

Then on demand brought in session level detail for the same statistics so that it was possible to investigate why a statistic value continued to grow. The previous article also displayed delta values from V$OSSTAT and the wait events from V$SYSTEM_EVENT. It appears that a couple people liked the previous effort, and I gave serious thought to having the computer provide audio feedback when a session started consuming a lot of resources – but then I started to wonder if maybe we should instead have an audio warning when a session is consuming less than the average resource consumption so that we could then determine who is reading this article rather than working. :-) In the end, I decided to leave out the audio feedback. So, what else can we do with the framework that was provided in the second article of this series?

It might be nice to be able to drill into session-level wait events to determine why a wait event’s time delta keeps growing, maybe by adding a couple of extra buttons to the web page that is created on the fly by the VBS script:

It might also be nice to be able to view the DBMS_XPLAN for a query that was identified as a SQL statement that was recently executed by a session. One of the problems with the original script is that it only retrieved the SQL_ID and SQL_CHILD_NUMBER from V$SESSION, and it seemed that those columns contained NULL values just as frequently as they contained data. The updated script will attempt to return the PREV_SQL_ID and PREV_CHILD_NUMBER columns if the other two columns contain NULL values. In addition to retrieving the DBMS_XPLAN for the CHILD_NUMBER that is executed by the session, it might also be helpful to retrieve the DBMS_XPLAN for all child cursors for a given SQL_ID so that we are able to determine if the execution plan changed, and why it changed. While we are at it, let’s make it possible to enable a 10046 extended SQL trace for a session just by clicking a button on the web page. With the changes to the script, the generated web page might look something like this (note that this is a touched up image – the computer name and username were erased):

Scrolling down to the bottom of the page, note that the Session Waits button for the db file scattered read wait event was clicked:

So, what happens if one of the XPlan buttons is clicked? We could just write the execution plan to a text file, but where is the fun in doing that? How about popping up another web browser page that lists all execution plans for a query that are currently in the library cache, the reasons for those generated execution plans from V$SQL_SHARED_CURSOR, and the bind variable definitions from V$SQL_BIND_METADATA. The generated web page might look something like this (with duplicate sections from the different child cursors removed to save space):

In the above, the selected session was actually using the execution plan for child number 3. Notice that one of the execution plans converted normal B*Tree indexes on the fly to permit comparisons much like what are possible with bitmap indexes. A large portion of the execution plans were created, at least in part, because of a bind mismatch – see the documentation V$SQL_SHARED_CURSOR for more information.

This example requires at a minimum Oracle Database 10.1.0.1 running on Windows, Unix, or Linux. The supplied script must be run from a Windows client computer. You will need to specify a suitable username, password, and database name (from tnsnames.ora) for the strUsername, strPassword, and strDatabase variables in the VBS script. This script ties into several of the chapters in the Expert Oracle Practices book.

Download the script from here: MonitorDatabaseTimeModel.vbs (save as MonitorDatabaseTimeModel.vbs, without the .doc extension – note that this is version 2.0.1)

Actions

Information

7 responses

Fixed a problem in the original script with the delta values of the session level wait events not calculating correctly in the script due to a missing explicit data type conversion function. Added in the 2.0.1 version the last update date/time, CPU utilization percent, and User Mode CPU utilization percent.

Big improvement to already very hand first version in a short time Charles.
It is amazing/inspiring to see how you can cope with
Managing a team (from my understanding you are a permanent employee)
Answering questions on forums
Writing min 5 posts a week (your frequency is currently biggest problems against my blogroll report :) I cannot keep up )
Developing the tools and sharing them
Writing book
preparing for presentations and giving them
and god knows what is going on in Oak table mailing list :)

Thank you very much for this script and your contributions Charles. you are definitely the most fruitful blogger since you started

Thanks for stopping by and offering a compliment to me regarding the blog. I was concerned that when I started the blog on November 30, 2009 that I would have little or nothing that is useful to offer to visitors of the blog. In the 97 days that have elapsed since the start of the blog, there are 154 published blog articles with 2 more that are just about ready to appear on Monday and Tuesday – that means I have averaged 1.6 blog articles per day. But I have been slowing down lately, as you mention, to just 5 blog articles per week because I am running out of what I consider to be interesting topics. There are so many great Oracle blogs on the Internet, and that makes it difficult to find topics that have not already been written much better than any blog article that I could put together (the blogs of Jonathan Lewis and Richard Foote immediately come to mind).

Yes, I have been a permanent employee for the last 10 years at my current employer. DBA work is just one component (seemingly small in the big picture) of my responsibilities at the company. The days are typically quite long, but I try to set aside time each day to learn something new, or try to remember something that I once knew and have since forgotten. Participating in the forums helps quite a bit to keep me from forgetting too much, as does maintaining this blog. Writing the two chapters for the book with Randolf also helped a lot to keep from forgetting things and to learn new things – Randolf caught a lot of silly mistakes and faulty reasoning in the chapters before I had a chance to analyze the technical details of the chapters. Without Randolf’s contributions in the chapters (some days he worked as late as 2 AM on the chapters), the technical quality of the chapters would not have met, much less exceeded, my expectations.

There are some very technical discussions on the OakTable mailing list. When I was offered membership in 2008 my name was added to a list with 61 other people’s names – I suspected that all 61 of the other people knew more about Oracle’s inner workings than I did. Nearly two years later my name is still on the list, now with about 80 other names – now I am certain that all 80+ of the other people on the list know more about Oracle’s inner workings than I do, but at least that recognition serves as an incentive to continue learning, and hopefully reduce the rate at which I forget things.

Woow long answer for a busy man again. About the book I have one more chapter left and your two chapter is in my top 5 list. I have been following you and Randolf since the beginning and what I can easily say is those two chapters have nearly same type of authoring like your blogs and I while reading I was wondering what was Randolfs part but now I know that Randolf was working behind the scenes. I really enjoyed reading and thank you both for writing them. I hope I will finish my review and be the first non-author review of the book ;)

For the above script I could not find anything about disabling the trace in the code, I wonder if forgot to put it or did not put it on purpose. If it is on purpose I would really appreciate, if you can share the idea behind it

By the way I have changed the code to get the hardcoded values as parameters for ease of use.

Just to clarify (my initial response may have been misleading), I did not write all of the contents of the two chapters, and Randolf did not just act behind the scenes. Randolf’s knowledge of 10053 trace files (yes he wrote that section), parallel queries, partitioning, and for many other subtopics exceeds my knowledge of those subtopics. Randolf worked behind the scenes on the portions of the chapters that I wrote, and I did the same for the sections of the chapters that he wrote. I had a couple of weeks (maybe a month) of a head start on the writing compared to Randolf because of the demands placed on his time by his employer, so he had the fun of reading through about 40-70 pages of material before I had a chance to even start proofreading. Once all of the sections were written, I went through the chapters with Randolf’s assistance to standardize the writing style, and make certain that the chapters were written using formal English, rather than the casual English style writing that you see in our blogs.

I am very happy that our chapters are in your top 5 list. I am looking forward to your review of the book.

You are correct that I did not provide a method to disable the 10046 trace in the script – that was intentional. The great thing about the scripts that I have provided is that if you follow the pattern and logic of the scripts, you can easily extend the scripts for other tasks, such as adding another button to disable the 10046 trace, removing the hardcoded username and password, etc. Someone else took my automated DBMS_XPLAN tool and added a logon window to remove the hardcoded username and password.

I think I was misunderstood too. I did not intend to say that Randolf was behind the scenes but after reading chapters and knowing both your writing style, my initial thought was that this writing style mostly looks like Charles Hoopers style and thats why I use that term.
Anyways thank you very much for the clarification for both chapters and script. Now I have a homework to put disable option to sqltrace

Hints for Posting Code Sections in Comments

********************
When the spacing of text in a comment section is important for readability (execution plans, PL/SQL blocks, SQL, SQL*Plus output, etc.) please use a <pre> tag before the code section and a </pre> tag after the code section:

<pre>

SQL> SELECT
2 SYSDATE TODAY
3 FROM
4 DUAL;
TODAY
---------
01-MAR-12

</pre>
********************
When posting test case samples, it is much easier for people to reproduce the test case when the SQL*Plus line prefixes are not included - if possible, please remove those line prefixes. This:

SELECT
SYSDATE TODAY
FROM
DUAL;

Is easier to execute in a test case script than this:

SQL> SELECT
2 SYSDATE TODAY
3 FROM
4 DUAL;

********************
Greater than and Less than signs in code sections are often interpretted as HTML formatting commands. Please replace these characters in the code sections with the HTML equivalents for these characters: