Home
%3CLINGO-SUB%20id%3D%22lingo-sub-909429%22%20slang%3D%22en-US%22%3EMSDTC%20Best%20Practices%20with%20an%20Availability%20Group%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-909429%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20this%20article%20we%20are%20going%20to%20look%20at%20some%20guidelines%20and%20MSDTC%20best%20practices%20with%20an%20Availability%20Group.%26nbsp%3B%20Please%20note%20that%20some%20of%20these%20recommendations%20change%20if%20you%20are%20deploying%20a%20Failover%20Cluster%20Instance.%26nbsp%3B%20If%20you%20are%20using%20the%20MSDTC%20(BizTalk%2C%20Linked%20Servers%2C%20etc.)%20and%20hosting%20the%20databases%20in%20an%20Availability%20Group%2C%20there%20are%20several%20things%20we%20need%20to%20take%20into%20consideration.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1845260119%22%20id%3D%22toc-hId-1845260119%22%20id%3D%22toc-hId-1845260119%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--706896842%22%20id%3D%22toc-hId--706896842%22%20id%3D%22toc-hId--706896842%22%3EPrecedence%3C%2FH2%3E%0A%3CP%3EWhen%20an%20instance%20of%20SQL%20Server%20starts%20it%20enlists%20with%20a%20transaction%20coordinator%20and%20Resource%20Manager.%26nbsp%3B%20Think%20of%20the%20coordinator%20as%20the%20Windows%20Service%20and%20the%20Manager%20as%20the%20handler%20between%20the%20service%20and%20SQL%20Server.%26nbsp%3B%20The%20SQL%20Server%20instance%20has%20always%20been%20the%20Resource%20Manager%20until%20SQL%202016%20when%20support%20for%20the%20MSDTC%20in%20an%20AG%20became%20available.%26nbsp%3B%20In%20a%20SQL%202016%20AG%20where%20per%20database%20MSDTC%20has%20been%20enabled%2C%20each%20database%20becomes%20its%20own%20Resource%20Manager.%26nbsp%3B%20For%20more%20information%20on%20versions%20and%20supportability%20for%20MSDTC%20please%20refer%20to%20the%20%E2%80%9C%3CSTRONG%3EAvailability%20Group%3C%2FSTRONG%3E%E2%80%9D%20and%20%E2%80%9C%3CSTRONG%3ESupport%20Matrix%3C%2FSTRONG%3E%E2%80%9D%20sections%20of%20this%20article%20on%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FPremier-Field-Engineering%2FMSDTC-Supported-Configurations%2Fba-p%2F371456%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EMSDTC%20Supported%20Configurations%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20order%20of%20precedence%20defines%20which%20MSDTC%20Coordinator%20SQL%20Server%20will%20enlist%20with%20at%20startup.%26nbsp%3B%20Although%20the%20precedence%20order%20has%20been%20discussed%20in%20the%20past%2C%20what%20we%20will%20see%20is%20that%20there%20really%20is%20no%20order.%26nbsp%3B%20The%20first%20place%20SQL%20Server%20looks%20is%20to%20see%20what%20the%20Default%20Clustered%20Instance%20is%20configured%20for%20within%20the%20Windows%20Cluster.%26nbsp%3B%20We%20can%20find%20this%20by%20opening%20Component%20Services%20or%20%3CSTRONG%3Ecomexp.msc%2C%20%3C%2FSTRONG%3Eright%20clicking%20My%20Computer%2C%20and%20selecting%20Properties.%26nbsp%3B%20Here%20is%20what%20that%20looks%20like%20prior%20to%20Windows%20Server%202016.%26nbsp%3B%20In%20Windows%202016%2B%20you%20would%20not%20see%20the%20check%20box%20for%20%E2%80%9CUse%20Local%20Coordinator%E2%80%9D.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20846px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F137219i85CD3F11015F0159%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Clustered%20Default%20Coordinator.png%22%20title%3D%22Clustered%20Default%20Coordinator.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20see%20that%20the%20Default%20Coordinator%20will%20use%20the%20local%20MSDTC%20by%20default%20(A%20default%20with%20a%20default!).%20In%20Windows%202016%2B%20you%20cannot%20change%20this%20default%20and%20would%20need%20to%20disable%20the%20service.%20I%20recommend%20disabling%20the%20service%20no%20matter%20what%20version%20of%20Windows%20you%20are%20using.%20Note%20that%20once%20you%20disable%20the%20service%20for%20the%20local%20MSDTC%2C%20you%20need%20have%20a%20clustered%20MSDTC%20defined%20or%20you%20will%20not%20have%20anything%20at%20all.%20Refer%20to%20the%20%3CSTRONG%3EManually%20Map%20MSDTC%3C%2FSTRONG%3E%20section%20later%20in%20this%20article%20for%20more%20information.%20You%20might%20be%20tempted%20to%20leave%20it%20on%20thinking%20it%20could%20serve%20as%20a%20backup%2C%20but%20if%20you%20do%20not%20want%20to%20use%20the%20local%20MSDTC%20you%20%3CSTRONG%3EMUST%3C%2FSTRONG%3E%20disable%20this.%20Also%2C%20the%20SQL%20instance%20only%20enlists%20with%20an%20MSDTC%20Coordinator%20once%20at%20startup%20and%20never%20tries%20again.%20If%20you%20enable%20%3CSTRONG%3EWITH%20DTC_SUPPORT%20%3D%20PER_DB%3C%2FSTRONG%3E%20in%20an%20AG%2C%20then%20this%20occurs%20for%20each%20database%20when%20it%20starts.%20If%20we%20want%20to%20use%20a%20clustered%20MSDTC%20then%20we%20will%20need%20to%20remove%20that%20check%20mark%20and%20select%20our%20desired%20default.%20Here%20is%20where%20you%20can%20find%20and%20disable%20the%20service%20using%20%3CSTRONG%3Eservices.msc%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F137220i7BD9B2AF2B2AC701%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Local%20DTC%20Service.png%22%20title%3D%22Local%20DTC%20Service.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELooking%20back%20at%20Component%20Services%20you%20will%20see%20we%20have%20a%20drop-down%20box%20where%20we%20can%20select%20our%20Default%20Clustered%20Instance.%26nbsp%3B%20Whatever%20you%20select%20here%20is%20what%20SQL%20will%20use%20for%20its%20MSDTC%20Coordinator%20and%20completes%20our%20%E2%80%9Corder%20of%20precedence%E2%80%9D.%26nbsp%3B%20You%20may%20have%20heard%20about%20an%20order%20that%20describes%20a%20DTC%20in%20its%20own%20role%20or%20DTCs%20within%20SQL%20roles.%20I%20will%20describe%20those%20scenarios%20in%20the%20Quantity%20section%20but%20know%20that%20they%20must%20be%20manually%20mapped%20per%20instance%20to%20override%20using%20the%20default%2C%20so%20this%20is%20where%20our%20order%20ends.%26nbsp%3B%20There%20are%20no%20automatic%20choices%20for%20SQL%20beyond%20the%20Default%20Clustered%20Instance%20since%20it%20must%20be%20defined.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1035913493%22%20id%3D%22toc-hId-1035913493%22%20id%3D%22toc-hId-1035913493%22%3EAvailability%3C%2FH2%3E%0A%3CP%3EA%20paramount%20concept%20to%20understand%20is%20how%20to%20make%20the%20DTC%20highly%20available.%26nbsp%3B%20We%20can%20see%20from%20the%20precedence%20order%20that%20SQL%20Server%20will%20use%20the%20local%20DTC%20out%20of%20the%20box.%26nbsp%3B%20This%20makes%20it%20appear%20that%20everything%20is%20working%2C%20and%20it%20is%2C%20but%20it%20is%20not%20exactly%20highly%20available.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20see%20a%20lot%20of%20customers%20leave%20it%20configured%20this%20way%20because%20they%20either%20don%E2%80%99t%20know%20the%20ramifications%20or%20do%20not%20realize%20they%20are%20using%20the%20MSDTC%20(Linked%20Servers).%20Since%20it%20simply%20works%20out%20of%20the%20box%2C%20things%20get%20left%20this%20way%20until%20they%20end%20up%20with%20a%20suspect%20database%20and%20error%20messages%20that%20look%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%22SQL%20Server%20detected%20a%20DTC%2FKTM%20in-doubt%20transaction%20with%20UOW%26nbsp%3B%20%7B598B7EDD-F7A1-9DC1-8D3E-303A4C93AAB4%7D.Please%20resolve%20it%20following%20the%20guideline%20for%20Troubleshooting%20DTC%20Transactions.%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%22An%20error%20occurred%20while%20recovering%20database%20'MyCriticalDB'.%20Unable%20to%20connect%20to%20Microsoft%20Distributed%20Transaction%20Coordinator%20(MS%20DTC)%20to%20check%20the%20completion%20status%20of%20transaction%20(5%3A861236355).%20Fix%20MS%20DTC%2C%20and%20run%20recovery%20again.%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%22Database%20'MyCriticalDB'%20cannot%20be%20opened.%20It%20has%20been%20marked%20SUSPECT%20by%20recovery.%20See%20the%20SQL%20Server%20errorlog%20for%20more%20information.%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20look%20at%20an%20example%20of%20how%20this%20could%20happen.%26nbsp%3B%20Assume%20we%20have%20a%202%20node%20AG%20using%20local%20DTCs.%26nbsp%3B%20Here%20is%20what%20that%20would%20look%20like.%26nbsp%3B%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorclipboard_image_2%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20521px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F137221i59F2D9915A588921%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22FCI%20Local%20DTC.png%22%20title%3D%22FCI%20Local%20DTC.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20Node1%20fails%20and%20the%20local%20MSDTC%20on%20that%20node%20has%20an%20in-flight%20distributed%20transaction%2C%20the%20local%20MSDTC%20on%20Node2%20kicks%20in%20after%20the%20failover.%20The%20local%20MSDTC%20on%20Node2%20tries%20to%20contact%20the%20local%20MSDTC%20on%20Node1%20and%20retrieve%20the%20status%20of%20any%20in-doubt%20transactions.%20This%20process%20is%20attempted%203%20times.%20If%20the%20old%20primary%20(Node1)%20still%20cannot%20be%20contacted%2C%20SQL%20takes%20its%20direction%20from%20the%20In-doubt%20Transaction%20Configuration%20or%20%22in-doubt%20xact%20resolution%22%20in%20sp_configure.%26nbsp%3B%20SPOILER%20ALERT%20%E2%80%93%20This%20is%20not%20configured%20by%20default%20which%20means%20your%20database%20will%20go%20into%20Suspect%20mode%E2%80%A6Yikes!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIs%20there%20some%20availability%20in%20this%20configuration%3F%20%3CSTRONG%3EYes%3C%2FSTRONG%3E%2C%20since%20the%20new%20primary%20node%20attempts%20to%20discover%20the%20transaction%20status%20from%20the%20failed%20primary%20node.%26nbsp%3B%20Is%20it%20highly%20available%3F%20%3CSTRONG%3ENo%2C%20and%20the%20prior%20error%20messages%20demonstrate%20that%3C%2FSTRONG%3E.%26nbsp%3B%20If%20the%20old%20primary%20does%20not%20come%20back%20online%20and%20fast%20enough%20prior%20to%20the%203%20attempts%20from%20the%20new%20primary%2C%20SQL%20must%20decide%20whether%20to%20commit%20or%20roll%20back.%26nbsp%3B%20The%20problem%20is%20that%20the%20status%20of%20in-flight%20distributed%20transactions%20is%20stored%20locally%20on%20the%20node.%26nbsp%3B%20If%20the%20log%20was%20on%20shared%20storage%20then%20the%20Resource%20Manager%20would%20know%20the%20outcome.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20using%20the%20local%20DTC%20is%20not%20highly%20available%2C%20the%20next%20natural%20question%20is%2C%20%E2%80%9CHow%20do%20we%20remedy%20that%3F%E2%80%9D%26nbsp%3B%20The%20answer%20lies%20in%20the%20%3CSTRONG%3Elog%20for%20the%20MSDTC%20service%3C%2FSTRONG%3E.%26nbsp%3B%20Just%20like%20SQL%20Server%2C%20the%20MSDTC%20has%20a%20log%20file%20it%20uses%20to%20track%20the%20status%20of%20distributed%20transactions.%26nbsp%3B%20If%20we%20can%20make%20that%20log%20file%20highly%20available%2C%20then%20we%20make%20the%20MSDTC%20highly%20available.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20several%20methods%20to%20make%20the%20MSDTC%20log%20highly%20available%20by%20making%20the%20storage%20where%20it%20is%20located%20highly%20available.%20This%20ensures%20that%20the%20MSDTC%20log%20and%20thus%20the%20outcome%20of%20distributed%20in-flight%20transactions%20is%20immediately%20available%20post%20failover.%20You%20can%20accomplish%20this%20using%20technologies%20like%20iSCSI%20(assuming%20the%20host%20has%20redundancy%20for%20the%20storage)%20or%20Storage%20Spaces%20Direct%20(S2D)%20and%20we%20have%20some%20partners%20with%20excellent%20solutions%20as%20well.%20If%20you%20want%20to%20see%20how%20to%20do%20this%20using%20S2D%20you%20can%20check%20out%20this%20post%20on%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FPremier-Field-Engineering%2FConfigure-SQL-Server-Failover-Cluster-Instance-on-Azure-Virtual%2Fba-p%2F371464%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EConfigure%20SQL%20Server%20Failover%20Cluster%20Instance%20on%20Azure%20Virtual%20Machines%20with%20MSDTC%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20post%20is%20geared%20toward%20FCIs%2C%20but%20the%20MSDTC%20part%20is%20identical%20for%20AGs.%26nbsp%3B%20The%20one%20thing%20you%20will%20note%20about%20having%20shared%20storage%20to%20make%20the%20MSDTC%20highly%20available%20is%20that%20it%20is%20not%20congruent%20with%20the%20architecture%20of%20AGs.%26nbsp%3B%20AGs%20do%20not%20have%20shared%20storage%20by%20design%2C%20so%20it%20seems%20counter%20intuitive%20to%20add%20shared%20storage%20to%20the%20design%2C%20but%20it%20is%20required%20only%20for%20the%20MSDTC%20to%20make%20it%20highly%20available%20like%20the%20AG.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1516243468%22%20id%3D%22toc-hId--1516243468%22%20id%3D%22toc-hId--1516243468%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId-226566867%22%20id%3D%22toc-hId-226566867%22%20id%3D%22toc-hId-226566867%22%3EQuantity%3C%2FH2%3E%0A%3CP%3EThe%20last%20thing%20we%20want%20to%20consider%20is%20scaling%20out.%26nbsp%3B%20This%20is%20completely%20dependent%20on%20your%20MSDTC%20workload%20and%20may%20not%20be%20necessary.%26nbsp%3B%20If%20you%20have%20multiple%20instances%20of%20SQL%20Server%20running%20in%20your%20cluster%20and%20you%20create%20one%20clustered%20MSDTC%20in%20its%20own%20resource%20group%2C%20every%20instance%20uses%20that%20same%20MSDTC.%20If%20you%20have%20a%20lot%20of%20distributed%20transactions%20this%20can%20become%20a%20bottleneck.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20Failover%20Cluster%20Instances%20we%20can%20create%20an%20MSDTC%20per%20instance%20because%20each%20one%20is%20its%20own%20instance%20of%20SQL%20Server.%26nbsp%3B%20However%2C%20if%20you%20have%20multiple%20AGs%20they%20are%20most%20likely%20in%20the%20same%20instance%20of%20SQL%20Server%20and%20every%20AG%20will%20use%20the%20same%20MSDTC.%26nbsp%3B%20In%20this%20situation%2C%20you%20would%20need%20to%20spread%20the%20AGs%20across%20multiple%20instances.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20other%20issue%20that%20can%20get%20introduced%20with%20a%20single%20clustered%20MSDTC%20in%20its%20own%20role%2C%20is%20that%20you%20cannot%20guarantee%20it%20will%20run%20on%20the%20same%20node%20as%20your%20SQL%20instance.%20You%20could%20easily%20have%20an%20instance%20running%20on%20Node2%20and%20using%20an%20MSDTC%20running%20on%20Node1.%20This%20can%20introduce%20network%20latency.%26nbsp%3B%20The%20best%20practice%20here%20would%20be%20to%20put%20the%20MSDTC%20for%20the%20instance%20running%20your%20AG%20in%20the%20same%20Windows%20Cluster%20Role.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20decide%20to%20have%20multiple%20MSDTCs%20for%20multiple%20instances%20and%20put%20them%20in%20their%20respective%20roles%2C%20you%20will%20need%20to%20manually%20map%20them%20or%20they%20will%20continue%20to%20use%20the%20Default%20Clustered%20Instance.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1969377202%22%20id%3D%22toc-hId-1969377202%22%20id%3D%22toc-hId-1969377202%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--582779759%22%20id%3D%22toc-hId--582779759%22%20id%3D%22toc-hId--582779759%22%3EManually%20Map%20MSDTC%3C%2FH2%3E%0A%3CP%3ETo%20manually%20map%20MSDTC%20to%20an%20instance%20of%20SQL%20Server%20we%20will%20need%20to%20use%20the%20%3CSTRONG%3Emsdtc.exe%3C%2FSTRONG%3E%20command%20line%20tool.%26nbsp%3B%20To%20start%20off%20we%20simply%20want%20to%20check%20if%20any%20mappings%20already%20exist%20using%20this%20command.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Emsdtc%20-tmMappingView%20*%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20add%20a%20mapping%2C%20we%20use%20the%20-tmMappingSet%20parameter%20along%20with%20-name%2C%20-service%2C%20and%20-ClusterResourceName.%20An%20example%20would%20look%20like%20this.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Emsdtc%20-tmMappingSet%20-name%20MyMSDTC%20-service%20MSSQLServer%20-ClusterResourceName%20ClusterDTC1%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20look%20at%20the%20parameters%20to%20understand%20what%20they%20are%20asking.%26nbsp%3B%20The%20-name%20parameter%20is%20the%20name%20you%20want%20to%20give%20to%20the%20mapping%20and%20can%20be%20anything%20you%20want%20to%20call%20it.%26nbsp%3B%20The%20-service%20parameter%20is%20the%20name%20of%20the%20SQL%20Server%20Service%20running%20the%20instance%20of%20SQL%20Server%20you%20want%20to%20map%20to.%26nbsp%3B%20If%20it%20is%20a%20default%20instance%20it%20will%20be%20MSSQLServer%20and%20if%20it%20is%20a%20named%20instance%20it%20will%20be%20MSSQL%24%3CINSTANCENAME%3E.%20The%20-ClusterResourceName%20is%20the%20name%20of%20the%20MSDTC%20instance%20you%20created%20in%20the%20cluster%20that%20you%20want%20to%20map.%3C%2FINSTANCENAME%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20need%20to%20remove%20a%20mapping%20that%20uses%20the%20-tmMappingClear%20parameter%20and%20would%20look%20like%20this.%26nbsp%3B%20Note%20that%20the%20-name%20parameter%20is%20the%20name%20of%20the%20mapping%20you%20chose%20in%20the%20step%20above.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Emsdtc%20-tmMappingClear%20-name%20MyMSDTC%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1160030576%22%20id%3D%22toc-hId-1160030576%22%20id%3D%22toc-hId-1160030576%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--1392126385%22%20id%3D%22toc-hId--1392126385%22%20id%3D%22toc-hId--1392126385%22%3EVerify%20MSDTC%3C%2FH2%3E%0A%3CP%3EIf%20you%E2%80%99re%20like%20me%2C%20you%20want%20to%20verify%20your%20configuration%20and%20make%20sure%20your%20SQL%20instance%20is%20using%20the%20MSDTC%20you%20expect.%26nbsp%3B%20It%E2%80%99s%20a%20pretty%20simple%20two%20step%20process.%26nbsp%3B%20First%2C%20we%20start%20a%20distributed%20transaction%20on%20our%20instance%20and%20second%2C%20we%20look%20in%20component%20services%20to%20see%20the%20transaction%20hit%20the%20coordinator.%26nbsp%3B%20In%20my%20test%20environment%20I%20have%20the%20local%20MSDTC%20service%20disabled%2C%20an%20MSDTC%20in%20its%20own%20role%2C%20and%20an%20MSDTC%20in%20the%20same%20role%20as%20my%20AG.%26nbsp%3B%20The%20MSDTC%20in%20its%20own%20role%20is%20configured%20as%20the%20Default%20Clustered%20Instance%20and%20the%20MSDTC%20in%20the%20AG%20role%20is%20manually%20mapped%20to%20the%20instance%20of%20SQL%20Server%20hosting%20my%20AG.%26nbsp%3B%20Here%20is%20the%20code%20I%20will%20use.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUSE%20App1AG_DB1%3B%3C%2FP%3E%0A%3CP%3EGO%3C%2FP%3E%0A%3CP%3EBEGIN%20DISTRIBUTED%20TRANSACTION%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%2F*%3C%2FP%3E%0A%3CP%3ECOMMIT%20TRANSACTION%3B%3C%2FP%3E%0A%3CP%3EROLLBACK%20TRANSACTION%3B%3C%2FP%3E%0A%3CP%3E*%2F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20have%20the%20COMMIT%20and%20ROLLBACK%20statements%20in%20a%20comment%20block%20so%20I%20can%20see%20the%20transaction%20hit%20the%20coordinator%20and%20then%20I%20can%20choose%20to%20either%20commit%20or%20roll%20it%20back%20and%20see%20that%20in%20component%20services.%26nbsp%3B%20Once%20I%20run%20the%20code%20that%20is%20not%20commented%2C%20here%20is%20what%20I%20see%20in%20Component%20Services.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20924px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F137222iD884EA5DE0429BC0%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Component%20Services%20Active.png%22%20title%3D%22Component%20Services%20Active.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20can%20see%20that%20I%20have%201%20transaction%20that%20is%20active%20in%20my%20APP1AG%20MSDTC.%26nbsp%3B%20That%20is%20the%20MSDTC%20I%20have%20in%20my%20AG%20role%20and%20is%20what%20I%20expected%20since%20I%20manually%20mapped%20it%20to%20override%20the%20Clustered%20Default%20which%20is%20the%20MYMSDTC.%26nbsp%3B%20When%20I%20look%20at%20the%20Local%20MSDTC%20and%20MYMSDTC%20Transaction%20Statistics%20I%20see%20all%20zeros%20which%20confirms%20I%20am%20only%20using%20the%20APP1AG%20MSDTC.%26nbsp%3B%20If%20I%20run%20the%20ROLLBACK%20statement%2C%20here%20is%20what%20I%20see%20in%20Component%20Services.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20836px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F137223i128A36F2ED510897%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Component%20Services%20Rollback.png%22%20title%3D%22Component%20Services%20Rollback.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-350683950%22%20id%3D%22toc-hId-350683950%22%20id%3D%22toc-hId-350683950%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--1316196446%22%20id%3D%22toc-hId--1316196446%22%20id%3D%22toc-hId--1316196446%22%3EBest%20Practices%20Conclusion%3C%2FH2%3E%0A%3CP%3EThe%20first%20thing%20is%20to%20understand%20how%20SQL%20Server%20enrolls%20with%20a%20transaction%20coordinator%2C%20so%20you%20know%20which%20one%20it%20is%20going%20to%20use.%26nbsp%3B%20It%E2%80%99s%20the%20local%20MSDTC%20by%20default%20and%20we%20need%20to%20disable%20that%20service%20to%20use%20a%20clustered%20MSDTC%20and%20then%20define%20it%20in%20Component%20Services.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20second%20thing%20is%20to%20use%20a%20clustered%20MSDTC%20instead%20of%20a%20local%20one%20so%20we%20can%20make%20it%20highly%20available.%26nbsp%3B%20This%20means%20we%20need%20to%20change%20the%20Default%20Coordinator%20and%20have%20some%20type%20of%20shared%20storage%20to%20host%20the%20MSDTC%20log%20file.%20For%20an%20example%20of%20shared%20storage%20using%20Storage%20Spaces%20Direct%20check%20out%20this%20article%20on%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FPremier-Field-Engineering%2FConfigure-SQL-Server-Failover-Cluster-Instance-on-Azure-Virtual%2Fba-p%2F371464%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EConfigure%20SQL%20Server%20Failover%20Cluster%20Instance%20on%20Azure%20Virtual%20Machines%20with%20MSDTC%3C%2FA%3E.%26nbsp%3B%20It%E2%80%99s%20geared%20toward%20FCIs%2C%20but%20the%20Storage%20Spaces%20configuration%20is%20the%20same%20when%20deploying%20AGs.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20third%20thing%20is%20to%20consider%20scaling%20out%20and%20using%201%20MSDTC%20per%20instance.%26nbsp%3B%20The%20only%20way%20to%20scale%20this%20out%20with%20multiple%20AGs%20is%20to%20put%20each%20AG%20in%20its%20own%20instance.%26nbsp%3B%20Remember%20that%20manually%20mapping%20is%20the%20only%20way%20to%20override%20the%20setting%20in%20the%20Default%20Clustered%20Instance%20and%20ensure%20that%20each%20instance%20hosting%20an%20AG%20is%20using%20a%20specific%20MSDTC.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELast%20is%20to%20make%20sure%20we%20put%20our%20MSDTC%20inside%20the%20role%20of%20our%20AG%20so%20when%20the%20AG%20fails%20over%2C%20the%20MSDTC%20will%20go%20with%20it.%26nbsp%3B%20Otherwise%20we%20run%20the%20risk%20of%20introducing%20network%20latency%20with%20the%20MSDTC%20and%20SQL%20Instance%20on%20different%20nodes.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-909429%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20the%20best%20practices%20for%20deploying%20a%20highly%20available%20MSDTC%20with%20your%20Availability%20Group.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-909429%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ERyanAdams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-914707%22%20slang%3D%22en-US%22%3ERe%3A%20MSDTC%20Best%20Practices%20with%20an%20Availability%20Group%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-914707%22%20slang%3D%22en-US%22%3E%3CP%3EGreat%20resource%2C%20thanks%20Ryan!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHopefully%2C%20Microsoft%20will%20integrate%20this%20kind%20of%20highly%20available%20MSDTC%20configuration%20built-in%20into%20the%20AG%20default%20configuration%20(or%20at%20least%20make%20it%20configurable%20during%20the%20wizard%20and%2For%20installation%20of%20FCI).%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

