Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 


Find the SID for a dbms_job dbms_scheduler job

Oracle Database Tips by Donald BurlesonOctober 30, 2015

Question:  I need a dictionary query to find the SID for a dbms_job dbms_scheduler job.  I'm trying to use the sys_context function for a task., and it works great when I run it via SQL*Plus.  However, when I schedule it to run via a dbms_job, there appears to be no session ID. 

I also see the same issue when I attempt to kill a job that is submitted via dbms_job because there is no entry in the v$session view and it has a SID equal to zero.  This query works fine if I create a dbms_job and run that job manually from SQL*Plus, but it fails when I execute it independently when sheduled via dbms_job.

select
   sid
from
   v$session
where
   audsid = sys_context( 'userenv', 'sessionid');

How does Oracle control the session ID for a job that is executed independently from a connected session, such as a dbms_job or dbms_scheduler task?

Answer:  This is similar to the issues on a UNIX crontab when a job fails because it is not connected to an active user session!  In your case, the dbms_job scheduled task is not connected to any session because is run independently from your own online session (as per v$session).

Oracle scheduled job are submitted via a job queue process using dbms_job.submit and a "child" process will be associated with the scheduled job.  For long running jobs you can query the v$session_longops view and get the system ID (SID).

select
   sid,
   message
from
   v$session_longops
order by
   start_time;

This SID can then be used in a "alter system kill session" command.
You can also force a row into v$session by invoking the procedure dbms_application_info.set_client_info:

dbms_application_info.set_client_info(client_info => 'submitted via dbms_scheduler');


 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.

 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster