Skip to Main Content
  • Questions
  • Want to get total SQL executions per day

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, KQ.

Asked: May 09, 2011 - 3:29 pm UTC

Last updated: September 18, 2020 - 4:29 pm UTC

Version: 11.1.0.7

Viewed 10K+ times! This question is

You Asked

Tom, your site has been very usefull, and usually I can get an answer by looking at past responses. However, this time I need to ask you a question.

An application analyst wants to track the total number of SQL executed per day in Prod database, and look at long term trends. I created the below query to get this info from V$SQL. After running for a few days, I found that one day the total executions went down. I was expecting a steady increase.

(Q1) Why would sum(executions) decrease if the database has not been restarted ?

(q2) Am I using the correct method to determine the total number of SQL executions since database was started ?


Ran below query for several days.

select i.instance_name "Database",
to_char(i.startup_time,'YYYY-MON-DD HH24:MI') "Started",
to_char(sysdate,'YYYY-MON-DD HH24:MI:SS') "Current Time",
sum(s.executions) "Tot Executions"
from v$instance@lk_prod1 i, v$sql@lk_prod1 s
group by i.instance_name, i.startup_time ;


Database Started Current Time Tot Executions
--------- ----------------- -------------------- ----------------
prod1 2011-FEB-15 16:15 2011-MAY-06 14:50:30 8,155,573,002
prod1 2011-FEB-15 16:15 2011-MAY-06 23:59:30 8,264,711,464
prod1 2011-FEB-15 16:15 2011-MAY-07 23:59:30 8,310,760,904
prod1 2011-FEB-15 16:15 2011-MAY-08 23:59:30 8,287,844,674 ??
prod1 2011-FEB-15 16:15 2011-MAY-09 14:21:18 8,391,105,271


On May 8, 2011 23:59, the total executions went down !. Did not expect this.
Appreciate your help

and Tom said...

v$sql is a v$ table, it is an in memory data structure of finite size.

All this means is that some sql aged out or was invalidated in your shared pool. Your shared pool - which is what v$sql shows you - is a data structure that grows and shrinks over time.


You would have to use AWR/ASH or statspack repositories for this type of analysis.


And it is a rather silly, meaningless metric. I question the validity of using it for "anything". What insight does this analyst hope to get from this? Knowing that the number of executions went up or down would only lead to more questions, it would provide no answers.


If the analyst really wants to "trend", you would get them hooked on Enterprise Manager and the AWR/ASH repositories - or if you do not have that, statspack at the very least.

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

check view

anbob, July 18, 2013 - 7:28 am UTC

starting 11g Release 1 (11.1) provides a view V$SQL_MONITOR
Tom Kyte
July 18, 2013 - 5:20 pm UTC

and that doesn't do what they asked for? it doesn't do anything remotely close to what they asked for.

that view shows sql we are currently monitoring or have recently monitored. it contains information for long running queries. MOST queries will never appear in there. And even those that do - we don't track the number of executions in that view

No of executions of query

Diwakar Krishnakumar, August 08, 2019 - 6:47 pm UTC

Sir,

Any suggested way to monitor for sudden increase of sql's in the database?

We had a situation where we identified that there was a query that was consuming so much of resources and that was after the number of executions of that query went up drastically.

Any way to pro-actively track and identify such queries, say those queries that have more than 10% increase in the total number of executions over a given period of time?

Regards,
K.Diwakar
Connor McDonald
August 09, 2019 - 6:34 am UTC

Check out DBA_HIST_SQLSTAT.

It can show you executions per SQL_ID over time.

Follow Up

Geraldo, September 18, 2020 - 2:32 pm UTC

What If I need the number of SQL_ID (query) executions in a period of time (e.g. 1 hour)?

Thanks in advanced.

Regards,
Chris Saxon
September 18, 2020 - 4:29 pm UTC

If you're licensed for AWR, you can get this from DBA_HIST_SQLSTAT (assuming the snap are taken at least hourly)

Otherwise you're looking at statspack.

More to Explore

Performance

Get all the information about database performance in the Database Performance guide.