In this article we are going to look at some guidelines and MSDTC best practices with an Availability Group.  Please note that some of these recommendations change if you are deploying a Failover Cluster Instance.  If you are using the MSDTC (BizTalk, Linked Servers, etc.) and hosting the databases in an Availability Group, there are several things we need to take into consideration.

 

Precedence

When an instance of SQL Server starts it enlists with a transaction coordinator and Resource Manager.  Think of the coordinator as the Windows Service and the Manager as the handler between the service and SQL Server.  The SQL Server instance has always been the Resource Manager until SQL 2016 when support for the MSDTC in an AG became available.  In a SQL 2016 AG where per database MSDTC has been enabled, each database becomes its own Resource Manager.  For more information on versions and supportability for MSDTC please refer to the “Availability Group” and “Support Matrix” sections of this article on MSDTC Supported Configurations.

 

The order of precedence defines which MSDTC Coordinator SQL Server will enlist with at startup.  Although the precedence order has been discussed in the past, what we will see is that there really is no order.  The first place SQL Server looks is to see what the Default Clustered Instance is configured for within the Windows Cluster.  We can find this by opening Component Services or comexp.msc, right clicking My Computer, and selecting Properties.  Here is what that looks like prior to Windows Server 2016.  In Windows 2016+ you would not see the check box for “Use Local Coordinator”.

 

