When a business needs to move a distribution database to a new MS SQL Server instance, the most common solution is to drop and recreate a replication topology with a new distributor instance. However, this approach can be time-consuming and may cause downtime in production systems. In this article, we will discuss a better solution that involves restoring the existing distribution database on the new distributor.
Step-by-Step Guide
Follow these steps to move a distribution database to a new SQL Server instance:
- Create a distribution database on the new distributor instance.
- Add the publisher values on the new distributor instance.
- Create the missing linked servers on the new distributor.
- Make sure the msdb.dbo.MSagent_profiles are matching between distributors.
- Set the distribution database to full recovery mode.
- Create the missing logins on the new distributor and add distribution agent and log reader agent accounts to the db_owner role on the distribution database.
- Create a missing distribution agent login and add it to the db_owner role on the subscriber databases for pull subscriptions.
- Stop or disable replication jobs on the current distributor and pull subscribers.
- Backup the distribution database on the current distributor.
- Restore the distribution database on the new distributor instance.
- Update the MSpublisher_databases table with the correct publisher id.
- Script out log reader and snapshot jobs from the current distributor and create these jobs in a disabled state on the new distributor with updated server names in all job steps.
- Change the publisher_id in the restored distribution database.
- Change the subscriber_id/publisher_id in the restored distribution database.
- Script out push subscription jobs from the current distributor and create these jobs in a disabled state on the new distributor with updated server names in all job steps.
- Alter pull subscribers replication jobs to update the new distributor name.
- Alter the distributor name on pull subscribers.
- Update log reader agent entries to ensure the replication monitor is working.
- Change the distributor name on the publisher.
- Enable subscriber jobs one-by-one and resolve any permission issues.
- Enable log reader agent jobs one-by-one and resolve any permission issues.
- Add the distribution database to the backup schedule and perform regular database backups.
- If no errors exist, delete disabled replication jobs on the old distributor.
- Drop the old publisher on the old distributor server.
- Open replication monitor and verify transactional replication activity.
This custom solution allows SQL DBAs to quickly move a distribution database to a new SQL Server instance without losing data and causing downtime in the production environment. It also provides a way to revert back to the previous setup if any issues occur during the change process.
It is important to note that if log-reader agents are enabled and new transactions have been processed on the new distributor, the correct way to rollback would be to drop and recreate replication objects and perform data synchronization afterwards.