SQL Server Replication
SQL Server Replication
Intro:
Earlier, most of the applications were using standalone environment where a single centralized server
was responding to multiple users, working in different locations.
Problems:
Performance
Availability
Maintenance
Advantages:
Replication Entities:
1. Publisher
2. Article
3. Publication
4. Distributor
5. Subscriber
6. Subscription
7. Push Subscription
8. Pull Subscription
1.Publisher:
2.Article:
Actual database objects included in replication like tables, views, indexes, etc.
It can be filtered when sent to subscriber.
3.Publication:
4.Distributor:
Replication Architecture:
5.Subscriber:
6.Subscription:
Push Subscription:
With this subscription, the publisher is responsible for updating all the changes to the
subscriber without the subscriber asking those changes.
Push subscriptions are created at the Publisher server.
Pull Subscription:
With this subscription the subscriber initiates the replication instead of the publisher.
The subscriptions are created at the Subscriber server.
Replication Agents:
Replication process works in the background with the help of jobs. These jobs are called
Agents.
These jobs internally uses respective .exe files present in …………….. \110\COM folder.
All the agents information is present in Distribution db in the following tables.
o dbo.MSxxx_agents
o dbo.MSxxx_history
Snapshot Agent:
It is an executable file that prepares snapshot files containing schema and data of published
tables and db objects
It stores the files in the snapshot folder, and records synchronization jobs in the distribution
database
Distribution Agent:
It is used with snapshot and transactional replication
It applies the initial snapshot to the Subscriber and moves transactions held in the Distribution
db to Subscribers.
It runs at either the Distributor for push subscriptions or at the Subscriber for pull subscriptions
Log Reader Agent:
It is used with transactional replication, which moves transactions marked for replication from
the transaction log on the publisher to the distribution db.
Each db has its own Log Reader Agent that runs on the Distributor and connects to the
Publisher.
Merge Agent:
It is used with merge replication.
It applies the initial snapshot to the Subscriber and moves incremental data changes that occur.
Each merge subscription has its own Merge Agent that connects to both the Publisher and the
Subscriber and updates both.
It captures changes using triggers.
Queue Reader Agent:
It is used with transactional replication with the queued updating option.
It runs at the Distributor and moves changes made at the Subscriber back to the Publisher.
Unlike Distribution Agent and Merge Agent, only one instance of the Queue Reader Agent
exists to service all Publishers and publications for a given distribution db.
REPLICATION TYPES:
Snapshot
Transactional
Merge
1.Snapshot Replication:
Used to provide initial data set for transactional and merge replication.
Copies and distribute data and database objects exactly as they appear at the current
moment of time.
Note: The initial data set is typically a snapshot that is created by the Snapshot agent and
distributed and applied by the Distribution agent.
2.Transactional replication:
Used in Server-to-server scenarios that require high throughput including improving
scalability & availability, integration of data from multiple sites, integrating heterogenous
data, data warehousing and reporting and offloading batch processing.
3.Merge replication:
Primarily designed for mobile applications or distributed server applications that have
possible data conflicts.
Common scenarios include: exchanging data with mobile users, consumer point-of-scale
(POS) applications and integration of data from multiple sites.