Clustered Default Coordinator.png

 

We can see that the Default Coordinator will use the local MSDTC by default (A default with a default!). In Windows 2016+ you cannot change this default and would need to disable the service. I recommend disabling the service no matter what version of Windows you are using. Note that once you disable the service for the local MSDTC, you need have a clustered MSDTC defined or you will not have anything at all. Refer to the Manually Map MSDTC section later in this article for more information. You might be tempted to leave it on thinking it could serve as a backup, but if you do not want to use the local MSDTC you MUST disable this. Also, the SQL instance only enlists with an MSDTC Coordinator once at startup and never tries again. If you enable WITH DTC_SUPPORT = PER_DB in an AG, then this occurs for each database when it starts. If we want to use a clustered MSDTC then we will need to remove that check mark and select our desired default. Here is where you can find and disable the service using services.msc.

 

 

Local DTC Service.png

 

Looking back at Component Services you will see we have a drop-down box where we can select our Default Clustered Instance.  Whatever you select here is what SQL will use for its MSDTC Coordinator and completes our “order of precedence”.  You may have heard about an order that describes a DTC in its own role or DTCs within SQL roles. I will describe those scenarios in the Quantity section but know that they must be manually mapped per instance to override using the default, so this is where our order ends.  There are no automatic choices for SQL beyond the Default Clustered Instance since it must be defined.

 

