In SQL Server Management Studio, locate the Replication node under the publica-tion server the DBARCH-LT2\SQL08DE01 named instance in this example or the Replication node under the subsc
Trang 1594 CHAPTER 19 Replication
FIGURE 19.45 Specifying a join filter on the SalesOrderHeader table (limiting the sales
rows that will be published by joining for the North East customers only)
Join filtering allows you to limit the rows you will publish, via join criteria, to another table
Figure 19.45 shows a complex join that filters SalesOrderHeader rows that correspond to
North East Territory customers only (that is, those with TerritoryID values of 1 or 2)
Creating Subscriptions
Now that you have installed and configured the distributor, enabled publishing, and
created a publication, you can create subscriptions
Remember that two types of subscriptions can be created: push or pull Pull subscriptions
allow remote sites to subscribe to any publication that they are allowed to, but for this to
work, you must be confident that the administrators at the other sites have properly
configured the subscriptions at their sites Push subscriptions are easier to create because
all the subscription processes are performed and administered from the
publication/distrib-utor point of view This also makes using them the most common approach
For this example, we use the New Subscription Wizard to create a push subscription:
1 In SQL Server Management Studio, locate the Replication node under the
publica-tion server (the DBARCH-LT2\SQL08DE01 named instance in this example) or the
Replication node under the subscription server (the DBARCH-LT2\SQL08DE03 named
instance in this example) You can create a push subscription from either (but we use
the subscription server here) Open the Replication node, navigate to the Local
Subscription branch, right-click, and choose the New Subscriptions option As you
can see in Figure 19.46, choosing this option launches the New Subscription Wizard,
Trang 2FIGURE 19.46 Launching the New Subscription Wizard from SQL Server Management Studio
FIGURE 19.47 Identifying the publication from which to subscribe
2 You first need to identify the publisher and publication from which you want to
create one or more subscriptions As you can see in Figure 19.47, we have specified
the publisher (DBARCH-LT2\SQL08DE01) and the publication that has been created for
the AdventureWorks2008 database
Trang 3596 CHAPTER 19 Replication
FIGURE 19.48 Run all agents at the Distributor (push subscriptions)
3 When you are presented with the option of where the replication agents will be run
for the subscription, choose the first option—having the agents run at the distributor
This makes it a push subscription, which is much easier to control and manage
centrally than a pull subscription (as shown in Figure 19.48)
4 Next, the New Database dialog appears, asking you to identify the database target for
the subscription and the physical database files for its allocation (assuming that you
want to create this from scratch using this wizard process) Figure 19.49 shows this
New Database dialog, with the target database named AdventureWorks2008ODS
Essentially, we have decided to create a subscription that will continuously flow data
from the publisher to the subscriber for all tables in the publication This continuous
replication at the transactional level effectively creates a mirror image of the data for
operational usage That’s why we have used the suffix ODS, for Operational Data
Store, for the new database This is a typical industry usage of replication that takes
all read-only access to OLTP data and offloads it to the ODS copy of the same data
(which is as close to up-to-date as the last transaction that was replicated to it)
5 In the Subscribers screen, with the new entry for the target subscriber server (the
DBARCH-LT2\SQL08DE03 named instance in this example), check the box for the
target subscription server Figure 19.50 shows this subscriber server and the
subscrip-tion database target
6 Specify the process account and connection options for the distribution agent (to
connect to the subscription server) Typically, you choose the option to use a domain
account or choose to impersonate the process account (shown in Figure 19.51)
7 Specify the synchronization schedule for each agent You want the distribution agent
to run continuously, but you also have the options to run on a schedule and on
Trang 4FIGURE 19.49 The New Database dialog specifying the target database
(AdventureWorks2008ODS)
FIGURE 19.50 Specifying the subscription server target database
Trang 5598 CHAPTER 19 Replication
FIGURE 19.51 Distribution Agent Security and Synchronization Schedule for the subscription
(Run Continuously)
8 Specify the initialization of the subscription You want the subscription to be
initial-ized immediately, but, depending on the size of the database, this might be
accom-plished manually with a database backup of the publication database
9 On the next screen, which lists the New Subscription Wizard actions, choose to
create the subscription and generate a script file with all the steps to create the
subscription for use later
10 On the next wizard dialog, identify the location of the script to be generated As
shown in Figure 19.52, you are presented with the final wizard summary screen
Click Finish to create your subscription, initialize the subscription database, and
enjoy a full transactional replication implementation
After you click Finish, the create subscription process starts and goes through each
step Remember to check for errors or warnings if any errors occur When this
process completes, you wait for the agents to initialize the target database and start
replication to the subscriber If you have specified that the schema and data be
created immediately, things start happening quickly The distribution agent finishes
the job As you can see in Figure 19.53, the distribution agent applies the schemas to
the subscriber (as viewed from the Replication Monitor’s Distributor to Subscriber
Trang 6FIGURE 19.52 The New Subscription Wizard summary
FIGURE 19.53 Delivering schemas and data to the subscriber
Trang 7600 CHAPTER 19 Replication
FIGURE 19.54 Transactions replicating to the subscriber (pushed)
The complete replication buildup is finished, and you should be fully functional for
repli-cating transactions to the subscriber
Figure 19.54 shows what the replication buildup looks like from the Replication Monitor
as transactions flow through the replication topology This screenshot shows the
transac-tion counts and commands being delivered on the last leg in the journey (from the
distributor to a subscriber) Figure 19.55 shows the full replication topology that was built
(Publisher, Distributor and Subscriber)
Your replication topology is now completely functional and will replicate flawlessly for as
long as you require
Scripting Replication
Earlier, it was strongly suggested that you generate SQL scripts for all that you do because
going through wizards every time you have to configure replication is a difficult way to
run a production environment In the example in the preceding section, you always chose
to generate these scripts as you built up the replication configuration This was only half
the scripts needed, however You must also generate the breakdown scripts (that is, those
that drop and remove replication components) to remove each component of the
replica-tion topology in case you need to start from scratch or, as an example, rebuild a subscriber
that is completely nonfunctional As you can see in Figure 19.56, SQL Server Management
Studio has a great feature that allows the complete generation of all aspects of replication
topology (including disabling and removing replication)
Trang 8FIGURE 19.55 Full replication topology that was built (Publisher, Distributor, Subscriber)
FIGURE 19.56 A script-generation feature for all replication topology components
NOTE
Remember that working from scripts minimizes the errors you make while supporting
your data replication environments (especially at 3:00 a.m.)
Trang 9602 CHAPTER 19 Replication
The following example shows the SQL scripts needed to generate the part of the data
repli-cation configuration you just built with the wizard:
From distribution Server
-/****** Scripting replication configuration Script Date: 6/30/2009 10:49:03 AM
******/
/****** Please Note: For security reasons, all password parameters were scripted
with either NULL or an empty string ******/
/****** Begin: Script to be run at Distributor ******/
/****** Installing the server as a Distributor Script Date: 6/30/2009 10:49:03 AM
******/
use master
exec sp_adddistributor @distributor = N’DBARCH-LT2\SQL08DE02’, @password = N’’
GO
Adding the agent profiles
Updating the agent profile defaults
exec sp_MSupdate_agenttype_default @profile_id = 1
GO
exec sp_MSupdate_agenttype_default @profile_id = 2
GO
exec sp_MSupdate_agenttype_default @profile_id = 4
GO
exec sp_MSupdate_agenttype_default @profile_id = 6
GO
exec sp_MSupdate_agenttype_default @profile_id = 11
GO
Adding the distribution databases
use master
exec sp_adddistributiondb @database = N’distribution’, @data_folder = N’C:\
Program Files\Microsoft SQL Server\MSSQL10.SQL08DE02\MSSQL\Data’, @data_file =
N’distribution.MDF’, @data_file_size = 6, @log_folder = N’C:\Program Files\
Microsoft SQL Server\MSSQL10.SQL08DE02\MSSQL\Data’, @log_file =
N’distribution.LDF’, @log_file_size = 3, @min_distretention = 0,
@max_distretention = 72, @history_retention = 48, @security_mode = 1
GO
Adding the distribution publishers
Trang 10@thirdparty_flag = 0, @publisher_type = N’MSSQLSERVER’
GO
/****** End: Script to be run at Distributor ******/
use master
GO
The complete set of buildup and breakdown scripts for the example used here are available
on this book’s CD They are labeled CreatingXXX.sql for the buildup scripts and
RemoveXXX.sql for the breakdown scripts
Monitoring Replication
After replication is up and running, it is important for you to monitor it and see how
things are running You can do this in several ways, including using SQL statements, SQL
Server Management Studio, and Windows Performance Monitor You are interested in the
agent’s successes and failures, the speed at which replication is done, and the
synchroniza-tion state of tables involved in replicasynchroniza-tion Other issues to watch for are the sizes of the
distribution database, growth of the subscriber databases, and available space on the
distri-bution server’s snapshot working directory
Replication Monitoring SQL Statements
One way to look at the replication configuration and validate row counts, for example, is
to use various replication stored procedures, including the following:
sp_helppublication—Information on the publication server
sp_helparticle—Article definition information
sp_helpdistributor—Distributor information
sp_helpsubscriberinfo—Subscriber server information
sp_helpsubscription—Subscription information
These stored procedures are all extremely useful for verifying exactly how the replication
configuration is really configured If you execute these stored procedures (from the
publi-cation database), you get a great documentation of your complete replipubli-cation topology
that can be included in run books or other system documentation Here’s what you might
do to see how the current replication configuration has been built out:
use AdventureWorks2008
go
exec sp_helppublication
exec sp_helparticle @publication=’PUBLISH AdventureWorks2008 - Transactional’
exec sp_helpdistributor
exec sp_helpsubscriberinfo
exec sp_helpsubscription
go