SlideShare a Scribd company logo
1
I am not OEM savvy !
The notes sections in this presentation also provide links to some of my blog posts
2
Only a small set of privileges are really required.
Also look at the OEM_MONITOR role that has ANALYZE ANY , SELECT ANY, SELECT
ANY DICTIONARY and ADVISOR privileges, none of which I use (although ADVISOR
may be useful).
For a short note on the difference between SELECT ANY DICTIONARY and
SELECT_CATALOG_ROLE see http://hemantoracledba.blogspot.com/2014/02/the-
difference-between-select-any.html
SELECT ANY can be useful if you need to query data (e.g. To identify distribution
patterns and skew) in a schema – but the owner might prefer to grant you SELECT
privileges on only a subset of tables --- that sort of requirement comes in handy
when doing Performance Tuning, which is outside of the scope of this presentation.
If you plan to use PLSQL (e.g. to schedule jobs to collect this monitoring information),
you *will* need direct privileges on the underlying views. For example, on
V_$SESSION, V_$SQL etc.
There are many System Privileges and Object level privileges that can be granted to
Junior DBAs, Performance Analysts etc without having to grant the DBA role.
3
These are the privileges I need. I don’t use ADVISORs but do use AWR.
4
See
select table_name, privilege from dba_tab_privs
where grantee = 'SELECT_CATALOG_ROLE‘
The fewer V$ joins you need to make the better. Also, some V$ views are preferable
over others. Remember that Oracle does not provide the same read-consistency for
V$ (and X$ !) views as for permanent tables and views. Joining V$ views (to each
other or to DBA_% views) does not guarantee read consistency across the join.
5
Columns that have been retrieved from V$SESSION_WAIT are now available in
V$SESSION. V$SQL preferred over V$SQLAREA because the latter does an
aggregation (across all Child Cursors).
When I join V$SESSION to V$SQL, I join on both SQL_ID and CHILD_NUMBER.
Similarly, I prefer V$SEGSTAT over V$SEGMENT_STATISTICS – the former is faster.
If you don’t have the Diagnostic Pack for V$ASH, you could sample V$SESSION quickly
with custom code.
6
What I intend to show is how to interpret the STATE. WAITED_SHORT_TIME means
that it is *not* currently in a Wait. The EVENT is the last wait, not current.
So, although the session is ACTIVE, it is not in a Wait. It is most likely on CPU.
7
Note the change to the WAITING on “free buffer waits”. That *is* the CURRENT Wait
as at the time of the snapshot. (Similarly, the “db file scattered read” wait after that).
So, at the bottom of this slide, the session’s current SQL has been active for 55
seconds and is currently in a multiblock read wait.
8
Note how the *current* wait status can keep changing. Have you noted SEQ#
incrementing ? That indicates that the Wait Events *are* changing.
9
Recursive SQLs called by DBMS_STATS (or any PLSQL procedure) are are at a depth
level below. The top level is dep=0, the succeeding levels are 1 and beyond.
10
The GATHER_TABLE_STATS ran for 25seconds. The LAST_CALL_ET against SID=135
(HEMANT’s session) was incremented across all the SQL calls, even though the SQL
calls (at lower depths of 1 and below) were changing. Therefore, in this case, the
LAST_CALL_ET is not for the SQL that was executing at that instant but for the calling
PLSQL – the DBMS_STATS.GATHER_TABLE_STATS call. So, when running PLSQL
beware that LAST_CALL_ET may not reflect the current SQL !
(Note the SQL_ID 8y9… statement – it was waiting on PQ slaves (I haven’t shown
those PQ slave sessions, but they id exist)
11
This slide is not necessarily part of this presentation. It is just to demonstrate that a
PLSQL (the DBMS_STATS.GATHER_TABLE_STATS in this case) can call multiple SQLs, at
different recursive depth levels. (From dep=0 to dep=4 in this case). So, when you
are monitoring V$SQL_ID in V$SESSION, you might get a statement that is at a much
lowe depth.
12
Note here that this session is WAITING on a message from client. Is it Idle ? Should
the DBA ignore this ? Let’s look at the next slide.
13
Note SEQ# incrementing ? Even though the status is INACTIVE and the wait is
“SQL*Net message from client” (In theory an “idle wait”) ?
What is really happening here is that the user or application server is running a query
that is retrieving a large number of rows. Between every ARRAY FETCH, the server
process has to wait for the client to acknowledge having received the rows – that is
the “SQL*Net message from client” wait.
Here the user says that his query is ACTIVE. And he is right ! The user is complaining
that the query is long running but the actual Database Time the DBA sees is very low.
Most of the time is being spent sending rows and waiting for the acknowledgement.
14
Note the last wait at SEQ#34020. It is now 4 seconds ! Let’s see the next slide.
15
The SEQ# is still 34020. Now, this is truly an idle “SQL*Net message from client” wait.
The server is waiting for the client to send the next SQL command. It has finished
sending the results of the last SQL statement. LAST_CALL_ET now reflect the time it
is idle – because it is the time since the last call ended.
16
I don’t have SELECT privilege on the underlying table in the HEMANT schema. Yet, I
can get the execution plan. I don’t need the SELECT privilege on the underlying
table(s) or the SELECT ANY privilege or the DBA role to be able to do this.
17
Because I have SELECT_CATALOG_ROLE, I can query the underlying statistics.
18
I can create AWR snapshots because I have EXECUTE on
DBMS_WORKLOAD_REPOSITORY. I don’t need to be granted the DBA role.
I can use SQLDeveloper 4.0.1 to generate an AWR report without logging in to the
server as “oracle”
19
I can retrieve historical execution plans captured by AWR.
20
Too many people on the Internet think that this view shows how long the query is
running and how long it is expected to continue.
It shows the *current operation* not the whole SQL. An SQL Query can consist of
multiple operations. Even Parallel Query can run different block ranges using multiple
passes, each pass is a separate operation (and each PQ slave a separate session, so a
separate row in this view).
21
Here is an SQL that a user is executing. He is querying 3 different tables. Let’s see in
the next few slides if V$SESSION_LONGOPS shows the execution of the whole SQL or
parts (operations) only.
22
Look a the SQL_PLAN_LINE_ID. This extract from V$SESSION_LONGOPS is for only
one step in the Execution Plan. The SOFAR, ELAPSED_SECONDS and
TIME_REMAINING are for that one operation – reading table
HEMANT.LARGE_TABLE_2
The estimated time for this operation is 15+26 = 41seconds.
23
The operation has been running for 32seconds and still needs another 30seconds (i.e.
62seconds in all, not the 42seconds estimated earlier). Oracle is continously revising
the estimated.
24
After the operation on Execution Plan Step 4 had completed, V$SESSION_LONGOPS
stopped reporting this session. But is the session still active ?
25
The session is still active. It is now on Execution Plan Step 5 – the next table in the
SQL operation.
A database server process can do only 1 thing at a time. If it is querying
LARGE_TABLE_2, it cannot also be querying LARGE_TABLE_3 at the same time. The
retrieval of rows from LARGE_TABLE_3 is sequentially done later ! (Parallel Query is
a way around the fundamental rule that a process can be doing only one thing at any
time – PQ spawns multiple processes to do multiple things (reads from different
block ranges and/or partitions of the same table) concurrently)
26
In the previous slide, the estimate for the read from HEMANT.LARGE_TABLE_3 was
(12 + 51) 63seconds. It is now 53seconds.
27
The estimate has now changed to 65seconds.
For another example of misreading V$SESSION_LONGOPS on a DML that does a Full
Table Scan see http://hemantoracledba.blogspot.com/2009/01/when-not-to-use-
vsessionlongops.html
28
I had mentioned earlier that a query that sends multiple rows to a client / application
server sends the rows in batches – based on the ARRAY Size. Search my blog for
examples of ARRAYSIZE (and LINESIZE and PAGESIZE if using an SQLPlus Client) {I
have a few different blogposts on this}
I have shown earlier how the “SQL*Net message from client” isn’t always an Idle
Event. The presence of this wait event, with increasing SEQ# can indicate array
fetches.
29
Note the two queries retrieved the same number of rows. The elapsed time reported
by the client would have included the “SQL*Net message wait from client” wait event
on the server for the multiple round trips. The FETCHES count indicates the round-
trips. The first SQL used an ARRAYSIZE of 100, the second was doing a Row-By-Row
FETCH. (The extra 1 FETCH is always present when you run an SQL, you’ll even see it
in the trace file as a FETCH with 0 rows executed first).
30
DBA_HIST_ACTIVE_SESS_HISTORY is a sample every 10seconds (not “1 in
10samples”). If I want to see the “distribution of a session or SQL over the CPU and
wait events”, I look at the number of samples, not a summation of TIME_WAITED.
The composite key for an SQL execution within a session is SQL_ID, SQL_EXEC_START,
SQL_EXEC_ID
Remember : SQL Operations that completed between 2 snapshots (SAMPLE_TIME)
are *not* captured !!
Here I present only a few examples of analysis using this view. There are many more
useful columns like BLOCKING%, CURRENT%, QC% (e.g. I’ve seen people look at
PGA_ALLOCATED and TEMP_SPACE_ALLOCATED and have a query based on these as
well).
31
I’ve not shown the filter by SAMPLE_TIME here. It is a very short elapsed time of
operations by Session 195. I can see that most of the samples indicate waiting on “db
file sequential read” – more so than On CPU. I say “more samples” rather than “more
time” as being more accurate.
32
Here, the session ran multiple SQL statements. I can see the distribution of CPU and
Wait Events amongst the different SQL.
33
Here, I filter for a MODULE, rather than a SESSION (I’ve not shown the filter by
SAMPLE_TIME). (Note : “log file sync” wait may not always show which the SQL_ID
was that was waiting on the Event).
34
Here, I query for the last 30minutes.
35
Here, I can also see, for each SQL, the time on each Step in the Execution Plan. So, I
know which Step is likely to have accounted for more time (on the basis of the
number of times it was sampled) !
36
Distribution of CPU Usage (this is an approximation because it is based on a sample
taken every 10seconds only !) This is based on number of occurrences in samples,
not actual time spent on CPU. But we could approximate the one for the other.
37
To chart the number of sessions in ON_CPU and in WAITING states. You could select
for a specific wait event as well.
(SQLPLUS allows you to use SET COLSEP ‘,’ and SET PAGESIZE 0 to spool to a CSV file)
Note : Information available in V$ACTIVE_SESSION_HISTORY is limited by memory
space allocated.
38
This is another way to represent Active Sessions.
39
Extract previous occurrences of an SQL from AWR history
40
The same SQL has had varying numbers of Buffer Gets and Rows Processed. For
example, in Snapshot 1088, there was 1 execution for 3million rows. The other two
snapshots had 2 or 3 executions for 676K or 768K rows each.
Note : PLAN_HASH_VALUE does not change if ROWS or COST changes. See
http://hemantoracledba.blogspot.com/2014/03/plan-hashvalue-remains-same-for-
same.html (So, two queries with the same P_H_V don’t have to have the same
expected runtime !)
41
If Resource Manager is implemented, I can also look at the CPU usage by each
Consumer Group.
Note : When “Virtual CPUs” (as in VMs or HyperThreading) are used, the CPU Count
may be larger than the number of actual cores so CPU time may be misleading
relative to the actual number of cores.
42
I can see how many PQs are running (look at QCSID as the Query Co-ordinator). I can
see if each QC did get the actual degree (DEGREE) that was requested (REQ_DEGREE).
So, if the server doesn’t have enough PARALLEL_MAX_SERVERS, the actual degree
may be less than the requested degree.
Thus, at 00:15, there was 1 query requesting DoP=4, getting Dop=4 but actually
running with 8 PQ slaves (Parallel Execution Servers). Why, because a query may take
2 (or, in very rare cases, more) Slave Sets.
At 00:17, there were two queries from two different sessions executing with a total of
12 PX servers.
See my blog posts on PX Servers.
43
Very important : UNDO RECORDS is NOT the same (or same size) as Table Rows or
Index Entries.
44
You can check the distribution of transactions across different Undo Segments.
Remember : The SQL_ID is only the current SQL. A transaction can consist of multiple
DMLs, including SELECT queries ! The current SQL may be a SELECT but the
transaction may have 1 or 100 or 1000 INSERT/UPDATE/DELETE statements before
this.
The transaction started rolling back after 00:28:15. (Also note that Current SQL_ID is
not always available)
45
I can compare CPU time with Wait Events time. I can identify the top Wait. I can
filter for statistics or waits that I am particularly interested in.
46
I can select which Statistics and which Wait Events are of interest to me for this
particular database instance. (Different application profiles may have different
interesting Statistics and Waits !)
This gives me a “Profile” view of the Instance
47
Note : Time_Waited and CPU used are both in Centi-seconds.
Here I can compare CPU time with time on major wait events. I can also look at
major statistics that I can filter.
48

More Related Content

What's hot (20)

PDF
SQL injection: Not Only AND 1=1 (updated)
Bernardo Damele A. G.
 
PPTX
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
PDF
Extending MySQL Enterprise Monitor
Mark Leith
 
PDF
Sql Injection 0wning Enterprise
n|u - The Open Security Community
 
PDF
Sql injection with sqlmap
Herman Duarte
 
PDF
Advanced SQL injection to operating system full control (slides)
Bernardo Damele A. G.
 
PPSX
Sql Performance Tuning with ASH & AWR: Real World Use Cases
vbarun01
 
PPTX
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Alex Zaballa
 
PPTX
View, Store Procedure & Function and Trigger in MySQL - Thaipt
Framgia Vietnam
 
PDF
Pl sql-ch3
Mukesh Tekwani
 
PDF
Basic - Oracle Edition Based Redefinition Presentation
N/A
 
PPT
Developing Information Schema Plugins
Mark Leith
 
PPSX
Barun_Practical_and_Efficient_SQL_Performance_Tuning
Vlado Barun
 
PDF
FIXING BLOCK CORRUPTION (RMAN) on 11G
N/A
 
PDF
Usertracing
oracle documents
 
PPTX
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Alex Zaballa
 
PDF
Flashback - The Time Machine..
Navneet Upneja
 
PPT
Oracle-L11 using Oracle flashback technology-Mazenet solution
Mazenetsolution
 
PPT
Database security
Javed Khan
 
PDF
Developing for Node.JS with MySQL and NoSQL
John David Duncan
 
SQL injection: Not Only AND 1=1 (updated)
Bernardo Damele A. G.
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
Extending MySQL Enterprise Monitor
Mark Leith
 
Sql Injection 0wning Enterprise
n|u - The Open Security Community
 
Sql injection with sqlmap
Herman Duarte
 
Advanced SQL injection to operating system full control (slides)
Bernardo Damele A. G.
 
Sql Performance Tuning with ASH & AWR: Real World Use Cases
vbarun01
 
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Alex Zaballa
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
Framgia Vietnam
 
Pl sql-ch3
Mukesh Tekwani
 
Basic - Oracle Edition Based Redefinition Presentation
N/A
 
Developing Information Schema Plugins
Mark Leith
 
Barun_Practical_and_Efficient_SQL_Performance_Tuning
Vlado Barun
 
FIXING BLOCK CORRUPTION (RMAN) on 11G
N/A
 
Usertracing
oracle documents
 
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Alex Zaballa
 
Flashback - The Time Machine..
Navneet Upneja
 
Oracle-L11 using Oracle flashback technology-Mazenet solution
Mazenetsolution
 
Database security
Javed Khan
 
Developing for Node.JS with MySQL and NoSQL
John David Duncan
 

Similar to Oracle : Monitoring and Diagnostics without OEM (20)

PPT
Introduction to Parallel Execution
Doug Burns
 
DOC
Analyzing awr report
satish Gaddipati
 
PPTX
SQL Server Wait Types Everyone Should Know
Dean Richards
 
PDF
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
cookie1969
 
PDF
Analyzing and Interpreting AWR
pasalapudi
 
PPT
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
John Kanagaraj
 
PPTX
SQL Tuning, takes 3 to tango
Mauro Pagano
 
PPT
Oracle Open World Thursday 230 ashmasters
Kyle Hailey
 
PPT
AWR, ADDM, ASH, Metrics and Advisors.ppt
bugzbinny
 
PPTX
Oracle performance tuning_sfsf
Mao Geng
 
PPT
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
udaymoogala
 
PPT
Ash masters : advanced ash analytics on Oracle
Kyle Hailey
 
PDF
Apps session wait_tables
Anil Pandey
 
PDF
Oracle Query Tuning Tips - Get it Right the First Time
Dean Richards
 
PDF
Collaborate 2019 - How to Understand an AWR Report
Alfredo Krieg
 
PDF
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
cookie1969
 
PPTX
Further Adventures With ASH
David Kurtz
 
PPTX
It Depends
Maggie Pint
 
PDF
Ebs dba con4696_pdf_4696_0001
jucaab
 
PDF
Oracle database performance tuning
Abishek V S
 
Introduction to Parallel Execution
Doug Burns
 
Analyzing awr report
satish Gaddipati
 
SQL Server Wait Types Everyone Should Know
Dean Richards
 
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
cookie1969
 
Analyzing and Interpreting AWR
pasalapudi
 
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
John Kanagaraj
 
SQL Tuning, takes 3 to tango
Mauro Pagano
 
Oracle Open World Thursday 230 ashmasters
Kyle Hailey
 
AWR, ADDM, ASH, Metrics and Advisors.ppt
bugzbinny
 
Oracle performance tuning_sfsf
Mao Geng
 
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
udaymoogala
 
Ash masters : advanced ash analytics on Oracle
Kyle Hailey
 
Apps session wait_tables
Anil Pandey
 
Oracle Query Tuning Tips - Get it Right the First Time
Dean Richards
 
Collaborate 2019 - How to Understand an AWR Report
Alfredo Krieg
 
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
cookie1969
 
Further Adventures With ASH
David Kurtz
 
It Depends
Maggie Pint
 
Ebs dba con4696_pdf_4696_0001
jucaab
 
Oracle database performance tuning
Abishek V S
 
Ad

More from Hemant K Chitale (7)

PDF
SQL Tracing
Hemant K Chitale
 
PDF
Oracle Diagnostics : Joins - 1
Hemant K Chitale
 
PDF
Oracle Diagnostics : Explain Plans (Simple)
Hemant K Chitale
 
PDF
Partitioning Tables and Indexing Them --- Article
Hemant K Chitale
 
PDF
Oracle database performance diagnostics - before your begin
Hemant K Chitale
 
PDF
The role of the dba
Hemant K Chitale
 
PDF
Partitioning tables and indexing them
Hemant K Chitale
 
SQL Tracing
Hemant K Chitale
 
Oracle Diagnostics : Joins - 1
Hemant K Chitale
 
Oracle Diagnostics : Explain Plans (Simple)
Hemant K Chitale
 
Partitioning Tables and Indexing Them --- Article
Hemant K Chitale
 
Oracle database performance diagnostics - before your begin
Hemant K Chitale
 
The role of the dba
Hemant K Chitale
 
Partitioning tables and indexing them
Hemant K Chitale
 
Ad

Recently uploaded (20)

PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 

Oracle : Monitoring and Diagnostics without OEM

  • 1. 1
  • 2. I am not OEM savvy ! The notes sections in this presentation also provide links to some of my blog posts 2
  • 3. Only a small set of privileges are really required. Also look at the OEM_MONITOR role that has ANALYZE ANY , SELECT ANY, SELECT ANY DICTIONARY and ADVISOR privileges, none of which I use (although ADVISOR may be useful). For a short note on the difference between SELECT ANY DICTIONARY and SELECT_CATALOG_ROLE see http://hemantoracledba.blogspot.com/2014/02/the- difference-between-select-any.html SELECT ANY can be useful if you need to query data (e.g. To identify distribution patterns and skew) in a schema – but the owner might prefer to grant you SELECT privileges on only a subset of tables --- that sort of requirement comes in handy when doing Performance Tuning, which is outside of the scope of this presentation. If you plan to use PLSQL (e.g. to schedule jobs to collect this monitoring information), you *will* need direct privileges on the underlying views. For example, on V_$SESSION, V_$SQL etc. There are many System Privileges and Object level privileges that can be granted to Junior DBAs, Performance Analysts etc without having to grant the DBA role. 3
  • 4. These are the privileges I need. I don’t use ADVISORs but do use AWR. 4
  • 5. See select table_name, privilege from dba_tab_privs where grantee = 'SELECT_CATALOG_ROLE‘ The fewer V$ joins you need to make the better. Also, some V$ views are preferable over others. Remember that Oracle does not provide the same read-consistency for V$ (and X$ !) views as for permanent tables and views. Joining V$ views (to each other or to DBA_% views) does not guarantee read consistency across the join. 5
  • 6. Columns that have been retrieved from V$SESSION_WAIT are now available in V$SESSION. V$SQL preferred over V$SQLAREA because the latter does an aggregation (across all Child Cursors). When I join V$SESSION to V$SQL, I join on both SQL_ID and CHILD_NUMBER. Similarly, I prefer V$SEGSTAT over V$SEGMENT_STATISTICS – the former is faster. If you don’t have the Diagnostic Pack for V$ASH, you could sample V$SESSION quickly with custom code. 6
  • 7. What I intend to show is how to interpret the STATE. WAITED_SHORT_TIME means that it is *not* currently in a Wait. The EVENT is the last wait, not current. So, although the session is ACTIVE, it is not in a Wait. It is most likely on CPU. 7
  • 8. Note the change to the WAITING on “free buffer waits”. That *is* the CURRENT Wait as at the time of the snapshot. (Similarly, the “db file scattered read” wait after that). So, at the bottom of this slide, the session’s current SQL has been active for 55 seconds and is currently in a multiblock read wait. 8
  • 9. Note how the *current* wait status can keep changing. Have you noted SEQ# incrementing ? That indicates that the Wait Events *are* changing. 9
  • 10. Recursive SQLs called by DBMS_STATS (or any PLSQL procedure) are are at a depth level below. The top level is dep=0, the succeeding levels are 1 and beyond. 10
  • 11. The GATHER_TABLE_STATS ran for 25seconds. The LAST_CALL_ET against SID=135 (HEMANT’s session) was incremented across all the SQL calls, even though the SQL calls (at lower depths of 1 and below) were changing. Therefore, in this case, the LAST_CALL_ET is not for the SQL that was executing at that instant but for the calling PLSQL – the DBMS_STATS.GATHER_TABLE_STATS call. So, when running PLSQL beware that LAST_CALL_ET may not reflect the current SQL ! (Note the SQL_ID 8y9… statement – it was waiting on PQ slaves (I haven’t shown those PQ slave sessions, but they id exist) 11
  • 12. This slide is not necessarily part of this presentation. It is just to demonstrate that a PLSQL (the DBMS_STATS.GATHER_TABLE_STATS in this case) can call multiple SQLs, at different recursive depth levels. (From dep=0 to dep=4 in this case). So, when you are monitoring V$SQL_ID in V$SESSION, you might get a statement that is at a much lowe depth. 12
  • 13. Note here that this session is WAITING on a message from client. Is it Idle ? Should the DBA ignore this ? Let’s look at the next slide. 13
  • 14. Note SEQ# incrementing ? Even though the status is INACTIVE and the wait is “SQL*Net message from client” (In theory an “idle wait”) ? What is really happening here is that the user or application server is running a query that is retrieving a large number of rows. Between every ARRAY FETCH, the server process has to wait for the client to acknowledge having received the rows – that is the “SQL*Net message from client” wait. Here the user says that his query is ACTIVE. And he is right ! The user is complaining that the query is long running but the actual Database Time the DBA sees is very low. Most of the time is being spent sending rows and waiting for the acknowledgement. 14
  • 15. Note the last wait at SEQ#34020. It is now 4 seconds ! Let’s see the next slide. 15
  • 16. The SEQ# is still 34020. Now, this is truly an idle “SQL*Net message from client” wait. The server is waiting for the client to send the next SQL command. It has finished sending the results of the last SQL statement. LAST_CALL_ET now reflect the time it is idle – because it is the time since the last call ended. 16
  • 17. I don’t have SELECT privilege on the underlying table in the HEMANT schema. Yet, I can get the execution plan. I don’t need the SELECT privilege on the underlying table(s) or the SELECT ANY privilege or the DBA role to be able to do this. 17
  • 18. Because I have SELECT_CATALOG_ROLE, I can query the underlying statistics. 18
  • 19. I can create AWR snapshots because I have EXECUTE on DBMS_WORKLOAD_REPOSITORY. I don’t need to be granted the DBA role. I can use SQLDeveloper 4.0.1 to generate an AWR report without logging in to the server as “oracle” 19
  • 20. I can retrieve historical execution plans captured by AWR. 20
  • 21. Too many people on the Internet think that this view shows how long the query is running and how long it is expected to continue. It shows the *current operation* not the whole SQL. An SQL Query can consist of multiple operations. Even Parallel Query can run different block ranges using multiple passes, each pass is a separate operation (and each PQ slave a separate session, so a separate row in this view). 21
  • 22. Here is an SQL that a user is executing. He is querying 3 different tables. Let’s see in the next few slides if V$SESSION_LONGOPS shows the execution of the whole SQL or parts (operations) only. 22
  • 23. Look a the SQL_PLAN_LINE_ID. This extract from V$SESSION_LONGOPS is for only one step in the Execution Plan. The SOFAR, ELAPSED_SECONDS and TIME_REMAINING are for that one operation – reading table HEMANT.LARGE_TABLE_2 The estimated time for this operation is 15+26 = 41seconds. 23
  • 24. The operation has been running for 32seconds and still needs another 30seconds (i.e. 62seconds in all, not the 42seconds estimated earlier). Oracle is continously revising the estimated. 24
  • 25. After the operation on Execution Plan Step 4 had completed, V$SESSION_LONGOPS stopped reporting this session. But is the session still active ? 25
  • 26. The session is still active. It is now on Execution Plan Step 5 – the next table in the SQL operation. A database server process can do only 1 thing at a time. If it is querying LARGE_TABLE_2, it cannot also be querying LARGE_TABLE_3 at the same time. The retrieval of rows from LARGE_TABLE_3 is sequentially done later ! (Parallel Query is a way around the fundamental rule that a process can be doing only one thing at any time – PQ spawns multiple processes to do multiple things (reads from different block ranges and/or partitions of the same table) concurrently) 26
  • 27. In the previous slide, the estimate for the read from HEMANT.LARGE_TABLE_3 was (12 + 51) 63seconds. It is now 53seconds. 27
  • 28. The estimate has now changed to 65seconds. For another example of misreading V$SESSION_LONGOPS on a DML that does a Full Table Scan see http://hemantoracledba.blogspot.com/2009/01/when-not-to-use- vsessionlongops.html 28
  • 29. I had mentioned earlier that a query that sends multiple rows to a client / application server sends the rows in batches – based on the ARRAY Size. Search my blog for examples of ARRAYSIZE (and LINESIZE and PAGESIZE if using an SQLPlus Client) {I have a few different blogposts on this} I have shown earlier how the “SQL*Net message from client” isn’t always an Idle Event. The presence of this wait event, with increasing SEQ# can indicate array fetches. 29
  • 30. Note the two queries retrieved the same number of rows. The elapsed time reported by the client would have included the “SQL*Net message wait from client” wait event on the server for the multiple round trips. The FETCHES count indicates the round- trips. The first SQL used an ARRAYSIZE of 100, the second was doing a Row-By-Row FETCH. (The extra 1 FETCH is always present when you run an SQL, you’ll even see it in the trace file as a FETCH with 0 rows executed first). 30
  • 31. DBA_HIST_ACTIVE_SESS_HISTORY is a sample every 10seconds (not “1 in 10samples”). If I want to see the “distribution of a session or SQL over the CPU and wait events”, I look at the number of samples, not a summation of TIME_WAITED. The composite key for an SQL execution within a session is SQL_ID, SQL_EXEC_START, SQL_EXEC_ID Remember : SQL Operations that completed between 2 snapshots (SAMPLE_TIME) are *not* captured !! Here I present only a few examples of analysis using this view. There are many more useful columns like BLOCKING%, CURRENT%, QC% (e.g. I’ve seen people look at PGA_ALLOCATED and TEMP_SPACE_ALLOCATED and have a query based on these as well). 31
  • 32. I’ve not shown the filter by SAMPLE_TIME here. It is a very short elapsed time of operations by Session 195. I can see that most of the samples indicate waiting on “db file sequential read” – more so than On CPU. I say “more samples” rather than “more time” as being more accurate. 32
  • 33. Here, the session ran multiple SQL statements. I can see the distribution of CPU and Wait Events amongst the different SQL. 33
  • 34. Here, I filter for a MODULE, rather than a SESSION (I’ve not shown the filter by SAMPLE_TIME). (Note : “log file sync” wait may not always show which the SQL_ID was that was waiting on the Event). 34
  • 35. Here, I query for the last 30minutes. 35
  • 36. Here, I can also see, for each SQL, the time on each Step in the Execution Plan. So, I know which Step is likely to have accounted for more time (on the basis of the number of times it was sampled) ! 36
  • 37. Distribution of CPU Usage (this is an approximation because it is based on a sample taken every 10seconds only !) This is based on number of occurrences in samples, not actual time spent on CPU. But we could approximate the one for the other. 37
  • 38. To chart the number of sessions in ON_CPU and in WAITING states. You could select for a specific wait event as well. (SQLPLUS allows you to use SET COLSEP ‘,’ and SET PAGESIZE 0 to spool to a CSV file) Note : Information available in V$ACTIVE_SESSION_HISTORY is limited by memory space allocated. 38
  • 39. This is another way to represent Active Sessions. 39
  • 40. Extract previous occurrences of an SQL from AWR history 40
  • 41. The same SQL has had varying numbers of Buffer Gets and Rows Processed. For example, in Snapshot 1088, there was 1 execution for 3million rows. The other two snapshots had 2 or 3 executions for 676K or 768K rows each. Note : PLAN_HASH_VALUE does not change if ROWS or COST changes. See http://hemantoracledba.blogspot.com/2014/03/plan-hashvalue-remains-same-for- same.html (So, two queries with the same P_H_V don’t have to have the same expected runtime !) 41
  • 42. If Resource Manager is implemented, I can also look at the CPU usage by each Consumer Group. Note : When “Virtual CPUs” (as in VMs or HyperThreading) are used, the CPU Count may be larger than the number of actual cores so CPU time may be misleading relative to the actual number of cores. 42
  • 43. I can see how many PQs are running (look at QCSID as the Query Co-ordinator). I can see if each QC did get the actual degree (DEGREE) that was requested (REQ_DEGREE). So, if the server doesn’t have enough PARALLEL_MAX_SERVERS, the actual degree may be less than the requested degree. Thus, at 00:15, there was 1 query requesting DoP=4, getting Dop=4 but actually running with 8 PQ slaves (Parallel Execution Servers). Why, because a query may take 2 (or, in very rare cases, more) Slave Sets. At 00:17, there were two queries from two different sessions executing with a total of 12 PX servers. See my blog posts on PX Servers. 43
  • 44. Very important : UNDO RECORDS is NOT the same (or same size) as Table Rows or Index Entries. 44
  • 45. You can check the distribution of transactions across different Undo Segments. Remember : The SQL_ID is only the current SQL. A transaction can consist of multiple DMLs, including SELECT queries ! The current SQL may be a SELECT but the transaction may have 1 or 100 or 1000 INSERT/UPDATE/DELETE statements before this. The transaction started rolling back after 00:28:15. (Also note that Current SQL_ID is not always available) 45
  • 46. I can compare CPU time with Wait Events time. I can identify the top Wait. I can filter for statistics or waits that I am particularly interested in. 46
  • 47. I can select which Statistics and which Wait Events are of interest to me for this particular database instance. (Different application profiles may have different interesting Statistics and Waits !) This gives me a “Profile” view of the Instance 47
  • 48. Note : Time_Waited and CPU used are both in Centi-seconds. Here I can compare CPU time with time on major wait events. I can also look at major statistics that I can filter. 48