Availability

A paramount concept to understand is how to make the DTC highly available.  We can see from the precedence order that SQL Server will use the local DTC out of the box.  This makes it appear that everything is working, and it is, but it is not exactly highly available.

 

I see a lot of customers leave it configured this way because they either don’t know the ramifications or do not realize they are using the MSDTC (Linked Servers). Since it simply works out of the box, things get left this way until they end up with a suspect database and error messages that look like this:

 

"SQL Server detected a DTC/KTM in-doubt transaction with UOW  {598B7EDD-F7A1-9DC1-8D3E-303A4C93AAB4}.Please resolve it following the guideline for Troubleshooting DTC Transactions."

 

"An error occurred while recovering database 'MyCriticalDB'. Unable to connect to Microsoft Distributed Transaction Coordinator (MS DTC) to check the completion status of transaction (5:861236355). Fix MS DTC, and run recovery again."

 

"Database 'MyCriticalDB' cannot be opened. It has been marked SUSPECT by recovery. See the SQL Server errorlog for more information."

 

Let’s look at an example of how this could happen.  Assume we have a 2 node AG using local DTCs.  Here is what that would look like. 

 

FCI Local DTC.png

 

If Node1 fails and the local MSDTC on that node has an in-flight distributed transaction, the local MSDTC on Node2 kicks in after the failover. The local MSDTC on Node2 tries to contact the local MSDTC on Node1 and retrieve the status of any in-doubt transactions. This process is attempted 3 times. If the old primary (Node1) still cannot be contacted, SQL takes its direction from the In-doubt Transaction Configuration or "in-doubt xact resolution" in sp_configure.  SPOILER ALERT – This is not configured by default which means your database will go into Suspect mode…Yikes!

 

