HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to add an article to existing replication

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
addreplicationhowexistingarticle

Problem

This is the first time I am going to add tables to replication.

I have outlined the below steps to add a new table to existing replication. Please correct me if I am wrong. The table is just created - no data.

exec sp_addarticle @publication = N'pub1', @article = N'tab1', @source_owner = N'dbo', @source_object = N'tab1'

 EXEC sp_addsubscription
  @publication = 'pub1',
  @subscriber = 'sub1',
  @destination_db = 'MLT-Rep'
GO
 EXEC sp_addsubscription
  @publication = 'pub1',
  @subscriber = 'sub2',
  @destination_db = 'MLT-Rep'


After this, I am supposed to run Snapshot right? How do I go about doing that? Just navigate to the "Local Publication" -> "View Snapshot Agent Status" -> Start

Are the above steps right?

Solution

Adding an a new article involves adding the article to the publication, creating a new snapshot, and synchronizing subscriptions to apply the schema and data for the newly added articles. Reinitialization is not required, but a new snapshot is.

Your steps are correct if the publication only has existing push subscriptions. If the publication has existing pull subscriptions, you will also need to execute sp_refreshsubscriptions. And you are correct, to generate a new snapshot you can use the View Snapshot Agent dialog, or you can execute sp_startpublication_snapshot.

To avoid generating a full snapshot when adding a new article, publication properties @immediate_sync and @allow_anonymous must be set to 0. Execute sp_addarticle, then execute sp_addsubscription. If the publication has existing pull subscriptions, you must also call sp_refreshsubscriptions. Then generate a snapshot and only a snapshot for the newly added article will be generated. Note that this approach is not necessary but is typically used when Administrators want to avoid generating a full snapshot when adding a new article.

Please see Add Articles to and Drop Articles from Existing Publications for more information.

Context

StackExchange Database Administrators Q#57600, answer score: 5

Revisions (0)

No revisions yet.