%3CLINGO-SUB%20id%3D%22lingo-sub-1530496%22%20slang%3D%22en-US%22%3EHow%20to%20find%20SQL%20Server%20Replication%20related%20jobs%20and%20T-SQL%20statements%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1530496%22%20slang%3D%22en-US%22%3E%3CP%3EVerbose%20log%20is%20heavily%20used%26nbsp%3B%20in%20replication%20troubleshooting.%20You%20need%20to%20find%20the%20right%20job%20to%20enable%20to%20verbose%20log.%20However%2C%20it's%20not%20easy%20to%20find%20the%26nbsp%3B%20jobs%20when%20you%20have%20hundreds%20replication%20jobs%20in%20one%20server.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20is%20how%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E1.Distribution%20agent%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EFollowing%20queries%20list%20all%20the%20distribution%20agent%20jobs%2C%20including%20push%20subscriptions%20and%20pull%20subscriptions.%20(You%20may%20need%20add%20more%20clause%20to%20customize%20your%20queries).%20By%20default%2C%20the%20SQL%20Server%20agent%20job%20names%20equal%20to%20the%20agent%20names%20for%20push%20subscription%2C%20unless%20you%20explicitly%20modify%20the%20job%20names.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Euse%20distribution---in%20distributor%20server%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eif%20not%20exists(select%201%20from%20sys.tables%20where%20name%20%3D'MSreplservers')%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ebegin%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20job.name%20JobName%2Ca.name%20AgentName%2C%20a.publisher_db%2Ca.publication%20as%20publicationName%2Csp.name%20as%20publisherName%20%2Css.name%20as%20subscriber%2Ca.subscriber_db%2C%20a.local_job%20From%20MSdistribution_agents%20a%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einner%20join%20sys.servers%20sp%20on%20a.publisher_id%3Dsp.server_id--publisher%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einner%20join%20sys.servers%20ss%20on%20a.subscriber_id%20%3Dss.server_id--subscriber%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eleft%20join%20msdb..sysjobs%20job%20on%20job.job_id%3Da.job_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ewhere%20a.subscription_type%20%26lt%3B%26gt%3B2---%20filter%20out%20the%20anonymous%20subscriber%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eend%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eelse%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ebegin%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20job.name%20JobName%2Ca.name%20AgentName%2C%20a.publisher_db%2Ca.publication%20as%20publicationName%2Csp.srvname%20as%20publisherName%20%2Css.srvname%20as%20subscriber%2Ca.subscriber_db%2C%20a.local_job%20From%20MSdistribution_agents%20a%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einner%20join%20msreplservers%20sp%20on%20a.publisher_id%3Dsp.srvid--publisher%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einner%20join%20msreplservers%20ss%20on%20a.subscriber_id%20%3Dss.srvid--subscriber%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eleft%20join%20msdb..sysjobs%20job%20on%20job.job_id%3Da.job_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ewhere%20a.subscription_type%20%26lt%3B%26gt%3B2---%20filter%20out%20the%20anonymous%20subscriber%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eend%3C%2FFONT%3E%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%20image-alt%3D%22Liwei_0-1595042676620.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206172iA86FF450011964E2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_0-1595042676620.png%22%20alt%3D%22Liwei_0-1595042676620.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20push%20subscription%2C%20you%20can%20use%20the%20job%20name%20directly%20to%20find%20the%20job%20in%20distributor%20server.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_1-1595042676622.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206171iCBE11CE4829DB529%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_1-1595042676622.png%22%20alt%3D%22Liwei_1-1595042676622.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%26nbsp%3B%20pull%20subscriptions(local_job%3D0)%2C%20you%20need%20to%20run%20following%20query%20in%20the%20subscription%20database%20in%20subscriber%20server.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Euse%20subdb2%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B---in%20subscriber%20server%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ego%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20job.name%20as%20JobName%2Cdistribution_agent%20as%20AgentName%2C%20*From%20MSreplication_subscriptions%20s%20inner%20join%20msdb.dbo.sysjobs%20job%20on%20s.agent_id%3Djob.job_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBy%20default%2C%20the%20SQL%20Server%20agent%20job%20names%20equal%20to%20the%20agent%20names%20for%20pull%20subscription%2C%20unless%20you%20explicitly%20modify%20the%20job%20names.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_2-1595042676623.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206170i5C6A4D568B27CC72%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_2-1595042676623.png%22%20alt%3D%22Liwei_2-1595042676623.png%22%20%2F%3E%3C%2FSPAN%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%20image-alt%3D%22Liwei_3-1595042676625.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206173i11C9498AE431DA57%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_3-1595042676625.png%22%20alt%3D%22Liwei_3-1595042676625.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E2.Merge%20agent%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EFollowing%20queries%20list%20all%20the%20merge%20agent%20jobs%2C%20including%20push%20subscriptions%20and%20pull%20subscriptions.%20(You%20may%20need%20add%20more%20clause%20to%20customize%20your%20queries).%20By%20default%2C%20the%20SQL%20Server%20agent%20job%20names%20equal%20to%20the%20merge%20agent%20names.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Euse%20distribution---in%20distributor%20server%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eif%20not%20exists(select%201%20from%20sys.tables%20where%20name%20%3D'MSreplservers')%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ebegin%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20job.name%20JobName%2Ca.name%20AgentName%2C%20a.publisher_db%2Ca.publication%20as%20publicationName%2Csp.name%20as%20publisherName%20%2Css.name%20as%20subscriber%2Ca.subscriber_db%2C%20a.local_job%20From%20MSmerge_agents%20a%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einner%20join%20sys.servers%20sp%20on%20a.publisher_id%3Dsp.server_id--publisher%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einner%20join%20sys.servers%20ss%20on%20a.subscriber_id%20%3Dss.server_id--subscriber%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eleft%20join%20msdb..sysjobs%20job%20on%20job.job_id%3Da.job_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eend%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eelse%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ebegin%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20job.name%20JobName%2Ca.name%20AgentName%2C%20a.publisher_db%2Ca.publication%20as%20publicationName%2Csp.srvname%20as%20publisherName%20%2Css.srvname%20as%20subscriber%2Ca.subscriber_db%2C%20a.local_job%20From%20MSmerge_agents%20a%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einner%20join%20msreplservers%20sp%20on%20a.publisher_id%3Dsp.srvid--publisher%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einner%20join%20msreplservers%20ss%20on%20a.subscriber_id%20%3Dss.srvid--subscriber%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eleft%20join%20msdb..sysjobs%20job%20on%20job.job_id%3Da.job_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eend%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_4-1595042676626.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206174i5987820DDDB1AA25%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_4-1595042676626.png%22%20alt%3D%22Liwei_4-1595042676626.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20push%20subscription%2C%20you%20can%20use%20the%20job%20name%20directly%20to%20find%20the%20job%20in%20distributor%20server.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_5-1595042676627.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206175i1532D6D0014381C2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_5-1595042676627.png%22%20alt%3D%22Liwei_5-1595042676627.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%26nbsp%3B%20pull%20subscriptions(local_job%3D0)%2C%20you%20need%20to%20run%20following%20query%20in%20the%20subscription%20database%20in%20subscriber%20server.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Euse%20subdb6--in%20subscriber%20server%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ego%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20job.name%2C%20sub.publisher%2Csub.publisher_db%2Csub.publication%20from%26nbsp%3B%20msdb..sysjobs%20job%20inner%20join%20msdb..sysjobsteps%20jobStep%20on%20job.job_id%3DjobStep.job_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einner%20join%20MSsubscription_properties%20sub%20on%20sub.job_step_uid%3DjobStep.step_uid%3C%2FFONT%3E%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%20image-alt%3D%22Liwei_6-1595042676628.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206178i100254E7BB1E2828%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_6-1595042676628.png%22%20alt%3D%22Liwei_6-1595042676628.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20use%20the%20job%20name%20directly%20to%20find%20the%20job%20in%20subscriber%20server.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_7-1595042676630.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206177i46C9CAF97AEE097A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_7-1595042676630.png%22%20alt%3D%22Liwei_7-1595042676630.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E3.Snapshot%20agent%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EFollowing%20queries%20list%20all%20the%20snapshot%20agent%20jobs.%20(You%20may%20need%20add%20more%20clause%20to%20customize%20your%20queries).%20By%20default%2C%20the%20SQL%20Server%20agent%20job%20names%20equal%20to%20the%20snapshot%20agent%20names%2C%20unless%20you%20explicitly%20modify%20the%20job%20names.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Euse%20distribution--in%20distributor%20server%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eif%20not%20exists(select%201%20from%20sys.tables%20where%20name%20%3D'MSreplservers')%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ebegin%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%26nbsp%3Bjob.name%20JobName%2C%20a.name%20AgentName%20%2C%20publisher_db%2Cpublication%2C%20s.data_source%20as%20publisher%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ecase%20publication_type%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ewhen%200%20then%20'Transactional'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ewhen%201%20then%20'snapshot'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ewhen%202%20then%20'Merge'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eend%20as%20publication_type%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E%26nbsp%3B%26nbsp%3B%20From%20MSsnapshot_agents%20a%20inner%20join%20sys.servers%20s%20on%20a.publisher_id%3Ds.server_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E%26nbsp%3B%26nbsp%3B%20inner%20join%20msdb..sysjobs%20job%20on%20a.job_id%3Djob.job_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eend%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eelse%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ebegin%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%26nbsp%3Bjob.name%20JobName%2C%20a.name%20AgentName%2C%20publisher_db%2Cpublication%2C%20s.srvname%20as%20publisher%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ecase%20publication_type%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ewhen%200%20then%20'Transactional'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ewhen%201%20then%20'snapshot'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ewhen%202%20then%20'Merge'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eend%20as%20publication_type%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E%26nbsp%3B%26nbsp%3B%20From%20MSsnapshot_agents%20a%20inner%20join%20MSreplservers%20s%20on%20a.publisher_id%3Ds.srvid%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E%26nbsp%3B%26nbsp%3B%20inner%20join%20msdb..sysjobs%20job%20on%20a.job_id%3Djob.job_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eend%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_8-1595042676631.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206176i3369F20CFFF8DC6A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_8-1595042676631.png%22%20alt%3D%22Liwei_8-1595042676631.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20use%20the%20job%20name%20directly%20to%20find%20the%20job%20in%20distributor%20server.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_9-1595042676632.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206179i638A2D33447713A0%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_9-1595042676632.png%22%20alt%3D%22Liwei_9-1595042676632.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E4.Logreader%20agent%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EFollowing%20queries%20list%20all%20the%20log%20agent%20jobs%2C%20including%20push%20subscriptions%20and%20pull%20subscriptions.%20(You%20may%20need%20add%20more%20clause%20to%20customize%20your%20queries).%20By%20default%2C%20the%20SQL%20Server%20agent%20job%20names%20equal%20to%20the%20log%20reader%20agent%20names.%3C%2FP%3E%0A%3CP%3Euse%20distribution%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eif%20not%20exists(select%201%20from%20sys.tables%20where%20name%20%3D'MSreplservers')%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ebegin%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%26nbsp%3Bjob.name%20JobName%2C%20a.name%20AgentName%2C%20publisher_db%2Cs.name%20as%20publisher%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3EFrom%20MSlogreader_agents%20a%20inner%20join%20sys.servers%20s%20on%20a.publisher_id%3Ds.server_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3EInner%20join%20msdb..sysjobs%20job%20on%20job.job_id%3Da.job_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eend%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eelse%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ebegin%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%26nbsp%3Bjob.name%20JobName%2C%20a.name%20AgentName%2C%20publisher_db%2Cs.srvname%20as%20publisher%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3EFrom%20MSlogreader_agents%20a%20inner%20join%20MSreplservers%20s%20on%20a.publisher_id%3Ds.srvid%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3EInner%20join%20msdb..sysjobs%20job%20on%20job.job_id%3Da.job_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eend%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20%3CSTRONG%3Enote%3C%2FSTRONG%3E%2C%20all%20publications%20of%20same%20publication%20database%20share%20same%20agent%20job%3C%2FP%3E%0A%3CP%3EPlease%20%3CSTRONG%3Enote%3C%2FSTRONG%3E%2C%20the%20agent%20name%20equals%20to%20job%20name%20by%20default%2C%20unless%20user%20modifies%20the%20job.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_10-1595042676633.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206181i9F0361B07FBBD6AD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_10-1595042676633.png%22%20alt%3D%22Liwei_10-1595042676633.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%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%20image-alt%3D%22Liwei_11-1595042676635.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206180i6C35991F5A50ADCE%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Liwei_11-1595042676635.png%22%20alt%3D%22Liwei_11-1595042676635.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20some%20complex%20cases%2C%20you%20may%20need%20to%20review%20all%20the%20T-SQL%20statements%20issued%20by%20these%20agent%20jobs.%3C%2FP%3E%0A%3CP%3EHere%20is%20how%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20agent%20have%20more%20than%20one%20connections%20to%20the%20servers%2C%20they%20have%20different%20session%20id%20but%20share%20the%20same%20process%20id.%20Once%20the%20process%20id%20is%20identified%2C%20you%20can%20use%20this%20process%20id%20to%20filter%2C%20using%20SQL%20Server%20profiler%20trace%20or%20xevent.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3E%20Distribution%20agent%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EDistribution%20agent%20connects%20both%20distributor%20and%20subscriber.%20It%20has%20more%20than%20one%20connections%20in%20distributor.%20The%20application%20name%20of%20one%20connections%20equals%20to%20the%20agent%20name%2C%20that's%20how%20I%20get%20all%20the%20connections%20of%20one%20specific%20agent.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1)For%20example%2C%20following%20query%20returns%206%20agents.%3C%2FP%3E%0A%3CP%3Euse%20distribution%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%26nbsp%3B%20*%26nbsp%3B%20From%20MSdistribution_agents%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_12-1595042676636.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206183iCC26369CB35470A5%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_12-1595042676636.png%22%20alt%3D%22Liwei_12-1595042676636.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2)Let's%20say%20I%20need%20to%20check%20the%20T-SQL%20of%20first%20agent.%3C%2FP%3E%0A%3CP%3EIf%20SQL%20Server%20trace%20files%20are%20collected%20in%20distributor%20and%20subscriber%20are%20collected%2C%20use%20the%20agent%20name%20to%20filter%20ApplicationName%20column%20to%20find%20the%20process%20id%20in%20%3CSTRONG%3Edistributor%3C%2FSTRONG%3E%20trace.%3C%2FP%3E%0A%3CP%3EThen%20Use%20the%20process%20id%20to%20filter%20queries%20in%20distributor%20trace%20and%20subscriber%20trace.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20need%20online%20troubleshoot%2Crun%20following%20statement%20in%20%3CSTRONG%3Edistributor%3C%2FSTRONG%3E%20server.%3C%2FP%3E%0A%3CP%3Eselect%20hostprocess%20as%20PID%20from%20sys.sysprocesses%20where%20program_name%20%3D'NODE1%5CSQLAG-AdventureWorks-TranPubTest1-NODE3%5CSQLAG-6'%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%20image-alt%3D%22Liwei_13-1595042676638.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206182i8DFF7B95266B4E9E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_13-1595042676638.png%22%20alt%3D%22Liwei_13-1595042676638.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3)It%20returns%20the%20process%20id%20of%20this%20agent.%20Then%20you%20can%20use%20the%20process%20id%20of%20find%20all%20the%20sessions%20in%20both%20distributor%20server%20and%20subscriber%20server.%3C%2FP%3E%0A%3CP%3EIn%20distributor%20server%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20%40%40servername%2C*From%20sys.sysprocesses%20where%20hostprocess%3D1832%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_14-1595042676639.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206184i1057C00178B977F4%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_14-1595042676639.png%22%20alt%3D%22Liwei_14-1595042676639.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20subscriber%20server%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20%40%40servername%2Cprogram_name%2C*From%20sys.sysprocesses%20where%20hostprocess%3D1832%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_15-1595042676640.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206185iA8DDB35F58990FBB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_15-1595042676640.png%22%20alt%3D%22Liwei_15-1595042676640.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E4)An%20alternative%20is%20to%20run%20following%20query%20in%20subscription%20database%2C%20then%20use%20the%20hostprocess%20to%20filter%E2%80%A6%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Euse%20subdbName%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20hostprocess%2C%20*From%20sys.sysprocesses%20where%20spid%20in%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E(%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20spid%20From%20MSsubscription_agents%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E2.Merge%20agent%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThe%20behavior%20of%20Merge%20agent%20is%20as%20same%20as%20distribution%20agent.%26nbsp%3B%20It%20connects%20publisher%2C%20distributor%20and%20subscriber.%3C%2FP%3E%0A%3CP%3E1.Run%20following%20query%20in%20distributor%20server.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Euse%20distribution%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20*%20From%20MSmerge_agents%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_16-1595042676641.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206186i6E22FE7BDE7E86D2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_16-1595042676641.png%22%20alt%3D%22Liwei_16-1595042676641.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2)Let's%20say%20I%20need%20to%20check%20the%20T-SQL%20of%20first%20agent.%3C%2FP%3E%0A%3CP%3EIf%20SQL%20Server%20trace%20files%20are%20collected%20in%20publisher%2Cdistributor%20and%20subscriber%20are%20collected%2C%20please%20use%20the%20agent%20name%20to%20filter%20ApplicationName%20column%20to%20find%20the%20process%20id%20in%20%3CSTRONG%3Epublisher%3C%2FSTRONG%3E%20trace.%3C%2FP%3E%0A%3CP%3EThen%20Use%20the%20process%20id%20to%20filter%20queries%20in%20publisher%2C%20distributor%20trace%20and%20subscriber%20trace.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3)If%20you%20need%20online%20troubleshoot%2C.%20run%20following%20statement%20in%20%3CSTRONG%3Epublisher%3C%2FSTRONG%3E%20server.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20%40%40servername%2Chostprocess%20From%20sys.sysprocesses%20where%20program_name%20in%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E(%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E'NODE1%5CSQLAG-AdventureWorks-MergePubTest-NODE3%5CSQLAG-1'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_17-1595042676642.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206187i88CD67E76BA938A7%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_17-1595042676642.png%22%20alt%3D%22Liwei_17-1595042676642.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3)Use%20this%20process%20id%20to%20filter%20queries%20in%20distributor%20and%20subscriber%2C%20the%20same%20way%20I%20used%20for%20distribution%20agent.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E3.Snapshot%20agent%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThe%20behavior%20of%20Snapshot%20agent%20is%20as%20same%20as%20distribution%20agent.%26nbsp%3B%20It%20connects%20publisher%20and%20distributor%3C%2FP%3E%0A%3CP%3E1.Run%20following%20query%20in%20distributor%20server.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Euse%20distribution%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20*%20From%20MSsnapshot_agents%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_18-1595042676643.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206188iD78FF05E3B94607A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_18-1595042676643.png%22%20alt%3D%22Liwei_18-1595042676643.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2)Let's%20say%20I%20need%20to%20check%20the%20T-SQL%20of%20first%20agent.%3C%2FP%3E%0A%3CP%3EIf%20SQL%20Server%20trace%20files%20are%20collected%20in%20publisher%20and%20distributor%20are%20collected%2C%20please%20use%20the%20agent%20name%20to%20filter%20ApplicationName%20column%20to%20find%20the%20process%20id%20in%20%3CSTRONG%3Epublisher%3C%2FSTRONG%3E%20trace.%3C%2FP%3E%0A%3CP%3EThen%20Use%20the%20process%20id%20to%20filter%20queries%20in%20publisher%20and%20distributor%20trace.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3)If%20you%20need%20online%20troubleshoot%2C%20run%20following%20statement%20in%20%3CSTRONG%3Epublisher%3C%2FSTRONG%3E%20server.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20%40%40servername%2Chostprocess%20From%20sys.sysprocesses%20where%20program_name%20in%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E(%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E'NODE1%5CSQLAG-AdventureWorks-MergePubTest-NODE3%5CSQLAG-1'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3)Use%20this%20process%20id%20to%20filter%20queries%20in%20publisher%20and%20distributor%20%2C%20the%20same%20way%20I%20used%20for%20distribution%20agent.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E4.Logreader%20agent%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ELogreader%20agent%20is%20little%20bit%20different.%20The%20agent%20name%20of%20MSlogreader_agents%20does%20not%20match%20anything.%20You%20need%20to%20use%26nbsp%3B%20following%20pattern%20to%20filter.%3C%2FP%3E%0A%3CP%3EThe%20application%20name%20of%20logreaer%20agent%20consists%20of%20Repl-LogReader-number-publicationDBName-number.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20example%2C%20if%20you%20need%20to%20collect%20process%20id%20of%20logreader%20of%20AdventureWorks%2C%20run%20following%20query%20in%20both%20publisher%20server%20and%20distributor%20server.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20program_name%2C%20hostprocess%2C%40%40servername%20From%20sys.sysprocesses%20where%20program_name%20like%20'Repl-LogReader%25'%20and%20program_name%20like%20'%25AdventureWorks%25'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_19-1595042676644.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206189i6B913A5AC766AA97%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_19-1595042676644.png%22%20alt%3D%22Liwei_19-1595042676644.png%22%20%2F%3E%3C%2FSPAN%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%20image-alt%3D%22Liwei_20-1595042676645.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206190iA0E3C461A22C75CD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_20-1595042676645.png%22%20alt%3D%22Liwei_20-1595042676645.png%22%20%2F%3E%3C%2FSPAN%3E%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-1530496%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_21-1595043805369.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206193i089C1DF03A9AE2F3%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Liwei_21-1595043805369.png%22%20alt%3D%22Liwei_21-1595043805369.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1530496%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EReplication%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Verbose log is heavily used  in replication troubleshooting. You need to find the right job to enable to verbose log. However, it's not easy to find the  jobs when you have hundreds replication jobs in one server.

 

 

