I've used for years this query to monitor the execution of a job:
SELECT j.name , ja.start_execution_date ,
Datediff(ss, ja.start_execution_date, Getdate()) AS 'HasRun(seconds)'
FROM msdb.dbo.sysjobactivity ja
INNER JOIN msdb.dbo.sysjobs J
ON j.job_id = ja.job_id
WHERE ja.session_id = (select MAX(sac.session_id)
from msdb.dbo.sysjobactivity sac
where sac.job_id = j.job_id)
AND ja.start_execution_date IS not NULL
and ja.stop_execution_date is null
This solution runs beautifully on a normal MSSQL server. But now I’m using RDS from Amazon, and the security is too limited. I’ve not been able to even execute
select * FROM msdb.dbo.sysjobactivity
with a login with the “most complete security profile available”.
I've tried other solutions posted on different blogs (like ....
SELECT name, current_execution_status, job_id
INTO #Jobs
FROM OPENROWSET(‘SQLNCLI’, ‘server=(local);trusted_connection=yes’,
‘set fmtonly off exec msdb.dbo.sp_help_job’)
...)
But none of those work on RDS, due to lack of permissions, either on msdb tables, sps, or other elements.
Do you have a way to retrieve on a table/variable the status of a job (i.e. if it is running or not)) on RDS for a mortal user?