High Level Transactional Replication Process Flow
High Level Transactional Replication Process Flow
I’ve posted this flow before on my BLOG but I wanted to include the stored procedure calls used by Transactional Replication.
While troubleshooting Replication performance/latency we’ll try and identify which stored procedure executing from which Replication Agent has the highest IO or highest CPU usage. These usually are a great place to start the investigation. To analyze the processes flow we use SQL Profiler and/or SQLDIAG and capture RPC:COMPLETED Events. We also add –OUTPUT tracking parameter to the Agent which writes a text file of each agent execution step along with a time stamp.
Log Reader Agent (logread.exe) – Sequence of Steps
- Calls sp_MSadd_LogReader_History to write to MSLogReader_History – “Starting Agent”
- sp_MShelp_logreader_agentid – Obtain log reader agent specific information for that publication
- sp_MShelp_profile – Obtains profile information for the Log Reader
- MSadd_logreader_history to write MSlogreader_history – “Initializing”
- sp_MSget_last_transaction – determine where the log reader agent left off reading the log.
- Read the transaction log – sp_replcmds
- Processes the returned commands from the sp_replcmds in batches by calling sp_MSadd_repl_commands
- Marks this transaction as committed in distribution database by using sp_repldone procedure
- Adjusts the identity range if necessary and if you are using Automatic Identity Range Management y calling sp_MSpub_adjust_identity
- Calls sp_MSget_last_transaction to check the last transaction read and stored in MSReplication_transactions table
- When all transactions are read, LogRead.exe calls sp_MSAdd_logreader_history and writes message to MSLogReader_history “1 transactions with 9 commands were delivered”
Distribution Agent (distrib.exe) – Sequence of Steps
- master.db.sp_msget_jobstate – get the status of the job (if it is already started)
- sp_Msadd_distribution_history – MSDistribution_history – Starting agent
- sp_MSSubscription_Status – whether subscription has expired or the snapshot is ready
- sp_server_info- determines the collation
- sp_mshelp_subscriber_info – retrieve subscriber information
- sp_mshelp_subscription_agentid – determine the name of the distribution agent
- sp_Msadd_distribution_history – Initializing message – Msrepl_distribution_history
- sp_Msadd_distribution_history – Connecting to Subscriber – Msrepl_distribution_history
- so_datatype_info – to determine the data type mapping necessary to create the tracking table necessary for the Distribution agent
- sp_MScheck_subscribe on subscription database – verifies that SQL Server Agent account is in sysadmin and db_owner role in subscription database
- sp_mscreate_sub_tables on subscriber in subscription database – creates MSSusbcription_agents and MSreplication_subscriptions tables
- Sp_MSinit_Subscription_agent – updates the Subscription agent information on subscription database
- Retrieves transaction_timestamp and subscription_guid to determine what Distribution agent has already replicated to the Subscriber. Transaction_timestamp correlates to xact_seqno column in MSReplication_transactions table in distribution database. All values large than the xact_seqno will be replicated
- If we are doing initial sync, Distribution Agent calls sp_MSupdatelastsyncinfo which updates MSreplication_susbcriptions and MSSusbcription_agents table
- Starts to retrieve all transactions and their corresponding commands from MSReplication_transactions and MSreplication_commands table where transaction_timestamp column in subscription database < xact_seqno column in MSreplication_transactions table. Applies the transaction using sp_MS_get_repl_commands procedure
- Issues dynamic SQL to update the MSreplication_subscriptions table with the last delivered transaction ID
- sp_MSDistribution_history to write the MSrepl_distribution_history table with status message “nn transaction(S) with nn command(s) were delivered”
Tags: sp_replcmds
Hey there
Should the sp_MSget_last_transaction job be constantly running against the distributor database? I have a long running job (several hours) running the same sproc
Thanks
Stephen