Here is how:

1.Distribution agent

Following queries list all the distribution agent jobs, including push subscriptions and pull subscriptions. (You may need add more clause to customize your queries). By default, the SQL Server agent job names equal to the agent names for push subscription, unless you explicitly modify the job names.

use distribution---in distributor server

if not exists(select 1 from sys.tables where name ='MSreplservers')

begin

select job.name JobName,a.name AgentName, a.publisher_db,a.publication as publicationName,sp.name as publisherName ,ss.name as subscriber,a.subscriber_db, a.local_job From MSdistribution_agents a

inner join sys.servers sp on a.publisher_id=sp.server_id--publisher

inner join sys.servers ss on a.subscriber_id =ss.server_id--subscriber

left join msdb..sysjobs job on job.job_id=a.job_id

where a.subscription_type <>2--- filter out the anonymous subscriber

end

else

begin

select job.name JobName,a.name AgentName, a.publisher_db,a.publication as publicationName,sp.srvname as publisherName ,ss.srvname as subscriber,a.subscriber_db, a.local_job From MSdistribution_agents a

inner join msreplservers sp on a.publisher_id=sp.srvid--publisher

inner join msreplservers ss on a.subscriber_id =ss.srvid--subscriber

left join msdb..sysjobs job on job.job_id=a.job_id