Is there some availability in this configuration? Yes, since the new primary node attempts to discover the transaction status from the failed primary node.  Is it highly available? No, and the prior error messages demonstrate that.  If the old primary does not come back online and fast enough prior to the 3 attempts from the new primary, SQL must decide whether to commit or roll back.  The problem is that the status of in-flight distributed transactions is stored locally on the node.  If the log was on shared storage then the Resource Manager would know the outcome.

 

If using the local DTC is not highly available, the next natural question is, “How do we remedy that?”  The answer lies in the log for the MSDTC service.  Just like SQL Server, the MSDTC has a log file it uses to track the status of distributed transactions.  If we can make that log file highly available, then we make the MSDTC highly available.

 

There are several methods to make the MSDTC log highly available by making the storage where it is located highly available. This ensures that the MSDTC log and thus the outcome of distributed in-flight transactions is immediately available post failover. You can accomplish this using technologies like iSCSI (assuming the host has redundancy for the storage) or Storage Spaces Direct (S2D) and we have some partners with excellent solutions as well. If you want to see how to do this using S2D you can check out this post on Configure SQL Server Failover Cluster Instance on Azure Virtual Machines with MSDTC.

 

That post is geared toward FCIs, but the MSDTC part is identical for AGs.  The one thing you will note about having shared storage to make the MSDTC highly available is that it is not congruent with the architecture of AGs.  AGs do not have shared storage by design, so it seems counter intuitive to add shared storage to the design, but it is required only for the MSDTC to make it highly available like the AG.

 

