MSSQL Server Jobları Hakkında Bilgi Edinme
MsSQL Server 'da çalışan joblarla ilgili bilgi veren stored procedure'ler olduğunu biliyor muydunuz?
Bu procedureler sp_help_job ve xp_sqlagent_enum_jobs olarak iki tane.
sp_help_job : Bu proceure çalıştırılınca joblarla ilgili bilgileri görebiliyorsunuz ancak bu procedure'un çıktısını herhangi bir tabloya insert edemiyorsunuz çünkü engellenmiş:)
Kullanımı oldukça basit:
Şu anda çalışır durumdaki joblar için:
exec msdb.dbo.sp_help_job @execution_status = 1
Tüm joblarla ilgili görüntülemek için:
exec msdb.dbo.sp_help_job
Adını belirttiğiniz jobla ilgili bilgiler için:
exec msdb.dbo.sp_help_job @job_name = 'JobAdi'
Tüm job bilgileri için:
select j.* from #JobBilgileri j
Şu anda çalışan joblar için:
select s.name,j.* from #JobBilgileri j
inner join msdb.dbo.sysjobs s on s.job_id = j.JobID
where j.running = 1
Şu anda çalışmayan joblar için:
select s.name,j.* from #JobBilgileri j
inner join msdb.dbo.sysjobs s on s.job_id = j.JobID
where j.running = 0
Bu procedureler sp_help_job ve xp_sqlagent_enum_jobs olarak iki tane.
sp_help_job : Bu proceure çalıştırılınca joblarla ilgili bilgileri görebiliyorsunuz ancak bu procedure'un çıktısını herhangi bir tabloya insert edemiyorsunuz çünkü engellenmiş:)
Kullanımı oldukça basit:
exec msdb.dbo.sp_help_job @execution_status = 1
exec msdb.dbo.sp_help_job
exec msdb.dbo.sp_help_job @job_name = 'JobAdi'
xp_sqlagent_enum_jobs :Bu proceure çalıştırılınca joblarla ilgili bilgileri görebiliyorsunuz ve dönen result seti de bir tabloya insert edebiliyorsunuz.
CREATE TABLE #JobBilgileri
(
JobID UNIQUEIDENTIFIER NOT NULL
, LastRunDAte INT not null
, LastRunTime INT not null
, NextRunDate INT not null
, NextRunTime INT not null
, NextRunScheduleID INT not null
, RequestedToRun INT not null
, RequestSource INT not null
, RequestSourceID varchar(100)
, Running INT not null
, CurrentStep INT not null
, CurrentRetryAttempt INT not null
, JobState INT not null
)
insert into #JobBilgileri
exec master.dbo.xp_sqlagent_enum_jobs 1, JobSahibininAdi
select j.* from #JobBilgileri j
select s.name,j.* from #JobBilgileri j
inner join msdb.dbo.sysjobs s on s.job_id = j.JobID
where j.running = 1
select s.name,j.* from #JobBilgileri j
inner join msdb.dbo.sysjobs s on s.job_id = j.JobID
where j.running = 0
Comment Form under post in blogger/blogspot