Job-history dolu full ise kontrol sorgusu ve delete sorgusu
Definition Description
-- hangi jobda nekadar history line var
SELECT b.name, a.job_id, a.run_date, COUNT(*) NumberofRun FROM sysjobhistory a, sysjobs b WHERE a.job_id = b.job_id GROUP by a.job_id, b.name, run_date ORDER BY NumberofRun DESC
-- sadece cdc history silmek için yazilan sorgu https://www.sqlservercentral.com/forums/topic/cdc-agent-job-fills-up-the-agent-jobs-history
IF OBJECT_ID('tempdb.dbo.#sp_Get_sqlagent_properties') IS NOT NULL DROP TABLE #sp_Get_sqlagent_properties
INSERT INTO #sp_Get_sqlagent_properties EXEC msdb.dbo.sp_Get_sqlagent_properties
;with cdc_job_history ( job_name ,job_id ,job_history_row_num ,instance_id ,jobhistory_max_rows_per_job ) AS (SELECT j.name ,j.job_id ,ROW_NUMBER() OVER (PARTITION BY h.job_id ORDER BY h.instance_id DESC) AS job_history_row_num ,h.instance_id ,a.jobhistory_max_rows_per_job FROM msdb.dbo.sysjobhistory h INNER JOIN msdb.dbo.sysjobs j ON j.job_id = h.job_id AND j.name like 'cdc%' CROSS APPLY (SELECT jobhistory_max_rows_per_job FROM #sp_Get_sqlagent_properties) a (jobhistory_max_rows_per_job) ) DELETE h FROM msdb.dbo.sysjobhistory h INNER JOIN cdc_job_history c ON c.instance_id = h.instance_id WHERE c.job_history_row_num > c.jobhistory_max_rows_per_job
--SELECT * -- FROM msdb.dbo.sysjobhistory h -- INNER JOIN cdc_job_history c -- ON c.instance_id = h.instance_id -- WHERE c.job_history_row_num > c.jobhistory_max_rows_per_job