Quantity

The last thing we want to consider is scaling out.  This is completely dependent on your MSDTC workload and may not be necessary.  If you have multiple instances of SQL Server running in your cluster and you create one clustered MSDTC in its own resource group, every instance uses that same MSDTC. If you have a lot of distributed transactions this can become a bottleneck.

 

For Failover Cluster Instances we can create an MSDTC per instance because each one is its own instance of SQL Server.  However, if you have multiple AGs they are most likely in the same instance of SQL Server and every AG will use the same MSDTC.  In this situation, you would need to spread the AGs across multiple instances.

 

The other issue that can get introduced with a single clustered MSDTC in its own role, is that you cannot guarantee it will run on the same node as your SQL instance. You could easily have an instance running on Node2 and using an MSDTC running on Node1. This can introduce network latency.  The best practice here would be to put the MSDTC for the instance running your AG in the same Windows Cluster Role.

 

If you decide to have multiple MSDTCs for multiple instances and put them in their respective roles, you will need to manually map them or they will continue to use the Default Clustered Instance.

 

Manually Map MSDTC

To manually map MSDTC to an instance of SQL Server we will need to use the msdtc.exe command line tool.  To start off we simply want to check if any mappings already exist using this command.

 

msdtc -tmMappingView *

 

To add a mapping, we use the -tmMappingSet parameter along with -name, -service, and -ClusterResourceName. An example would look like this.

 

