How to add an article to an existing Transactional Subscription initialized through backup

Sakthivel Chidambaram
Microsoft SQL Server Support

There are situations where you initialize a Transactional subscription from a backup and later you need to add an article. If the publication was created using Snapshot Replication, you can re-run the Snapshot Agent and only the newly added article is BCP’ed out then BCP’ed in at the subscriber.  However when setting up the Subscriber using backup/restore there is no Snapshot agent.

There are two options when a new tables needs to be published.

1) Create a NEW publication for just that article.  Use Publication Wizard or script and select default options to push a new snapshot to the subscriber.  One LogReader will handle both publications, while separate Distribution Agents will move data in parallel to the subscriber.

2) Use the steps below to add the NEW article to an existing Publication and manually sync the data before restarting Replication.

Here are the steps for option 2):

1. Stop the log reader agent

2. Stop making changes to the new article in the Publisher (Note that table should be quiesced to all changes while the data is being copied out from the publisher and until the table is added to the publication with sp_addarticle)

3. Generate a script to create the table on the subscriber and copy the data out of the article from Publisher to Subscriber.

    A. For new or small tables you can use INSERT INTO… SELECT * FROM

    B. For tables with a lot of existing data, create a SSIS package that creates and then load the table on the remote server

4. Add the article to the publication using sp_addarticle

5. Start Log Reader Agent

6. Now you can start to make changes as the log reader will start tracking changes for the article at this point.

Please note that if the backup already had the article and if it is still present in the subscriber and provided there is no schema change is done to that table, you don’t need to create it again in the subscriber.

Also compare the row count of the table being added between publisher and subscriber before starting log reader agent to make sure that both publisher and subscriber have the same amount of data.

Related articles:

SQL BOL: How to: Initialize a Transactional Subscription from a Backup (Replication Transact-SQL Programming)

ReplTalk Blog: How to manually synchronize replication subscriptions by using backup or restore

ReplTalk Blog: Stored Procedure schema changes are not being replicated when using ”initialize with backup”

ReplTalk Blog: How to: Initialize a Transactional Subscription from a Backup with Multiple Backup Files

ReplTalk Blog: Deep Dive on Initialize from Backup for Transactional Replication

 

posted by Chris Skorlinski