Skip to content

Tag: Replication in SQL Server

SQL Server 1

SQL Server Replication Types and Components

SQL Server Replication is a technique of copying and distributing data and database objects from one database to another. It then synchronizes between databases to maintain the consistency and integrity of data.
In Replication data is synchronizing continuously or it can also schedule to run in fixed intervals.
There are multiple types of replication based on the several types of data synchronization they support.

1. Snapshot Replication
2. Transactional Replication
3. Merge Replication
4. Peer-to-peer Replication

Below are basic components of Replication

  1. Article
    An Article is the basic unit of Replication in SQL server. An article can be Table, View, Stored Procedure and function. We can create multiple articles on same object.

2. Publication
A publication is a logical collection of articles. It includes the article to be provided to subscriber. You can use below query to get more information on your publication.

EXEC sp_helppublications;

3. Publisher Database
The database holds a list of objects. These objects are designated as SQL Server replication articles and are known as a publication database.
The publisher can have one or more publications.
Each publisher defines a data propagation mechanism by creating several internal replication stored procedures.

4. Publisher
The publisher is the database instance which makes data available to other database instances using SQL server replication. The publisher can have multiple publications, each defines logical set of objects and data to replicate.

5. Distributor
The Distributor is the database that stores transactions from publisher and distributes those to subscriber. Sometimes Publisher instance also acts as distributor. However, in remote distributor scenario, Publisher and Distributor runs on different instances.
Basically, it collects data from Publisher and sends it to Subscriber.

6. Distribution databases
Distributor must have at least one Distribution database.
The Distribution database consists of article data, replication metadata, and data.
A remote Distributor can have multiple distribution databases. However, all publications defined on a single publisher must use the same distribution database.
To check details of Distribution database you can use below queries.

EXEC sp_helpdistributor;
EXEC sp_helpdistributiondb;
EXEC sp_helpdistpublisher;

7. Subscriber
Subscriber receives SQL server replication data from publisher. Subscriber can receive data from one or more publishers. The subscriber can pass the database changes back to the publisher. Alternatively, they can republish the data to other subscribers. This depends on the replication type and design.
To check details of subscriber you can use below query.

EXEC sp_helpsubscriberinfo;

8. Subscriptions
A subscription is request for a copy of a publication to be delivered to a subscriber. The subscription defines what publication data will be received, where and when.
There are two types of subscription

  1. Push Subscription – Distributor directly updates the data in the Subscriber database.
  2. Pull Subscription – the subscriber is scheduled to check at the distributor regularly. They determine if any new changes are available. Then, they update the data in the subscription database.

To check details of subscription you can use below query.

EXEC sp_helpsubscription;

9. Replication Agents
Replication uses a number of standalone programs. These programs are called agents. They carry out the tasks associated with tracking changes and distributing data. By default, replication agents run as jobs scheduled under SQL Server Agent. SQL Server Agent must be running for the jobs to run.
Replication agents can also be run from the command line and by applications that use Replication Management Objects(RMO).
Replication agents can be administered from SQL Server Replication Monitor and SQL Server Management Studio.

10. Snapshot Agent
The snapshot agent prepares the schema and initial data files of published tables and other objects. It takes a snapshot, stores the snapshot files, and records information about synchronization in the distribution database.
Snapshot Agent runs at distributor.
It is typically used in all types of replication.

11. Log Reader Agent
The Log Reader Agent is used with Transactional replication. It moves transactions from the transaction log on the Publisher to the distribution database.
Each database in transactional replication has its own Log Reader Agent. This agent runs on the Distributor. It connects to the Publisher.

12. Distribution Agent
The Distribution agent is used with Snapshot replication and transactional replication. It applies initial snapshot to the subscriber and moves transactions from the distribution database to subscribers.
For push subscriptions Distribution Agent runs at the Distributor.
For pull subscriptions Distribution Agent runs at the Subscriber.

13. Merge Agent
The Merge agent is used with merge replication. It applies the initial snapshot to the subscriber and reconciles the incremental data changes that occur at both ends.
By default, the Merge Agent uploads changes from the subscriber to the publisher. It then downloads the changes from the Publisher to the Subscriber.

Check all related articles