Do I really need to use DTC Transactions?

Published Jan 15 2019 04:24 PM 553 Views
Microsoft
First published on MSDN on Jan 26, 2015

It is sometimes common practice to enable Distributed Transaction (DTC) behavior but it can be unnecessary, and adds unwanted overhead.

DTC has the ability to determine single phase vs two phase commit requirements.  A DTC transaction involves resource managers (RMs) of which SQL Server can be one of them.  If a single resource manager is involved in the transaction there is no need to perform 2-phase commit.   DTC shortcuts the activity and performs a single-phase commit safely.   This reduces the communication between the DTC and RM managers.  However, the overhead of the DTC manager is still involved making the transaction slightly slower than a native TSQL transaction.

Single Phase

The following is a single phase DTC commit example.

begin distributed tran
go

update dbTest.dbo.tblTest set object_id = 100
go

commit tran
go

Notice the trace output does not indicate a prepared state.  This is a direct indication of a single phase commit.

Two Phase

The following is a 2-phase commit example.

begin distributed tran
go

update MYREMOTESERVER.dbTest.dbo.tblTest set object_id = 100
go

commit tran
go

The transaction involved the local instance (RM=1) and a remote instance (RM=2).  With 2 RMs involved DTC commits the transaction under full, 2-phase commit protocol.   Notice the prepared state in the trace indicating full, 2-phase commit protocol is being used.


You may want to review the DTC transactions executing on your system, looking for prepared state.  If the DTC transactions running on your system are not using 2-phase commit protocol you should consider removing DTC from the transactions in order to improve performance.

Bob Dorr - Principal SQL Server Escalation Engineer

%3CLINGO-SUB%20id%3D%22lingo-sub-318495%22%20slang%3D%22en-US%22%3EDo%20I%20really%20need%20to%20use%20DTC%20Transactions%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-318495%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Jan%2026%2C%202015%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EIt%20is%20sometimes%20common%20practice%20to%20enable%20Distributed%20Transaction%20(DTC)%20behavior%20but%20it%20can%20be%20unnecessary%2C%20and%20adds%20unwanted%20overhead.%3C%2FP%3E%0A%20%20%3CP%3EDTC%20has%20the%20ability%20to%20determine%20single%20phase%20vs%20two%20phase%20commit%20requirements.%26nbsp%3B%20A%20DTC%20transaction%20involves%20resource%20managers%20(RMs)%20of%20which%20SQL%20Server%20can%20be%20one%20of%20them.%26nbsp%3B%20If%20a%20single%20resource%20manager%20is%20involved%20in%20the%20transaction%20there%20is%20no%20need%20to%20perform%202-phase%20commit.%26nbsp%3B%26nbsp%3B%20DTC%20shortcuts%20the%20activity%20and%20performs%20a%20single-phase%20commit%20safely.%26nbsp%3B%26nbsp%3B%20This%20reduces%20the%20communication%20between%20the%20DTC%20and%20RM%20managers.%26nbsp%3B%20However%2C%20the%20overhead%20of%20the%20DTC%20manager%20is%20still%20involved%20making%20the%20transaction%20slightly%20slower%20than%20a%20native%20TSQL%20transaction.%3C%2FP%3E%0A%20%20%3CP%3E%3CSTRONG%3E%20Single%20Phase%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%20%20%3CP%3EThe%20following%20is%20a%20single%20phase%20DTC%20commit%20example.%3C%2FP%3E%0A%20%20%3CBLOCKQUOTE%3E%0A%20%20%20%3CP%3Ebegin%20distributed%20tran%20%3CBR%20%2F%3E%20go%3C%2FP%3E%0A%20%20%20%3CP%3Eupdate%20dbTest.dbo.tblTest%20set%20object_id%20%3D%20100%20%3CBR%20%2F%3E%20go%3C%2FP%3E%0A%20%20%20%3CP%3Ecommit%20tran%20%3CBR%20%2F%3E%20go%3C%2FP%3E%0A%20%20%3C%2FBLOCKQUOTE%3E%0A%20%20%3CP%3ENotice%20the%20trace%20output%20does%20not%20indicate%20a%20%3CEM%3E%20prepared%20%3C%2FEM%3E%20state.%26nbsp%3B%20This%20is%20a%20direct%20indication%20of%20a%20single%20phase%20commit.%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F68258iCB8C3317B8E7F620%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CSTRONG%3E%20Two%20Phase%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%20%20%3CP%3EThe%20following%20is%20a%202-phase%20commit%20example.%3C%2FP%3E%0A%20%20%3CBLOCKQUOTE%3E%0A%20%20%20%3CP%3Ebegin%20distributed%20tran%20%3CBR%20%2F%3E%20go%3C%2FP%3E%0A%20%20%20%3CP%3Eupdate%20MYREMOTESERVER.dbTest.dbo.tblTest%20set%20object_id%20%3D%20100%20%3CBR%20%2F%3E%20go%3C%2FP%3E%0A%20%20%20%3CP%3Ecommit%20tran%20%3CBR%20%2F%3E%20go%3C%2FP%3E%0A%20%20%3C%2FBLOCKQUOTE%3E%0A%20%20%3CP%3EThe%20transaction%20involved%20the%20local%20instance%20(RM%3D1)%20and%20a%20remote%20instance%20(RM%3D2).%26nbsp%3B%20With%202%20RMs%20involved%20DTC%20commits%20the%20transaction%20under%20full%2C%202-phase%20commit%20protocol.%26nbsp%3B%26nbsp%3B%20Notice%20the%20prepared%20state%20in%20the%20trace%20indicating%20full%2C%202-phase%20commit%20protocol%20is%20being%20used.%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F68259iC1F8D07C6B058DE5%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20You%20may%20want%20to%20review%20the%20DTC%20transactions%20executing%20on%20your%20system%2C%20looking%20for%20%3CSTRONG%3E%20%3CEM%3E%20prepared%20%3C%2FEM%3E%20%3C%2FSTRONG%3E%20state.%26nbsp%3B%20If%20the%20DTC%20transactions%20running%20on%20your%20system%20are%20not%20using%202-phase%20commit%20protocol%20you%20should%20consider%20removing%20DTC%20from%20the%20transactions%20in%20order%20to%20improve%20performance.%20%3CBR%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EBob%20Dorr%20-%20Principal%20SQL%20Server%20Escalation%20Engineer%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-318495%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Jan%2026%2C%202015%20It%20is%20sometimes%20common%20practice%20to%20enable%20Distributed%20Transaction%20(DTC)%20behavior%20but%20it%20can%20be%20unnecessary%2C%20and%20adds%20unwanted%20overhead.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-318495%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMSDTC%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETransactions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Jan 15 2019 04:24 PM
Updated by: