[{"data":1,"prerenderedAt":152},["ShallowReactive",2],{"blog:2007:sql-server-replication-blocking-on-cleanup-job":3,"blogMore-Technology":138,"comments-sql-server-replication-blocking-on-cleanup-job":151},{"id":4,"title":5,"body":6,"category":120,"commentCount":121,"date":122,"description":12,"excerpt":123,"extension":124,"filenames":125,"hidden":126,"image":125,"meta":127,"minutes":118,"navigation":128,"path":129,"seo":130,"showCategory":125,"stem":131,"tags":132,"updated":125,"url":135,"wordCount":136,"__hash__":137},"content\u002Fblog\u002F2007\u002Fsql-server-replication-blocking-on-cleanup-job.md","SQL Server replication blocking on cleanup job",{"type":7,"value":8,"toc":117},"minimark",[9,13,16,19,68,84,91,94,105,108,113],[10,11,12],"p",{},"For some time my primary workplace has been having a problem with SQL Server replication delaying for several minutes at a time which is surprising given the 12GB of RAM and quad processor hardware behind it.",[10,14,15],{},"Activity Monitor showed a number of processes on the distribution database used for SQL Server’s replication were blocked by another process which was in turn blocked by a SQL Agent TSQL Job executing on the distribution database.",[10,17,18],{},"This process’s job GUID that did not match any of our jobs and appeared to be an internal job that regularly executes:",[20,21,26],"pre",{"className":22,"code":23,"language":24,"meta":25,"style":25},"language-sql shiki shiki-themes everforest-light dracula","EXEC dbo.sp_MSdistribution_cleanup @min_distretention = 0, @max_disretention = 32760\n","sql","",[27,28,29],"code",{"__ignoreMap":25},[30,31,34,38,42,46,49,52,56,60,63,65],"span",{"class":32,"line":33},"line",1,[30,35,37],{"class":36},"smiwp","EXEC",[30,39,41],{"class":40},"s2G2r"," dbo",[30,43,45],{"class":44},"s6Vpi",".",[30,47,48],{"class":40},"sp_MSdistribution_cleanup",[30,50,51],{"class":44}," @min_distretention ",[30,53,55],{"class":54},"s9HRq","=",[30,57,59],{"class":58},"s3Ipq"," 0",[30,61,62],{"class":44},", @max_disretention ",[30,64,55],{"class":54},[30,66,67],{"class":58}," 32760\n",[10,69,70,71,74,75,79,80,83],{},"This would sit on the ",[27,72,73],{},"PAGEIOLATCH_SH"," status for over 10 minutes at a time most most likely because it was operating on an ",[76,77,78],"em",{},"MSrepl_commands"," table with 3.4 million records and a ",[27,81,82],{},"MSrepl_transactions"," table of 600k records.",[10,85,86,87,90],{},"The default ",[27,88,89],{},"max_disretention"," is 72 (hours) and specifies how long to hold the replication history for. This means if a subscriber is down for longer than this period it will lose transactions.",[10,92,93],{},"How exactly this system obtained the value 32760 (3.7 years) is a bit of a mystery and I’m assuming that it actually uses a lower value as there have been more than 3.4 million updates in that period.",[10,95,96,97,100,101,104],{},"Setting this value to 84 hours (3.5 days) in ",[76,98,99],{},"Management Studio’s Replication > Distributor Properties > Transaction Retention"," soon dropped those large MS tables down to 406 records and 300 respectively and resulted in ",[27,102,103],{},"sp\\_MSdistribution\\_cleanup"," executing in a couple of seconds.",[10,106,107],{},"It’s a very specific scenario but perhaps this blog post will be of use to somebody else!",[10,109,110],{},[76,111,112],{},"[)amien",[114,115,116],"style",{},"html pre.shiki code .smiwp, html code.shiki .smiwp{--shiki-default:#F85552;--shiki-dark:#FF79C6}html pre.shiki code .s2G2r, html code.shiki .s2G2r{--shiki-default:#5C6A72;--shiki-dark:#BD93F9}html pre.shiki code .s6Vpi, html code.shiki .s6Vpi{--shiki-default:#5C6A72;--shiki-dark:#F8F8F2}html pre.shiki code .s9HRq, html code.shiki .s9HRq{--shiki-default:#F57D26;--shiki-dark:#FF79C6}html pre.shiki code .s3Ipq, html code.shiki .s3Ipq{--shiki-default:#DF69BA;--shiki-dark:#BD93F9}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":25,"searchDepth":118,"depth":118,"links":119},2,[],"Technology",0,"2007-11-09T16:55:47+00:00","[object Object]","md",null,false,{},true,"\u002Fblog\u002F2007\u002Fsql-server-replication-blocking-on-cleanup-job",{"title":5,"description":12},"blog\u002F2007\u002Fsql-server-replication-blocking-on-cleanup-job",[133,134],"Microsoft","SQL Server","\u002Fblog\u002F2007\u002Fsql-server-replication-blocking-on-cleanup-job\u002F",336,"gbzEkuS9df4U1bs9qKF6HpCPKT1eluKX6M0JAYXXAz4",[139,143,147],{"title":140,"date":141,"url":142},"VTX5000: Part 4 - Communications","2026-05-06T10:19:24.727Z","\u002Fblog\u002F2026\u002Fvtx5000-part-4-comms-routines\u002F",{"title":144,"date":145,"url":146},"VTX5000: Part 3 - Software ROM","2026-04-15T23:00:00.000Z","\u002Fblog\u002F2026\u002Fvtx5000-part-3-software-rom\u002F",{"title":148,"date":149,"url":150},"VTX5000: Part 2 - Hardware","2026-03-30T23:00:00.000Z","\u002Fblog\u002F2026\u002Fprism-vtx5000-part-2\u002F",[],1780900518032]