msdtc -tmMappingSet -name MyMSDTC -service MSSQLServer -ClusterResourceName ClusterDTC1

 

Let’s look at the parameters to understand what they are asking.  The -name parameter is the name you want to give to the mapping and can be anything you want to call it.  The -service parameter is the name of the SQL Server Service running the instance of SQL Server you want to map to.  If it is a default instance it will be MSSQLServer and if it is a named instance it will be MSSQL$<InstanceName>. The -ClusterResourceName is the name of the MSDTC instance you created in the cluster that you want to map.

 

If you need to remove a mapping that uses the -tmMappingClear parameter and would look like this.  Note that the -name parameter is the name of the mapping you chose in the step above.

 

msdtc -tmMappingClear -name MyMSDTC

 

Verify MSDTC

If you’re like me, you want to verify your configuration and make sure your SQL instance is using the MSDTC you expect.  It’s a pretty simple two step process.  First, we start a distributed transaction on our instance and second, we look in component services to see the transaction hit the coordinator.  In my test environment I have the local MSDTC service disabled, an MSDTC in its own role, and an MSDTC in the same role as my AG.  The MSDTC in its own role is configured as the Default Clustered Instance and the MSDTC in the AG role is manually mapped to the instance of SQL Server hosting my AG.  Here is the code I will use.

 

