I am using sqlwatch to monitor some of my servers and it has a job that deletes in batch from a table called dbo.sqlwatch_logger_snapshot_header
I had lots of problems of locking and blocking as this table is used by different processes, then I disabled all other jobs with the exception of the one that deals with this table.
I used the following script to disable all other sqlwatch jobs:
use distribution
set nocount on
set transaction isolation level read uncommitted
declare @Job_id uniqueidentifier
declare @job_name varchar(300)
declare @category_name varchar(300)
declare @body varchar(max)
declare @flag tinyint
declare @enabled bit = 0; --0 - disable 1-enable
declare @subject varchar(300) = case when @enabled = 0 then 'Disabling sqlwatch jobs on' + @@servername else 'Enabling sqlwatch jobs on' + @@servername end;
declare @job_enabled bit;
set @flag = 0
set @body = 'The following jobs are going to be ' +
case when @enabled = 0 then 'Disabled' else 'Enabled' end
+ ' : '+char(10)+Char(13)
IF OBJECT_ID('tempdb.[dbo].[#LogReaderAgents]') IS NOT NULL
DROP TABLE [dbo].[#LogReaderAgents]
CREATE TABLE [dbo].[#LogReaderAgents] (
[job_id] UNIQUEIDENTIFIER NOT NULL,
[job_name] SYSNAME NOT NULL,
[category_name] SYSNAME NOT NULL,
[enabled] TINYINT NOT NULL)
INSERT INTO [dbo].[#LogReaderAgents] ([job_id],[job_name],[category_name],[enabled])
select job_id, job_name = sj.name, category_name=sc.name, sj.enabled
from msdb.dbo.sysjobs sj
inner join msdb.dbo.syscategories sc
on sj.category_id = sc.category_id
where 1=1
and sj.name like 'SQLWATCH%'
-- and sc.category_id in (10,13)
and sj.name not in ('SQLWATCH-INTERNAL-RETENTION')
-- exec sp_gettabledef 'dbo.#LogReaderAgents'
-- exec sp_GetInsertList 'TEMPDB','DBO.#LogReaderAgents'
DECLARE c1 CURSOR FOR
SELECT Job_id,job_name, category_name, [enabled]
FROM #LogReaderAgents
OPEN c1
FETCH NEXT FROM c1
INTO @Job_id,@job_name,@category_name,@job_enabled
WHILE @@FETCH_STATUS = 0
begin
if (select top (1) stop_execution_date from msdb.dbo.sysjobactivity ja
where Job_ID = @Job_id
and
ja.start_execution_date IS NOT NULL
order by Start_execution_date desc) is not NULL
begin
set @flag = 1
Print @job_name +' is ' + case when @job_enabled=1 then 'Enabled' else 'disabled' end
exec msdb..sp_update_job @job_id = @job_id, @enabled = @enabled
set @Body = @Body + char(10)+char(13) + @job_name + ' -- ' + @category_name +' is ' + case when @job_enabled=1 then 'Enabled' else 'disabled' end
end
FETCH NEXT FROM c1
INTO @Job_id,@job_name,@category_name,@job_enabled
end
CLOSE c1
DEALLOCATE c1
however, after that the job is still running, but I dont see any changes in the number of the records that are in this table.
here is the job executing a procedure and doing a delete in batch:
progress has been slow but steady, there were 37.2 million rows
now there are 36.9 millions
so basically it is working, so all good.
Now my question:
Suppose I had to stop this job for any reason,
it is a batch delete, if I had to stop this job now, how many rows are affected, how costly would it be to rollback what has not been committed yet?