It is important to monitor all aspects of the replication process, from overseeing changes that are made to a publication to verifying the replicated changes on the Subscriber. SQL Server tools that are designed for this purpose are the most efficient means of monitoring replication, but it is also possible to use system stored procedures and to retrieve information from system tables.
After this lesson, you will be able to
- Monitor and troubleshoot Microsoft SQL Server 7 replication using tools, system stored procedures, and system tables
- Generate a replication script
Estimated lesson time: 60 minutes
SQL Server Replication Monitor is a component of SQL Server Enterprise Manager that is added to the console tree on the Distributor when the Distributor is enabled. It is designed for viewing the status of replication agents and for troubleshooting potential replication problems.
You can use SQL Server Replication Monitor to
NOTE
Although the Distribution and Merge Agents run on the Subscriber for pull subscriptions, the Replication Monitor is not available on the Subscriber. The status of the agents running on the Subscriber is monitored in the Replication Monitor running on the Distributor to which the Subscriber agents connect.
When you manage replication, you will need to address certain maintenance issues, including space management and backup strategies.
Space management requires that you
History tables and replicated transactions consume database storage space. Several replication agents clear these tables periodically. Ensure that the agents listed in the following table are running.
Miscellaneous agent | Description |
---|---|
Agent history clean up: distribution | Removes replication agent history records from the distribution database |
Distribution clean up: distribution | Removes replicated transactions from the distribution database |
Expired subscription clean up | Detects and removes inactive subscriptions from published databases |
Reinitialize subscriptions having data validation failures | Reinitializes (performs another initial synchronization of) all subscriptions that have failed due to data validation failure |
Replication agents checkup | Detects replication agents that are not actively logging history |
It is important to back up the distribution database, because if it is lost you must re-create all publications and subscriptions. By default, the trunc. log on chkpt. option is enabled when the distribution database is created. If you choose to perform transaction log backups on the distribution database, you must first disable this option. Plan and implement backup strategies by
Due to the large number of different possible replication configurations, detailed backup and restore strategies are not presented in this book. Books Online has matrixes that present strategies for each possible configuration.
A replication script provides many benefits, including the following:
To create replication scripts, select Tools/Replication/Generate Replication Scripts in SQL Server Enterprise Manager. Figure 17.1 shows the resulting dialog box. A script automatically has the name of the server that was used when replication was defined. To execute a script on another server, change server names in the script as appropriate.
Figure 17.1 The Generate SQL Scripts — Replication dialog box
In this exercise, you will generate a script, preview it, and then save it to disk.
You can use the Replication Monitor in SQL Server Enterprise Manager, Microsoft Windows NT Performance Monitor, and system stored procedures to monitor replication performance. You can obtain information on delivered transactions, undelivered transactions, rates of delivery, and latency.
Replication counters that graphically display replication details are useful for retrieving information about replication. You can use the counters described in this section in Windows NT Performance Monitor.
SQLServer:Replication Agents
The counter for the SQLServer:Replication Agents object has an instance for each type of replication agent.
Counter | Description |
---|---|
Running | The number of replication agents, of the specified type, currently running |
SQLServer:Replication Dist.
The SQLServer:Replication Dist. object has counters for monitoring instances of the Distribution Agent.
Counter | Description |
---|---|
Dist:Delivery Latency | The current amount of time, in milliseconds, that elapses between when transactions are delivered to the Distributor and when they are applied at the Subscriber |
Dist:Delivered Commands/sec | The number of commands per second delivered to the Subscriber |
Dist:Delivered Transactions/sec | The number of transactions per second delivered to the Subscriber |
SQLServer:Replication Logreader
The SQLServer:Replication Logreader object has counters for monitoring instances of the Log Reader Agent.
Counter | Description |
---|---|
Logreader:Delivery Latency | The current amount of time, in milliseconds, that elapses between when transactions are applied at the Publisher and when they are delivered to the Distributor |
Logreader:Delivered Commands/sec | The number of commands per second delivered to the Distributor |
Logreader:Delivered Transactions/sec | The number of transactions per second delivered to the Distributor |
SQLServer:Replication Merge
The SQLServer:Replication Merge object has counters for monitoring instances of the Merge Agent.
Counter | Description |
---|---|
Uploaded Changes/sec | The number of rows per second merged from the Subscriber to the Publisher |
Downloaded Changes/sec | The number of rows per second merged from the Publisher to the Subscriber |
Conflicts/sec | The number of conflicts per second occurring during the merge process |
SQLServer:Replication Snapshot
The SQLServer:Replication Snapshot object has counters for monitoring instances of the Snapshot Agent.
Counter | Description |
---|---|
Snapshot:Delivered Commands/sec | The number of commands per second delivered to the Distributor |
Snapshot:Delivered Transactions/sec | The number of transactions per second delivered to the Distributor |
You can retrieve information about replication using system stored procedures. This method allows you to reference replication information that may be used in triggers, user-defined stored procedures, or scripts. Some of these system stored procedures are listed in the following table.
To retrieve information on | Use |
---|---|
Servers | sp_helpserver sp_helpremotelogin |
Databases | sp_helpdb sp_helpdistributor sp_helppublication sp_helpsubscription sp_helpsubscriberinfo |
Replication activity | sp_replcmds sp_repltrans sp_replcounters |
History tables contain information for all replication agents. You should regularly view replication histories to identify any tasks that fail and the reasons for the failures. Message detail provides an indicator of the issues for example, connectivity problems, permission restrictions, and log-full errors.
Viewing Selected Replication Agent Histories
With the Agent History in SQL Server Replication Monitor, you can view replication information from the history tables for one or more sessions of a selected agent. Agent History allows you to filter the list of sessions to show
Using System Tables
The history tables in the distribution database track replication job activity for all replication agents. Instead of viewing the agent histories in the Replication Monitor, you can query the tables directly in the distribution database. These history tables (one for each agent) are
Many difficulties in replication processing involve connectivity and security. Before these can be addressed, you must determine which servers are involved in a replication problem by observing the processing order of the replication agents. Troubleshooting and resolution should focus on the access to each of the servers and to the databases that are involved in the replication scenario.
Several error logs can assist you in troubleshooting replication problems: SQL Server Error Log, SQL Server Agent Error Log, and Windows NT Event Viewer. You also can use SQL Server Profiler to troubleshoot replication.
Replication alerts are standard SQL Server alerts, configured to respond to conditions caused by the replication process. In SQL Server Enterprise Manager, you can configure all of the replication alerts under Alerts in SQL Server Agent or under Replication Alerts in the Replication Monitor. You must add new replication alerts under Replication Alerts in the Replication Monitor; otherwise they will show up only in SQL Server Agent. If you use the sp_add_alert system stored procedure to add a replication alert, you must specify the category 'Replication' with the @category_name argument if you want the new alert to be listed under Replication Alerts in the Replication Monitor.
A number of predefined replication alerts are created when you enable publishing and distribution. In order to use any of these alerts, you must enable it and add one or more operators to be notified when it fires. As for standard SQL Server Agent alerts, you can specify a job to be executed when the alert fires. The following predefined replication alerts are created for you:
Replication agents run under the user context of the SQLServerAgent service. If you have difficulty with the MSSQLServer service or the SQLServerAgent service, verify that
By default, SQL Server replication uses the same Windows NT domain user account that SQL Server Agent uses. If you experience a problem with connectivity, test the connectivity as follows:
If you cannot connect using either of these methods, the problem is with security rather than replication.
On Windows NT_based SQL Servers that need to replicate data from a Microsoft Windows 95_based or Windows 98_based SQL Server, use the SQL Server Client Network Utility to define an alias for the Windows 95 or Windows 98 server that uses the TCP/IP or Multiprotocol network library. This is necessary because Windows NT_based SQL Servers use the Named Pipes client network library by default, and Windows 95_based and Windows 98_based SQL Servers do not support incoming Named Pipes connections.
If replication is not occurring as expected, you may simply have to wait for the agents to start as scheduled, or you can manually start the agents to initiate the replication process.
Consider the following transactional replication scenario. After creating a publication and a subscription, the tables corresponding to the publication articles are not being created and populated on the Subscriber. You have checked the security and the connectivity between the Publisher, the Distributor, and the Subscriber, and they are working correctly.
The most likely cause for the replication not occurring in this case is that the initial synchronization has not taken place. This is probably because the Snapshot Agent has not run to generate the initial snapshot that the Distribution Agent needs in order to perform the initial synchronization. Depending on how the initial snapshot was scheduled when the publication was created, the initial snapshot may be created later or on demand. You need either to wait for the snapshot to be created or to start the Snapshot Agent for the publication manually before the initial synchronization will occur. After the initial synchronization is complete, regular transactional replication will begin.
In this exercise, you will modify the length of time that the Distributor retains transaction records in the distribution database. You will also modify the length of time that the Distributor retains replication performance history.
In this exercise, you will review the properties of the Miscellaneous Agents.
What is the function of this agent and how often does it run?
Answer
It is important to make backups of the distribution database if you are using replication because most of the replication configuration information is stored in the distribution database. SQL Server provides many tools for monitoring and checking replication. You can use the Replication Monitor in SQL Server Enterprise Manager, the Windows NT Performance Monitor, system stored procedures, agent histories, and replication alerts to monitor the status and performance of replication on your servers. Most problems with replication are caused by connectivity or security problems between the servers.