USE App1AG_DB1;

GO

BEGIN DISTRIBUTED TRANSACTION

 

/*

COMMIT TRANSACTION;

ROLLBACK TRANSACTION;

*/

 

I have the COMMIT and ROLLBACK statements in a comment block so I can see the transaction hit the coordinator and then I can choose to either commit or roll it back and see that in component services.  Once I run the code that is not commented, here is what I see in Component Services.

 

Component Services Active.png

 

I can see that I have 1 transaction that is active in my APP1AG MSDTC.  That is the MSDTC I have in my AG role and is what I expected since I manually mapped it to override the Clustered Default which is the MYMSDTC.  When I look at the Local MSDTC and MYMSDTC Transaction Statistics I see all zeros which confirms I am only using the APP1AG MSDTC.  If I run the ROLLBACK statement, here is what I see in Component Services.

 

Component Services Rollback.png

 

Best Practices Conclusion

The first thing is to understand how SQL Server enrolls with a transaction coordinator, so you know which one it is going to use.  It’s the local MSDTC by default and we need to disable that service to use a clustered MSDTC and then define it in Component Services. 

 

The second thing is to use a clustered MSDTC instead of a local one so we can make it highly available.  This means we need to change the Default Coordinator and have some type of shared storage to host the MSDTC log file. For an example of shared storage using Storage Spaces Direct check out this article on Configure SQL Server Failover Cluster Instance on Azure Virtual Machines with MSDTC.  It’s geared toward FCIs, but the Storage Spaces configuration is the same when deploying AGs.

 

The third thing is to consider scaling out and using 1 MSDTC per instance.  The only way to scale this out with multiple AGs is to put each AG in its own instance.  Remember that manually mapping is the only way to override the setting in the Default Clustered Instance and ensure that each instance hosting an AG is using a specific MSDTC.

 

Last is to make sure we put our MSDTC inside the role of our AG so when the AG fails over, the MSDTC will go with it.  Otherwise we run the risk of introducing network latency with the MSDTC and SQL Instance on different nodes.

 

 

1 Comment
Senior Member

Great resource, thanks Ryan!

 

Hopefully, Microsoft will integrate this kind of highly available MSDTC configuration built-in into the AG default configuration (or at least make it configurable during the wizard and/or installation of FCI).