Lecture 7 Data Replication
Department of Computer Science, Kardan University
Data Replication in SQL Server 2012
Lect-7
Prepared by
Bilal Khan
Lecture 7 Data Replication
2
 The word replication comes from the Latin word
replicare, which means to repeat.
 Replication describes the process of reproducing or
duplicating
 Storing a separate copy of database at each of two or
three or more sites
Lecture 7 Data Replication
3
 Replication in SQL Server does exactly that; it
reproduces or duplicates data.
 That copy can exist in the same database as the source
data, in a different database on the same instance, or in
a database on a separate instance or server.

Lecture 7 Data Replication
4
 SQL Server replication is about more than just copying
data.
 In SQL Server replication is to continuously
synchronize the source data with the copied data or set
it up to synchronize the data at scheduled intervals.
 Plus, replication supports both one-way and bi-
directional synchronization.
Lecture 7 Data Replication
5
 Reliability.
 Fast response.
 May avoid complicated distributed transaction integrity
routines (if replicated data is refreshed at scheduled
intervals.)
 De-couples nodes (transactions proceed even if some
nodes are down.)
 Reduced network traffic at prime time (if updates can
be delayed.)
Lecture 7 Data Replication
6
 Additional requirements for storage space.
 Additional time for update operations.
 Complexity and cost of updating.
 Integrity exposure of getting incorrect data if replicated
data is not updated simultaneously.
 Therefore, better when used for non-volatile data.
Lecture 7 Data Replication
7
 Replication requires a number of components to work
properly.
Lecture 7 Data Replication
8
 Artical
 The objects that are replicated like tables, views, and
stored procedures are called articals.
dbo.tbl_3 and
dbo.tbl_4 are
two articles
Lecture 7 Data Replication
9
 Artical
 An article's properties determine whether that article
contains the entire object or a part of object.
 Multiple articles can be created on a single object.
Lecture 7 Data Replication
10
 Publication
 A Publication is group of related data and objects that
we want to replicate together.
 A publication is a collection of articles grouped
together as one unit.
 Every article is defined to be part of exactly one
publication. However, you can define different articles
on the same object in separate publications.
Lecture 7 Data Replication
11
 Publisher
 A Publisher is a server that is the source of data to be
replicated.
 The Publisher is the SQL Server instance that makes a
publication available for replication;
 Publisher itself doesn't actually have an active role in a
replication setup. After the publication is defined, the
Distributor and sometimes the Subscriber do all the
heavy lifting.
Lecture 7 Data Replication
12
 Subscriber
 There are two types of subscriptions:
 Push subscriptions
 The Distributor directly updates the data in the Subscriber
database.
 Pull subscriptions
 The Subscriber asks the Distributor regularly if any new
changes are available, and then updates the data in the
subscription database itself.
Lecture 7 Data Replication
13
 Subscriber
 A database that is the target of a replication
subscription is called a subscription database.
Lecture 7 Data Replication
14
 Subscriber
 A Subscriber is a server that receives the data replicated by
the publisher.
 The Subscriber defines a subscription to a particular
publication.
 Each subscription creates a link, between one publication
and one Subscriber.

Lecture 7 Data Replication
15
 Distributor
 A Distributor is a server that performs various tasks
when moving articles from Publishers to Subscribers.
 The actual tasks performed depend on the type of
replication performed.
Lecture 7 Data Replication
16
 Distributor
 Each Publisher is linked to a single Distributor.
 The Distributor identifies changes to the articles on each of its
Publishers.
 The Distributor notify the Subscribers that an article has
changed.
 The information about changes are stored in the distribution
database until all Subscribers have been notified or the retention
period has expired.
Lecture 7 Data Replication
17
 Replication agents
 Agents are the software components used in
replication.
 The replication processes are executed by a set of
replication agents.
Lecture 7 Data Replication
18
 Snapshot Agent
 Log Reader Agent
 Distribution Agent
Lecture 7 Data Replication
19
 Snapshot Agent
 Snapshot is a state of any thing at a particular moments.
 Snapshot Agent run at least one for any types of
Replication.
 The Snapshot Agent provides the data required to
perform the initial synchronization of the publication
database with the subscription database.
Lecture 7 Data Replication
20
 Log Reader Agent
 The Log Reader Agent reads the transaction log of the
publication database.
 If it finds changes to the published objects, it records
those changes to the distribution database.
Lecture 7 Data Replication
21
 Distribution Agent
 Distribution Agent It performs different activities,
mainly distributes publication to subscribers.
 The Distribution Agent applies the changes recorded in
the distribution database to the subscription database.
Only transactional replication uses the Distribution
Agent.
Lecture 7 Data Replication
22
Central Publisher / Distributor
Publ/Dist Sever
Lecture 7 Data Replication
23
Publisher / Remote Distributor
Publisher
Remote
Distr
Lecture 7 Data Replication
24
 Snapshot Replication
 Transaction Replication.
 Merge Replication
