@@ -1259,49 +1259,30 @@ AND ca.utc_timestamp < @end_date';
12591259 SYSDATETIME ()
12601260 );
12611261
1262- /* Clean up each log table */
1262+ /*
1263+ Clean up each log table in batches of 10,000 rows. A single
1264+ unbatched DELETE against a long-installed instance that
1265+ hasn't been cleaned up will take a large transaction-log
1266+ hit and potentially escalate to table-level locking. The
1267+ WHILE loop keeps each transaction small and lets other
1268+ writers progress between batches. @@ROWCOUNT < 10000 is
1269+ the loop exit condition once the trailing batch finishes.
1270+ */
12631271 SET @dsql = N'
1264- DELETE FROM ' + @log_table_significant_waits + '
1265- WHERE collection_time < @cleanup_date;
1266-
1267- DELETE FROM ' + @log_table_waits_by_count + '
1268- WHERE collection_time < @cleanup_date;
1269-
1270- DELETE FROM ' + @log_table_waits_by_duration + '
1271- WHERE collection_time < @cleanup_date;
1272-
1273- DELETE FROM ' + @log_table_io_issues + '
1274- WHERE collection_time < @cleanup_date;
1275-
1276- DELETE FROM ' + @log_table_cpu_tasks + '
1277- WHERE collection_time < @cleanup_date;
1278-
1279- DELETE FROM ' + @log_table_memory_conditions + '
1280- WHERE collection_time < @cleanup_date;
1281-
1282- DELETE FROM ' + @log_table_memory_broker + '
1283- WHERE collection_time < @cleanup_date;
1284-
1285- DELETE FROM ' + @log_table_memory_node_oom + '
1286- WHERE collection_time < @cleanup_date;
1287-
1288- DELETE FROM ' + @log_table_system_health + '
1289- WHERE collection_time < @cleanup_date;
1290-
1291- DELETE FROM ' + @log_table_scheduler_issues + '
1292- WHERE collection_time < @cleanup_date;
1293-
1294- DELETE FROM ' + @log_table_severe_errors + '
1295- WHERE collection_time < @cleanup_date;
1296-
1297- DELETE FROM ' + @log_table_pending_tasks + '
1298- WHERE collection_time < @cleanup_date;
1299-
1300- DELETE FROM ' + @log_table_blocking + '
1301- WHERE collection_time < @cleanup_date;
1302-
1303- DELETE FROM ' + @log_table_deadlocks + '
1304- WHERE collection_time < @cleanup_date;
1272+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_significant_waits + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1273+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_waits_by_count + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1274+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_waits_by_duration + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1275+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_io_issues + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1276+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_cpu_tasks + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1277+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_memory_conditions + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1278+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_memory_broker + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1279+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_memory_node_oom + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1280+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_system_health + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1281+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_scheduler_issues + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1282+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_severe_errors + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1283+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_pending_tasks + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1284+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_blocking + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
1285+ WHILE 1 = 1 BEGIN DELETE TOP (10000) FROM ' + @log_table_deadlocks + ' WHERE collection_time < @cleanup_date; IF @@ROWCOUNT < 10000 BREAK; END;
13051286 ' ;
13061287
13071288 IF @debug = 1
0 commit comments