How to Identify All SQLs That are Running Currenly

It is useful to be able to see all SQLs that are running along with how long it has been running, and the number of parallel sessions opened by the session running it etc.
The following script can do the job. Some of the columns are self explanatory. For other columns , a brief explanation is given below:

SQL_OPNAME – type of SQL (Select, Update etc)
SQL_EXEC_START_TM – SQL start time
MINS_RUNNING – how long this SQL has been running
PRLL_SESNS — Number of paralle sessions if the SQL is running in parallel
SQL_CNT – how many sessions running the same SQL
FMS_CNT – how many sessions running SQLs with the same force matching signature(often these are sessions running SQLs w/o binds that only differ in the value provided)
FMS – force matching signature

Script

--
-- sqlnow.sql
-- Parameters - none
--
-- Purpose: Identify all sqls that are running currenly
-- scripts also list how long it has been running, number of parallel sessions etc
--
set verify on
set echo on
set lines 250
set head on
set tab off

col username format a30
col fms format a30
col sql_exec_start_tm  format a17
col sql_cnt format 999999
col fms_cnt format 999999
col sql_opname format a10

WITH SQLS
     AS (SELECT /*+materialize no_merge*/
               DISTINCT sql_id, sql_exec_id
           FROM gv$session
          WHERE status = 'ACTIVE'
          --AND username IS NOT NULL
          --AND username NOT IN ('SYS', 'SYSTEM', 'DBSNMP')
        )
SELECT inst_id,
         session_id,
         SESSION_SERIAL#,
         (SELECT username
            FROM all_users
           WHERE user_id = ash.user_id) username,
         sql_id,
         sql_exec_id,
         sql_opname,
         to_char(MIN (sql_exec_start),'dd-mon-rr hh24:mi') sql_exec_start_tm ,
         CEIL ( (SYSDATE - MIN (sql_exec_start)) * 24 * 60) mins_running,
         COUNT (*) OVER (PARTITION BY sql_id || '-' || sql_exec_id) prll_sesns,
         COUNT (DISTINCT sql_exec_id || sql_exec_start)  OVER (PARTITION BY sql_id)  sql_cnt,
         case when FORCE_MATCHING_SIGNATURE != 0 then
		 COUNT (DISTINCT sql_exec_id || sql_exec_start)  OVER (PARTITION BY FORCE_MATCHING_SIGNATURE)
         end fms_cnt,
         TO_CHAR (FORCE_MATCHING_SIGNATURE) fms
         --MIN (sample_time) sample_time
    FROM gv$active_session_history ash
   WHERE (sql_id, sql_exec_id) IN (SELECT sql_id, sql_exec_id FROM sqls)
GROUP BY inst_id, session_id, SESSION_SERIAL#,user_id, sql_id,sql_opname, sql_exec_id, sql_exec_start,
         FORCE_MATCHING_SIGNATURE
         --HAVING SYSDATE - MAX (sql_exec_start) > (1 / 24 / 60 / 2)  running for more than 30 secs
ORDER BY mins_running DESC, fms
/

CLEAR COLUMNS
-- end of script

Sample Output

   INST_ID SESSION_ID SESSION_SERIAL# USERNAME                       SQL_ID        SQL_EXEC_ID SQL_OPNAME SQL_EXEC_START_ MINS_RUNNING PRLL_SESNS SQL_CNT FMS_CNT FMS
---------- ---------- --------------- ------------------------------ ------------- ----------- ---------- --------------- ------------ ---------- ------- ------- --------------------
         4       4898           21199 SALES                          55t1wf74z145c    67108864 SELECT     07-jan-15 12:37          219          1       2       2 12114432892951959166
         4       4384            2251 SALES                          55t1wf74z145c    67108865 SELECT     07-jan-15 13:07          189          1       2       2 12114432892951959166
         3       4628           64895 SALES                          rtkcs85g8twg7    50331648 SELECT     07-jan-15 16:10            6          1       1       1 8647423045760569048
         1        148            3437 SALES                          tygug4ak7vw7d    16777483 SELECT     07-jan-15 16:12            4          1       1       1 8416747714864488742
         3        695           21423 MARKETING                      7453fh3pxknh8    50331649 SELECT     07-jan-15 16:14            3          1       1       1 11026030165138208448
         3       4236           50751 MARKETING                      66yswb95s0chd    50331648 SELECT     07-jan-15 16:15            2          2       1       1 12290910331691816147
         3       4951           43791 MARKETING                      ggyswb95s0chd    50331648 SELECT     07-jan-15 16:15            2          2       1       1 67477148649674771486
         1       3840            3207 MARKETING                      883t81m5yu0hv    17912049 SELECT     07-jan-15 16:16            1          1       1       1 7298091671828702764

Conclusion

There are a total of eight active sessions running different SQLs when the report was generated. SQL with id 55t1wf74z145c has been running for 3+ hours. There are two sessions running the same SQL. But it is not a parallel query.SQL_CNT and FMS_CNT are the the same probably because bind variables are being used, or it may be exactly same SQLs.
This gives the picture of what each active session is doing currently. You can identify long running and parallel SQLs immediately from this report.