Lecture 7 Data Replication
25
 Snapshot Replication
 Snapshot replication creates an identical copy of the
replicated objects and their data each time it runs.
 It always copy the entire dataset again and applied to
the target database.
Lecture 7 Data Replication
26
 Snapshot Replication
 All other replication types use Snapshot Replication in
first step, by default, a single replication snapshot to
sync the Publisher to its Subscribers.
 Can be push or pull
Lecture 7 Data Replication
27
 Transaction Replication
 Transactional replication copies data uni-directionally
from the source database to the target database.
 This replication type uses the log files associated with
the source database to keep data in sync. If a change is
made to the source database, that change can be
immediately synced to the target database, or the
synchronization can be scheduled.
Lecture 7 Data Replication
28
 Transaction Replication
 Transactional replication, however, is sensitive to
changes to the target database. Any change can break
replication so, the target database should be considered
read-only.
 You can modify objects in the target database that are
not part of the replication setup.
Lecture 7 Data Replication
29
 Transaction Replication
 Transactional replication works on a transaction basis.
 The Log Reader Agent scans the transaction log of the
publication database and examines each committed
transaction to determine whether any changes affect the
replicated articles. If they do, those changes are logged to
the distribution database.
 The Distribution Agent then replicates those changes to the
Subscriber.
Lecture 7 Data Replication
30
 Merge Replication
 Merge replication allows two or more databases to be
kept in sync. Any change applied to one database will
automatically be applied to the other databases – and
vice versa.
Lecture 7 Data Replication
31
 Merge Replication
 Merge replication allow data changes on the Publisher
as well as the Subscriber,
 Merge replication also allows for disconnected
scenarios.
◦ For example, if a Subscriber is disconnected from a Publisher
during part of the day, the Subscriber and Publisher are
synchronized when they are reconnected.
Lecture 7 Data Replication
32
Have a Nice Day
2/4/2016

