Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 556 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 468 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
How do i find out which query is hanging the stored procedure?

Hi All,
I have a stored procedure which is running forever. The particular stored procedure reads a file and performs validation and inserts into some transaction table.
There are many stored procedures that are called within the main procedure. There might be locks or blocks or some query is taking long time to execute
How do i find out which query in which procedure is taking long time to execute? But sometimes the same procedures completes successfully within few seconds inserting
all the records (10000 recs).
Thanks
Gautam S
Answers
-
580988 wrote:Hi All, I have a stored procedure which is running forever. The particular stored procedure reads a file and performs validation and inserts into some transaction table. There are many stored procedures that are called within the main procedure. There might be locks or blocks or some query is taking long time to execute How do i find out which query in which procedure is taking long time to execute? But sometimes the same procedures completes successfully within few seconds inserting all the records (10000 recs).ThanksGautam S
Consider to issue SQL below just prior to starting the rogue procedure.
ALTER SESSION SET SQL_TRACE=TRUE; -- ensure the USER has necessary privilege to successfully run this SQL statement
process resultant trace file using TKPROF
-
I just ran the main procedure now and it ran successfully within few seconds. I don't know why it was not running earlier 1 hour ago. Can someone throw some light on this?
Thanks
Gautam
-
580988 wrote:I just ran the main procedure now and it ran successfully within few seconds. I don't know why it was not running earlier 1 hour ago. Can someone throw some light on this?ThanksGautam
Something changed, but we don't know what you have.
Does any of the SQL in your mystery procedure use bind variables?
-
No, none of the SQL use bind variables. My procedure calls the innermost procedure which is a PRAGMA AUTONOMOUS procedure.
FYI : The innermost procedure has a FOR UPDATE in a select clause. I have issued proper COMMIT/ROLLBACK also in that procedure. Does it have something to do with that? Also, the total record count i am processing is 10000.
Thanks
Gautam
-
@John Thorton
However the records are processed successfully and inserted into relevant tables. Only the session keeps hanging in SQL Developer.
Let me know if you need anything else. If the session keeps hanging probably the application would also keep hanging in Production.
Can you someone kindly help on this.
Thanks
Gautam
-
Hi all,
It's solved. The hanging was due to the excessive dbms_output messages being populated for each of the 10000 records.
-
580988 wrote:No, none of the SQL use bind variables.
Are you using dynamic SQL? Because unless you are, all your SQL will definitely be using bind variables. PL/SQL sorts that out automatically.
-
The most simple thing is to use a log table and log there when the code gets to some place using a store procedure with pragma autonomous_transaction.
Or, you may see what shows in the sys.gv_$open_cursor and sys.gv_$sql for that session of yours, like below:
select sq.*
from sys.gv_$open_cursor oc
join sys.gv_$sql sq on oc.sql_id=sq.sql_id and oc.inst_id=sq.inst_id
where oc.sid=&sid and oc.inst_id=&inst_id
and sq.users_executing>0
;
If it's quite difficult to know which your session is, you may mark that session using the facilities of package dbms_application_info.
-
If you suspect there may be some session blocking:
Select * from sys.gv_$session_blockers
;
And see what you get.