where a.subscription_type <>2--- filter out the anonymous subscriber

end

 

Liwei_0-1595042676620.png

 

 

For push subscription, you can use the job name directly to find the job in distributor server.

Liwei_1-1595042676622.png

 

 

For  pull subscriptions(local_job=0), you need to run following query in the subscription database in subscriber server.

use subdb2        ---in subscriber server

go

select job.name as JobName,distribution_agent as AgentName, *From MSreplication_subscriptions s inner join msdb.dbo.sysjobs job on s.agent_id=job.job_id

 

By default, the SQL Server agent job names equal to the agent names for pull subscription, unless you explicitly modify the job names.

Liwei_2-1595042676623.png

 

 

Liwei_3-1595042676625.png

 

 

 

 

 

2.Merge agent

Following queries list all the merge agent jobs, including push subscriptions and pull subscriptions. (You may need add more clause to customize your queries). By default, the SQL Server agent job names equal to the merge agent names.

use distribution---in distributor server

if not exists(select 1 from sys.tables where name ='MSreplservers')

begin

select job.name JobName,a.name AgentName, a.publisher_db,a.publication as publicationName,sp.name as publisherName ,ss.name as subscriber,a.subscriber_db, a.local_job From MSmerge_agents a

inner join sys.servers sp on a.publisher_id=sp.server_id--publisher