Lect 07 data replication

  • 1.
    Lecture 7 DataReplication Department of Computer Science, Kardan University Data Replication in SQL Server 2012 Lect-7 Prepared by Bilal Khan
  • 2.
    Lecture 7 DataReplication 2  The word replication comes from the Latin word replicare, which means to repeat.  Replication describes the process of reproducing or duplicating  Storing a separate copy of database at each of two or three or more sites
  • 3.
    Lecture 7 DataReplication 3  Replication in SQL Server does exactly that; it reproduces or duplicates data.  That copy can exist in the same database as the source data, in a different database on the same instance, or in a database on a separate instance or server. 
  • 4.
    Lecture 7 DataReplication 4  SQL Server replication is about more than just copying data.  In SQL Server replication is to continuously synchronize the source data with the copied data or set it up to synchronize the data at scheduled intervals.  Plus, replication supports both one-way and bi- directional synchronization.
  • 5.
    Lecture 7 DataReplication 5  Reliability.  Fast response.  May avoid complicated distributed transaction integrity routines (if replicated data is refreshed at scheduled intervals.)  De-couples nodes (transactions proceed even if some nodes are down.)  Reduced network traffic at prime time (if updates can be delayed.)
  • 6.
    Lecture 7 DataReplication 6  Additional requirements for storage space.  Additional time for update operations.  Complexity and cost of updating.  Integrity exposure of getting incorrect data if replicated data is not updated simultaneously.  Therefore, better when used for non-volatile data.
  • 7.
    Lecture 7 DataReplication 7  Replication requires a number of components to work properly.
  • 8.
    Lecture 7 DataReplication 8  Artical  The objects that are replicated like tables, views, and stored procedures are called articals. dbo.tbl_3 and dbo.tbl_4 are two articles
  • 9.
    Lecture 7 DataReplication 9  Artical  An article's properties determine whether that article contains the entire object or a part of object.  Multiple articles can be created on a single object.
  • 10.
    Lecture 7 DataReplication 10  Publication  A Publication is group of related data and objects that we want to replicate together.  A publication is a collection of articles grouped together as one unit.  Every article is defined to be part of exactly one publication. However, you can define different articles on the same object in separate publications.
  • 11.
    Lecture 7 DataReplication 11  Publisher  A Publisher is a server that is the source of data to be replicated.  The Publisher is the SQL Server instance that makes a publication available for replication;  Publisher itself doesn't actually have an active role in a replication setup. After the publication is defined, the Distributor and sometimes the Subscriber do all the heavy lifting.
  • 12.
    Lecture 7 DataReplication 12  Subscriber  There are two types of subscriptions:  Push subscriptions  The Distributor directly updates the data in the Subscriber database.  Pull subscriptions  The Subscriber asks the Distributor regularly if any new changes are available, and then updates the data in the subscription database itself.
  • 13.
    Lecture 7 DataReplication 13  Subscriber  A database that is the target of a replication subscription is called a subscription database.
  • 14.
    Lecture 7 DataReplication 14  Subscriber  A Subscriber is a server that receives the data replicated by the publisher.  The Subscriber defines a subscription to a particular publication.  Each subscription creates a link, between one publication and one Subscriber. 
  • 15.
    Lecture 7 DataReplication 15  Distributor  A Distributor is a server that performs various tasks when moving articles from Publishers to Subscribers.  The actual tasks performed depend on the type of replication performed.
  • 16.
    Lecture 7 DataReplication 16  Distributor  Each Publisher is linked to a single Distributor.  The Distributor identifies changes to the articles on each of its Publishers.  The Distributor notify the Subscribers that an article has changed.  The information about changes are stored in the distribution database until all Subscribers have been notified or the retention period has expired.
  • 17.
    Lecture 7 DataReplication 17  Replication agents  Agents are the software components used in replication.  The replication processes are executed by a set of replication agents.
  • 18.
    Lecture 7 DataReplication 18  Snapshot Agent  Log Reader Agent  Distribution Agent
  • 19.
    Lecture 7 DataReplication 19  Snapshot Agent  Snapshot is a state of any thing at a particular moments.  Snapshot Agent run at least one for any types of Replication.  The Snapshot Agent provides the data required to perform the initial synchronization of the publication database with the subscription database.
  • 20.
    Lecture 7 DataReplication 20  Log Reader Agent  The Log Reader Agent reads the transaction log of the publication database.  If it finds changes to the published objects, it records those changes to the distribution database.
  • 21.
    Lecture 7 DataReplication 21  Distribution Agent  Distribution Agent It performs different activities, mainly distributes publication to subscribers.  The Distribution Agent applies the changes recorded in the distribution database to the subscription database. Only transactional replication uses the Distribution Agent.
  • 22.
    Lecture 7 DataReplication 22 Central Publisher / Distributor Publ/Dist Sever
  • 23.
    Lecture 7 DataReplication 23 Publisher / Remote Distributor Publisher Remote Distr
  • 24.
    Lecture 7 DataReplication 24  Snapshot Replication  Transaction Replication.  Merge Replication
  • 25.
    Lecture 7 DataReplication 25  Snapshot Replication  Snapshot replication creates an identical copy of the replicated objects and their data each time it runs.  It always copy the entire dataset again and applied to the target database.
  • 26.
    Lecture 7 DataReplication 26  Snapshot Replication  All other replication types use Snapshot Replication in first step, by default, a single replication snapshot to sync the Publisher to its Subscribers.  Can be push or pull
  • 27.
    Lecture 7 DataReplication 27  Transaction Replication  Transactional replication copies data uni-directionally from the source database to the target database.  This replication type uses the log files associated with the source database to keep data in sync. If a change is made to the source database, that change can be immediately synced to the target database, or the synchronization can be scheduled.
  • 28.
    Lecture 7 DataReplication 28  Transaction Replication  Transactional replication, however, is sensitive to changes to the target database. Any change can break replication so, the target database should be considered read-only.  You can modify objects in the target database that are not part of the replication setup.
  • 29.
    Lecture 7 DataReplication 29  Transaction Replication  Transactional replication works on a transaction basis.  The Log Reader Agent scans the transaction log of the publication database and examines each committed transaction to determine whether any changes affect the replicated articles. If they do, those changes are logged to the distribution database.  The Distribution Agent then replicates those changes to the Subscriber.
  • 30.
    Lecture 7 DataReplication 30  Merge Replication  Merge replication allows two or more databases to be kept in sync. Any change applied to one database will automatically be applied to the other databases – and vice versa.
  • 31.
    Lecture 7 DataReplication 31  Merge Replication  Merge replication allow data changes on the Publisher as well as the Subscriber,  Merge replication also allows for disconnected scenarios. ◦ For example, if a Subscriber is disconnected from a Publisher during part of the day, the Subscriber and Publisher are synchronized when they are reconnected.
  • 32.
    Lecture 7 DataReplication 32 Have a Nice Day 2/4/2016

Editor's Notes

  • #11 Few objects are collected and considered as publication like few relations or may be few attributes of relation.
  • #12 The server where we define the publications is called publisher.
  • #13 The server where we have to replicate our publish data
  • #14 The server where we have to replicate our publish data
  • #15 The server where we have to replicate our publish data
  • #17 The Distributor is a SQL Server instance
  • #19 Snapshot is a state of any thing at a particular moments
  • #20 Snapshot Agent take the snapshot of publication. It works by copying all the data every time from the publication database to the subscription databas
  • #21 Only transactional replication uses the Log Reader Agent.
  • #22 Take publication from publisher and distribute and place to subscribers. only transactional replication uses the Distribution Agent.