Replicación SQL
Replicación SQL
will now become the principal. After the former principal database
comes online again, executing a manual failover will resync the
databases and swap the roles back.
Implement Replication
Replication is one of the oldest data distribution techniques supported
by SQL Server. The purpose of replication is to copy data or transac-
tions from one server to another. While this can be a very effective dis-
tribution technique, there is no support for failover or transparent client
redirection, so it is a marginal availability solution in most cases. Repli-
cation can still be an excellent data distribution technique, however.
Data Administration
should be familiar. We will assume that these terms are understood for
the remainder of this chapter:
Push subscription A subscription model in which the distributor
services push data to the subscriber. SQL Agent jobs running on the
distributor will periodically connect to the subscriber and execute
transactions necessary to bring the subscriber current.
PART III
Pull subscription With a pull subscription model, the subscriber
services retrieve transactions from the distributor for execution to
keep the subscriber current. Pull subscriptions allow some of the
overhead of replication to move from the distributor to the sub-
scriber, which may load-balance the model better.
Article An individual collection of replicated data usually associ-
ated with a table. Creating an article from a table allows the adminis-
trator to filter out columns or rows that they wish to exclude from the
replication scenario.
Publication A collection of articles usually associated with a data-
base. A subscriber can subscribe to either an individual article or
the entire publication.
288 Chapter 8
Implementing Availability and Replication
In addition to these server roles and the replication types previously dis-
cussed, it is also possible to combine these components in different ways to
create various replication topologies. A topology is a collection of replica-
tion services that are combined in a specific way to accomplish a desired
goal. Some of the more prominent topology patterns are listed here:
Central subscriber It is possible to have multiple publishers replicate
data to a single subscriber. The data for each publisher article may
even be published to the same table in the subscriber as long as each
publisher’s data is distinct. This pattern, illustrated in Figure 8.18, is
most common where there is a centralized data need for reporting or
decision making.
Publisher A
Subscriber
Table
Publisher B
Publisher C
Central publisher You can also configure a single publisher that can
partition data to various subscribers. Assuming that each subscriber
needs only a subset of the data, the administrator can create multiple
articles, each one filtering out data for a particular subscriber. Each
subscriber can then receive the data that’s relevant for them. This
approach, pictured in Figure 8.19, is useful when data is centrally col-
lected but must be distributed locally for decentralized processing.
Subscriber C
Article
C
Implement Replication 289
Publisher/ Publisher/
Subscriber A Subscriber B
Publish
Article A
Publish
Article B
Data Administration
will replicate to a single subscriber that has more convenient
access to the ultimate subscribers. The subscriber then republishes
the data to the subscribers that need it. In this model, pictured in
Figure 8.21, the central server is responsible for both subscription
and publication services.
PART III
Figure 8.21: Distributed subscriber/republisher
Subscriber A
Publisher Pub/Sub
Table Table
Subscriber C
Subscriber C
290 Chapter 8
Implementing Availability and Replication
Of course, there are other patterns that you can use, and almost
limitless combinations of these patterns, so be creative. Just be sure to
do production-level performance and reliability testing on your models
before taking them live. What looks good on paper will not always work
so well in the real world.
Data Administration
PART III
5. The screen that now appears will provide the configuration of this
database, specifically the database name and file locations. The
default name is distribution, which we will retain for this example
292 Chapter 8
Implementing Availability and Replication
Data Administration
10. Review the page for accuracy and click Finish when you’re ready
to execute the configuration. When the replication is complete,
click Close.
act as its own distributor, you can configure the distributor now.
In this example, however, you will point to the distributor that
we configured in the previous step. Click the second option in the
dialog to enable the Add button.
3. Click the Add button and connect to the server previously config-
ured as the distributor. Then click Next to advance.
4. Provide the distributor password that you specified when you
configured the distributor. (You will not be able to make an adminis-
trative link to the distributor without this resource password.) After
providing the password click Next to advance. (This simple page
contains only the password prompt and is not pictured here.)
5. Select the database that you wish to publish from the list of
databases that are eligible for publication. In this case, only the
pubs database is on the list. Data from multiple databases will be
published as multiple publications. Click Next to continue.
6. You will now see the page illustrated in Figure 8.26, which lists all
publication types previously discussed. Refer to the introductory
section of this chapter if you need a refresher on replication types.
NOTE We wish that we had the time and space to cover all of
the replication models more exhaustively, but that is unfortu-
nately not possible. The good news, though, is that this informa-
tion should be enough to get you going and the replication
process is very well documented in the SQL Server Books Online
when you are ready to dive deeper. Again, don’t be afraid to
experiment with the options and be sure to do some testing
before you pull the trigger in production.
Now it is finally time to decide what you are going to publish. You
can publish tables, views, and stored procedures as articles. If you
publish a table, it must have a primary key.
Data Administration
8. On the right side of the dialog pictured in Figure 8.27, you will see
a button with two options, one to set properties for the selected
article and one for all articles. Review these properties carefully
on your own. You will control much of the replication behavior
here, including copying related artifacts, doing type conversions,
and other useful options. In our example, we will replicate only a
limited number of columns in the authors table. Select the check PART III
boxes for the authors table as shown and click Next to advance.
9. The next step is to select articles to filter. The previous dialog
allowed you to filter out any columns that you did not need. The
next dialog provides the ability to do row filtering based on criteria
that you provide. Figure 8.28 illustrates a completed dialog. To add
filtering for an article, click the Add button on the right, which will
be enabled if there are any articles remaining that do not have
filters. This will open the dialog pictured in Figure 8.29, where you
will provide a 7(%2% clause for the filter statement to indicate which
data you want to include in the article. In our example, we are only
publishing authors that live in the state of California. Click Next on
the dialog to advance.
296 Chapter 8
Implementing Availability and Replication
Data Administration
snapshot on the subscriber. The log reader agent is responsible for
retrieving transactions from the publishing log. You should use
domain accounts with necessary permissions for these agents.
This is pictured in Figure 8.30. Click Next to advance.
Data Administration
Figure 8.32 : Selecting subscribers and databases
PART III
300 Chapter 8
Implementing Availability and Replication
Figure 8.33 shows these options. Select Run Continuously for this
example. Click Next to continue.
9. The next dialog is similar except that it allows you to specify how
the subscription will be initialized, either immediately or on the
first sync task. If you choose to wait for the first sync task, you will
Implement Replication 301
not see any data in the article until a database modification occurs
on the publisher and that transaction replicates to the subscriber.
Choose to initialize immediately. This is a simple dialog and is not
pictured here.
10. You are almost done. Click Next and choose the option to create
the subscription immediately or generate a script.
11. Click next to review the summary page, and then click Finish to
complete the wizard.
Once the wizard reports that you have successfully created the sub-
scription, you can go back to the Object Explorer. You will now see a
table in the target database with the same name as the article that you
created, in this case authors. Since we configured this to initialize imme-
diately, you should be able to select from the table and see the initial
snapshot of data.
Additionally, if you make a modification to the published data on
the publishing server, you will be able to select from the subscription
table and see the change. Do a couple of experiments with your data-
bases and see how long it takes for the subscriptions to update.
Data Administration
PART III