Transcript Ch12-short

SQL Server 2005
Implementation and
Maintenance
Chapter 12: Achieving High
Availability Through Replication
Introduction
• Use replication to copy data to
different locations in your
enterprise
• There are several reasons
– Move data closer to the users
– To reduce locking conflictsTo allow
site autonomy
– To remove the impact of readintensive operations
© Wiley Inc. 2006. All Rights Reserved.
Publisher/Subscriber
Metaphor
•
There are several key terms used in replication
– Publisher
• the source database where replication begins. It makes data available for
replication
– Subscriber
• the destination database where replication ends
– Distributor
• the intermediary between the publisher and subscriber. It receives published
transactions or snapshots and then stores and forwards these publications to
the subscribers
– Publication
• is the storage container for different articles. A subscriber can
• subscribe to an individual article or an entire publication.
– Article
• the data, transactions, or stored procedures that are stored within a
publication. This is the actual information that is going to be replicated.
– Two-phase commit
• is a form of replication
• in which modifications made to the publishing database are made at the
subscription
• database at the same time
© Wiley Inc. 2006. All Rights Reserved.
Articles
• An article is data in a table
• It can be the whole table or just a
subset
– Horizontal partitioning
• Rows are filtered out
– Vertical partitioning
• Columns are filtered out
© Wiley Inc. 2006. All Rights Reserved.
Publications
• A publication is a logical collection
of articles
• Subscribers subscribe to a
publication
– They do not need to read all of the
articles though
© Wiley Inc. 2006. All Rights Reserved.
Replication Factors
• Factors that affect replication are
– Autonomy
• Level of subscriber independence
– Will the replicated data be considered readonly? How long will the data at a subscriber be
valid? How often do you need to connect to the
distributor to download more data?
– Latency
• Frequency of data updates
– Transactional Consistency
• Do all the transactions that are stored need to
be applied at the same time and in order? What
happens if there is a delay in the processing?
© Wiley Inc. 2006. All Rights Reserved.
Using Transactional
Replication
• Transactions from the publisher
are stored on the distributor
• Subscribers receive and apply
transactions
– They should treat data as read-only
• Some latency and autonomy can
be introduced
• Subscribers do not need to be in
contact with publishers at all times
© Wiley Inc. 2006. All Rights Reserved.
Using Snapshot
Replication
• Moves an entire copy of the
published items
© Wiley Inc. 2006. All Rights Reserved.
Snapshot With Updating
Subscribers
• Initial replication works just like
snapshot replication
• Subscribers use 2PC to update
the publisher
• Publishers must approve
subscriber updates
© Wiley Inc. 2006. All Rights Reserved.
Using Merge Replication
• This allows subscribers to make
changes to their local data
• All changes are merged with all
other subscribers
– When all subscribers have the same
data, they are in convergence
© Wiley Inc. 2006. All Rights Reserved.
Using Queued Updating
• Used with transactional and
snapshot replication
• Allows subscribers to update
publishers
• Updates are queued, not
immediate
• There are other Restrictions
© Wiley Inc. 2006. All Rights Reserved.
Replication Internals
• There are two types of
subscriptions
• Push
– Configured and maintained at the
publisher
• Pull
– Configured and maintained at the
subscriber
© Wiley Inc. 2006. All Rights Reserved.
Publication Issues
• Timestamp datatype
– This is replicated as binary data in
transactional and snapshot
– Data is not replicated in merge
• Identity values
– You can assign a range of values to
replicate
• User-defined datatypes
– These must be created on each subscriber
• Not for replication
– Prevents objects from being replicated
© Wiley Inc. 2006. All Rights Reserved.
Publication Restrictions
• Replicated tables must have a primary key.
– Except in snapshot replication.
• Publications cannot span multiple databases.
• Varchar(max), nvarchar(max), and
varbinary(max) data is not replicated in
transactional or merge replication.
– Because of their size, these objects must be
refreshed by running a snapshot.
– Only the 16-byte pointer to their storage location
within the publishing database is replicated.
• You cannot replicate from the master, model,
MSDB, or tempdb databases.
© Wiley Inc. 2006. All Rights Reserved.
Distributor Issues
•
•
•
•
•
•
•
•
Ensure you have enough hard disk space for the Distribution
working folder and the distribution database.
Do not let the distribution database’s transaction log fill up.
The distribution database will store all transactions from the
publisher to the subscriber. It will also track when those
transactions were applied.
Snapshots and merge data are stored in the Distribution
working folder.
Be aware of the size and number of articles being published.
Text, ntext, and image datatypes are replicated only when
you use a snapshot.
A higher degree of latency can significantly increase your
storage space requirements.
Know how many transactions per synchronization cycle there
are.
© Wiley Inc. 2006. All Rights Reserved.
Replication Backup
• There are four possible strategies
– Publisher only
– Publisher and distributor
– Publisher and subscriber(s)
– Publisher, distributor and
subscriber(s)
© Wiley Inc. 2006. All Rights Reserved.
Replication Scripts
• Use scripts to track different versions
of your replication implementation.
• Use scripts to create additional
subscribers and publishers with the
same basic options.
• You can quickly customize your
environment by modifying the script
and then rerunning it.
• Use scripts as part of your database
recovery process.
© Wiley Inc. 2006. All Rights Reserved.