inner join sys.servers ss on a.subscriber_id =ss.server_id--subscriber

left join msdb..sysjobs job on job.job_id=a.job_id

 

end

else

begin

select job.name JobName,a.name AgentName, a.publisher_db,a.publication as publicationName,sp.srvname as publisherName ,ss.srvname as subscriber,a.subscriber_db, a.local_job From MSmerge_agents a

inner join msreplservers sp on a.publisher_id=sp.srvid--publisher

inner join msreplservers ss on a.subscriber_id =ss.srvid--subscriber

left join msdb..sysjobs job on job.job_id=a.job_id

end

Liwei_4-1595042676626.png

 

 

For push subscription, you can use the job name directly to find the job in distributor server.

Liwei_5-1595042676627.png

 

 

 

For  pull subscriptions(local_job=0), you need to run following query in the subscription database in subscriber server.

use subdb6--in subscriber server

go

select job.name, sub.publisher,sub.publisher_db,sub.publication from  msdb..sysjobs job inner join msdb..sysjobsteps jobStep on job.job_id=jobStep.job_id

inner join MSsubscription_properties sub on sub.job_step_uid=jobStep.step_uid

 

Liwei_6-1595042676628.png

 

 

You can use the job name directly to find the job in subscriber server.

Liwei_7-1595042676630.png

 

 

 

 

 

3.Snapshot agent

Following queries list all the snapshot agent jobs. (You may need add more clause to customize your queries). By default, the SQL Server agent job names equal to the snapshot agent names, unless you explicitly modify the job names.

 

use distribution--in distributor server

if not exists(select 1 from sys.tables where name ='MSreplservers')

begin

select job.name JobName, a.name AgentName , publisher_db,publication, s.data_source as publisher,

case publication_type

when 0 then 'Transactional'

when 1 then 'snapshot'

when 2 then 'Merge'

end as publication_type

   From MSsnapshot_agents a inner join sys.servers s on a.publisher_id=s.server_id

   inner join msdb..sysjobs job on a.job_id=job.job_id

 

end

else

begin

select job.name JobName, a.name AgentName, publisher_db,publication, s.srvname as publisher,

case publication_type

when 0 then 'Transactional'

when 1 then 'snapshot'

when 2 then 'Merge'

end as publication_type

   From MSsnapshot_agents a inner join MSreplservers s on a.publisher_id=s.srvid

   inner join msdb..sysjobs job on a.job_id=job.job_id

end

Liwei_8-1595042676631.png

 

You can use the job name directly to find the job in distributor server.

Liwei_9-1595042676632.png

 

 

4.Logreader agent

Following queries list all the log agent jobs, including push subscriptions and pull subscriptions. (You may need add more clause to customize your queries). By default, the SQL Server agent job names equal to the log reader agent names.

use distribution

if not exists(select 1 from sys.tables where name ='MSreplservers')

begin

select job.name JobName, a.name AgentName, publisher_db,s.name as publisher

From MSlogreader_agents a inner join sys.servers s on a.publisher_id=s.server_id

Inner join msdb..sysjobs job on job.job_id=a.job_id

end

else

begin

select job.name JobName, a.name AgentName, publisher_db,s.srvname as publisher

From MSlogreader_agents a inner join MSreplservers s on a.publisher_id=s.srvid

Inner join msdb..sysjobs job on job.job_id=a.job_id

end

 

Please note, all publications of same publication database share same agent job

Please note, the agent name equals to job name by default, unless user modifies the job.

Liwei_10-1595042676633.png

 

 

 

Liwei_11-1595042676635.png

 

 

 

 

In some complex cases, you may need to review all the T-SQL statements issued by these agent jobs.

Here is how:

 

One agent have more than one connections to the servers, they have different session id but share the same process id. Once the process id is identified, you can use this process id to filter, using SQL Server profiler trace or xevent.

  1. Distribution agent

Distribution agent connects both distributor and subscriber. It has more than one connections in distributor. The application name of one connections equals to the agent name, that's how I get all the connections of one specific agent.

 

1)For example, following query returns 6 agents.