50 thoughts on “How to Identify All SQLs That are Running Currenly

  1. This is the right blog for anyone who wants to find out about this topic. You realize so much its almost hard to argue with you (not that I actually would want…HaHa). You definitely put a new spin on a topic thats been written about for years. Great stuff, just great!

  2. Greetings! I know this is kinda off topic but I’d figured I’d ask. Would you be interested in exchanging links or maybe guest authoring a blog article or vice-versa? My website goes over a lot of the same subjects as yours and I feel we could greatly benefit from each other. If you’re interested feel free to send me an e-mail. I look forward to hearing from you! Terrific blog by the way!

  3. A lot of of what you assert happens to be astonishingly appropriate and it makes me ponder why I hadn’t looked at this with this light before. Your piece really did switch the light on for me personally as far as this specific subject goes. But there is actually just one point I am not really too cozy with so whilst I make an effort to reconcile that with the actual central theme of your issue, let me observe what all the rest of your subscribers have to point out.Very well done.

  4. Hi there, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam responses? If so how do you prevent it, any plugin or anything you can recommend? I get so much lately it’s driving me crazy so any support is very much appreciated.

  5. What is Renew? Renew is a dietary supplement designed to support blood flow while also aiming to boost testosterone levels and provide an explosive energy drive

  6. There are some interesting deadlines in this article but I don’t know if I see all of them center to heart. There may be some validity but I’ll take maintain opinion until I look into it further. Good article , thanks and we wish extra! Added to FeedBurner as nicely

  7. I¦ve recently started a website, the information you provide on this web site has helped me tremendously. Thanks for all of your time & work.

  8. Heya i am for the first time here. I found this board and I find It truly helpful & it helped me out a lot. I hope to offer something again and help others like you aided me.

  9. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  10. When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks!

  11. What Is ZenCortex? ZenCortex is a natural supplement that promotes healthy hearing and mental tranquility. It’s crafted from premium-quality natural ingredients, each selected for its ability to combat oxidative stress and enhance the function of your auditory system and overall well-being.

  12. hello!,I love your writing very much! proportion we keep in touch extra approximately your article on AOL? I require an expert in this area to solve my problem. May be that’s you! Taking a look forward to look you.

  13. Thanks a bunch for sharing this with all folks you really know what you are speaking approximately! Bookmarked. Please also discuss with my website =). We could have a link exchange arrangement among us!

  14. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  15. After study a few of the blog posts on your website now, and I truly like your way of blogging. I bookmarked it to my bookmark website list and will be checking back soon. Pls check out my web site as well and let me know what you think.

  16. I’m really enjoying the design and layout of your site. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a designer to create your theme? Exceptional work!

  17. I do like the way you have presented this situation and it does present me personally some fodder for thought. However, because of what I have seen, I simply just hope as the feedback pile on that individuals keep on point and don’t get started on a soap box associated with some other news of the day. Still, thank you for this fantastic piece and although I do not necessarily agree with this in totality, I respect the standpoint.

  18. An impressive share, I just given this onto a colleague who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you become expertise, would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post!

  19. Thanks for the sensible critique. Me & my neighbor were just preparing to do a little research on this. We got a grab a book from our area library but I think I learned more from this post. I am very glad to see such fantastic information being shared freely out there.

  20. Hello very cool website!! Guy .. Beautiful .. Wonderful .. I will bookmark your web site and take the feeds also?KI’m satisfied to search out numerous helpful information right here in the post, we want work out extra strategies on this regard, thank you for sharing. . . . . .

  21. I like the helpful information you provide in your articles. I will bookmark your weblog and check again here regularly. I am quite certain I will learn lots of new stuff right here! Good luck for the next!

  22. Youre so cool! I dont suppose Ive read anything like this before. So good to search out any person with some unique ideas on this subject. realy thank you for beginning this up. this web site is something that’s wanted on the net, somebody with a little bit originality. helpful job for bringing one thing new to the web!

  23. After study a few of the blog posts on your website now, and I truly like your way of blogging. I bookmarked it to my bookmark website list and will be checking back soon. Pls check out my web site as well and let me know what you think.

  24. I saw that your artoftuning.net website may be missing out on approximately 1,000 visitors daily. Our AI powered traffic system is tailored to increase your site’s visibility: https://tinyurl.com/mrynyznw
    We’re offering a free trial that includes 4,000 targeted visitors to show the potential benefits. After the trial, we can supply up to 250,000 targeted visitors per month. This solution could greatly enhance your website’s reach and visitors.

  25. I’ve been browsing on-line greater than 3 hours today, but I by no means found any attention-grabbing article like yours. It is lovely worth enough for me. Personally, if all web owners and bloggers made excellent content as you probably did, the web will be a lot more useful than ever before. “It’s all right to have butterflies in your stomach. Just get them to fly in formation.” by Dr. Rob Gilbert.

  26. obviously like your web site but you have to test the spelling on quite a few of your posts. Several of them are rife with spelling issues and I find it very bothersome to inform the reality however I will surely come back again.

  27. I’ve been surfing online more than three hours today, but I by no means found any fascinating article like yours. It is pretty price enough for me. Personally, if all site owners and bloggers made excellent content material as you did, the internet will probably be much more helpful than ever before.

Leave a Reply

Your email address will not be published. Required fields are marked *