Determine when currently executed job started

  • Hello!

      I am trying to determine whether currently executed job is taking longer than usual. I was wondering whether there is a way to determine start time of currently executed job. I can use sp_help_job or xp_sqlagent_enum_jobs but none of them reports this information.

      Any advice is greately appreciated,

    Igor

  • See if msdb..sysjobhistory table will give you want you need. 

  • Veronika,

    Unfortunately, sysjobhistory doesn't store data for currently executed jobs.

    Igor

  • My next thought is to look at the active processes to see if the job is still running.

    Or you can create some type of a job status table.  But in this case you will need to add steps to your job to records begin time and end time.  This is what I have done in the past. 

  • Veronika,

     

      I have already implemented solution based on info in sysprocesses table. I am trying to find when specific job started by matching program_name in sysprocesses and job_id (job_id is a part of program_name).

      I personally like this approach better since there is no need to add extra steps to the jobs.

     

    Thanks,

    Igor

  • There is an extended stored procedure that is called to return the currently running jobs. I think it's xp_enum_sqlagentjobs, not sure about that though and I don't have access to a server at the moment.

    From this procedure you should be able to get the currently executing jobs.

     

    --------------------
    Colt 45 - the original point and click interface

  • I think yiou are referring to xp_sqlagent_enum_jobs. Unfortunately, this stored procedure doesn't return start time of currently running jobs.

    Igor

  • Yes, but couldn't you link the information you've already got from sysprocesses to the information from the xp?

     

    --------------------
    Colt 45 - the original point and click interface

  • I am already linking but this is a little bit phuzzy because I am trying to locate process where program_name containg job_id of the job in question.

    I was hoping SQL server stores job start time of currently running job somewhere. 

  • I think it stores it in memory somewhere, unless it calculates it based on the job duration prior to writing to sysjobhistory.

    Job execution status has always been one of those sticky things to do outside of the GUI.

     

    --------------------
    Colt 45 - the original point and click interface

  • Thanks Phill!

    Igor

  • Gregory Larsen has some SQL which you could adapt in an article titled "Identifying Long Running SQL Server Agent Jobs" at

    http://www.databasejournal.com/features/mssql/article.php/3500276

    SQL = Scarcely Qualifies as a Language

  • I am using his logic but I am not sure whether it is 100% reliable (matching entry in sysprocesses with job_id).

    Thanks,

    Igor

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply