You are here:Home » undistributed commands » Script to get undistributed commands in replication - SQL Server

Script to get undistributed commands in replication - SQL Server

This post is about replication, you may read some earlier posts for the same. I would like you to go through the same with below links,
Configuration Replication failure and retry alert-SQL Server
Script to get replication latency and alert in SQL Server
The row was not found at the Subscriber when applying the replicated command - Alternate workaround
Copy nonclustered indexes to subscriber while generating snapshot - SQL Server Replication
Hope you enjoyed above posts and now going ahead to share information about the past of undistributed commands in transaction replication. Let me share a script here which runs against a distribution database on distributor server.
EXECUTE sp_replmonitorsubscriptionpendingcmds  
  @publisher ='publisher', -- Put publisher server name here
  @publisher_db = 'publisher_db', -- Put publisher database name here
  @publication ='publication',  -- Put publication name here
  @subscriber ='subscriber', -- Put subscriber server name here
  @subscriber_db ='subscriber_db', -- Put subscriber database name here
  @subscription_type ='1' -- 0 = push and 1 = pull
Above execution output is as follows,

This returns pending undistributed commands and estimated processing time for same for particular subscriber and some other parameters passed through the script. This is a same information which returns from subscriber details in the replication monitor as below,

Hope you liked it and stay tuned for more. I will come with another post which have different script to get the same information.