use distribution

select  *  From MSdistribution_agents

Liwei_12-1595042676636.png

 

 

2)Let's say I need to check the T-SQL of first agent.

If SQL Server trace files are collected in distributor and subscriber are collected, use the agent name to filter ApplicationName column to find the process id in distributor trace.

Then Use the process id to filter queries in distributor trace and subscriber trace.

 

If you need online troubleshoot,run following statement in distributor server.

select hostprocess as PID from sys.sysprocesses where program_name ='NODE1\SQLAG-AdventureWorks-TranPubTest1-NODE3\SQLAG-6'

 

Liwei_13-1595042676638.png

 

3)It returns the process id of this agent. Then you can use the process id of find all the sessions in both distributor server and subscriber server.

In distributor server

select @@servername,*From sys.sysprocesses where hostprocess=1832

Liwei_14-1595042676639.png

 

 

In subscriber server

select @@servername,program_name,*From sys.sysprocesses where hostprocess=1832

Liwei_15-1595042676640.png

 

 

4)An alternative is to run following query in subscription database, then use the hostprocess to filter…

use subdbName

select hostprocess, *From sys.sysprocesses where spid in

(

select spid From MSsubscription_agents

)

 

 

2.Merge agent

The behavior of Merge agent is as same as distribution agent.  It connects publisher, distributor and subscriber.

