The script executes at the Distributor! I use it primarily to monitor replication. Here is a case, for reference only! Modify the relevant parameters according to the actual situation
/*
Description: command is used to monitor replication performance in primary use:
1. Execution at the Distributor: monitoring the number of commands that the replication process runs, the Publisher to the Distributor, and the distribution to the subscriber;
2. Distribution server to subscriber replication wait
*/
-- ****************************************************************************************** ****
--Part I: Monitor whether the replication process is running, Publisher to Distributor, and the number of commands distributed to subscribers
-- ****************************************************************************************** ****
SET NOCOUNT ON
--New temporary table
CREATE TABLE #result
(
dbname sysname NULL,
Name nvarchar NOT NULL,
status int not NULL,
Publisher sysname NULL,
publisher_db sysname NULL,
Publication sysname NULL,
start_time datetime NULL,
Time datetime NULL,
Duration int NULL,
Comments nvarchar (255) NULL,
delivered_transactions int NULL,
delivered_commands int NULL,
delivery_rate int NULL,
job_id varchar () NULL,
delivery_latency int NULL,
Subscriber sysname NULL,
subscriber_db sysname NULL,
subscription_type int NULL,
Subscriber_type tinyint NULL,
Publisher_insertcount int NULL,
Publisher_updatecount int NULL,
Publisher_deletecount int NULL,
publisher_conflicts int NULL,
Subscriber_insertcount int NULL,
Subscriber_updatecount int NULL,
Subscriber_deletecount int NULL,
subscriber_conflicts int NULL,
Agent_type nvarchar (4000)
)