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

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

Comments (5)

  1. nicoCn says:

    Hi Microsoft SQL Server Support

    I added an article to an existing Transactional Subscription initialized through backup use this post,but i found the logreader always execute sp_repldone the last lsn after logreader started , so ,lost many transactions . why ?

  2. susheel says:

    I have tried adding a new article using this post, but stored procedure that are responsible to propogate commands to subscription are not getting created. SP_MSIns, SP_MSDel, SP_MSUpd etc.,. Please let me know how to solve this.

  3. Daniel Liedke says:

    This is a sample script to add an article for replication with a transactional replication created with backup and restore:

    :setvar PublicationDatabase DatabaseName

    :setvar PublicationName DatabasePublication

    :setvar TableName NewTable

    use $(PublicationDatabase)

    exec sp_addarticle @publication = N'$(PublicationName)', @article = N'$(TableName)', @source_owner = N'dbo', @source_object = N'$(TableName)', @type = N'logbased', @description = null, @creation_script = null, @pre_creation_cmd = N'drop', @schema_option = 0x000000000803509F, @force_invalidate_snapshot = 1, @identityrangemanagementoption = N'manual', @destination_table = N'$(TableName)', @destination_owner = N'dbo', @vertical_partition = N'false', @ins_cmd = N'CALL sp_MSins_dbo$(TableName)', @del_cmd = N'CALL sp_MSdel_dbo$(TableName)', @upd_cmd = N'SCALL sp_MSupd_dbo$(TableName)'

    exec sp_refreshsubscriptions @publication = N'$(PublicationName)'

    Make sure to click in Query -> SQLCMD Mode to enable the :setvar parameters


  4. Chris Rose says:

    I've done some testing on this, and believe it only works on 2008R2 and higher. Thoughts?

  5. sacha bess says:

    It's possible to add article but you need to change somes options on publication and update system table for subscribtion :…/replication-initialisation-par-sauvegarde