1.Run following query in distributor server.

use distribution

select * From MSmerge_agents

Liwei_16-1595042676641.png

 

 

2)Let's say I need to check the T-SQL of first agent.

If SQL Server trace files are collected in publisher,distributor and subscriber are collected, please use the agent name to filter ApplicationName column to find the process id in publisher trace.

Then Use the process id to filter queries in publisher, distributor trace and subscriber trace.

 

3)If you need online troubleshoot,. run following statement in publisher server.

select @@servername,hostprocess From sys.sysprocesses where program_name in

(

'NODE1\SQLAG-AdventureWorks-MergePubTest-NODE3\SQLAG-1'

)

Liwei_17-1595042676642.png

 

 

3)Use this process id to filter queries in distributor and subscriber, the same way I used for distribution agent.

 

 

3.Snapshot agent

The behavior of Snapshot agent is as same as distribution agent.  It connects publisher and distributor

1.Run following query in distributor server.

use distribution

select * From MSsnapshot_agents

Liwei_18-1595042676643.png

 

2)Let's say I need to check the T-SQL of first agent.

If SQL Server trace files are collected in publisher and distributor are collected, please use the agent name to filter ApplicationName column to find the process id in publisher trace.

Then Use the process id to filter queries in publisher and distributor trace.

 

3)If you need online troubleshoot, run following statement in publisher server.

select @@servername,hostprocess From sys.sysprocesses where program_name in

(

'NODE1\SQLAG-AdventureWorks-MergePubTest-NODE3\SQLAG-1'

)

 

3)Use this process id to filter queries in publisher and distributor , the same way I used for distribution agent.

 

4.Logreader agent

Logreader agent is little bit different. The agent name of MSlogreader_agents does not match anything. You need to use  following pattern to filter.

The application name of logreaer agent consists of Repl-LogReader-number-publicationDBName-number.

 

 

For example, if you need to collect process id of logreader of AdventureWorks, run following query in both publisher server and distributor server.

select program_name, hostprocess,@@servername From sys.sysprocesses where program_name like 'Repl-LogReader%' and program_name like '%AdventureWorks%'

Liwei_19-1595042676644.png

 

 

Liwei_20-1595042676645.png