Migrate MS SQL database to GCP cloud native - Cloud SQL MS SQL server(Part 1)
Set up Transactional Replication Publication
- In the VM Instance, Connect to On-Prem DB instance using SSMS.
We will now create a Publisher:
- Expand the menu under your Instance in SSMS. Go to Replication → Local Publications
- Right Click on Local Publications and Click on “New Publication”
- Select the Database to be Publisher.
- On the Next Screen, Select “Transactional Publication”
- On the next screen, you are given Objects to set up Transactional Publishing for.
- Note the Application Changes required if any
8.You may choose to add Filtering on Table Rows in Next Window
- On the Next screen, choose “Create Snapshot Immediately and keep the snapshot available to initialize subscription”. You can choose to run Snapshot Agent to run on schedule too
- On the Next Page, there would be Snapshot Agent and Log Reader Agent. Give the Administrator Account to both.
- On the next page, Give name to Publication and Click on Finish. Monitor the Logs to make sure there are no errors.
- Check if Snapshot is an Agent running or not. Go to Your Publication and Right Click. If not, enable to service to start running
Set up Transactional Replication Subscription
- Go to your Publication and Right Click and go to Properties → Publication Access List. Add administrator here if missing.
- Go to your Publication and Right Click and go to New Subscription
- On the next screen, select the Publication just created
- We need a PUSH Based Subscription. On the next window select this. There is also a PULL based subscription on Agent.
- On the next screen, we will add Subscriber ie. our Cloud SQL Server Details. Click “Add Subscriber”.
- On the Window that opens, give Public IP of Cloud SQL server and put authentication details for the user set.
- Once this is created, we need to add Subscription DB. We can use “Create New DB” here.
-
Give DB information on the next screen
-
On the next screen, you will see Distribution Agent Security. For the Distribution Agent, the machine runs on-prem. So keep Windows Authentication for DOMAIN\administrator. For Connecting to Subscriber give Cloud SQL user details in “SQL Server Login”
-
Click on Finish and monitor for any errors.
Database Level Permissions
Make sure that the Database Owner is set and the user has the permissions.
This can be configured on the Database Properties
Monitoring the Subscription
Now let’s have a look at the subscription status for the Replication.
- Go to Subscription and Right Click. Go to “Replication Monitor”. Check for any errors. There should be no authentication errors in Subscription. If there are errors, these are segregated into 3 categories.
- Publisher to Distributor History
- Distributor to Subscriber History
- Undistributed Command
- For the current Example, Latency is 4 seconds
- Connect to Cloud SQL Server using SSMS. You should be able to see the New Database with Tables being replicated.
Key Observations
- For Creating new Users and correcting Server Names, SQL Server Restart might be needed on the Node.
- Network Connectivity will be critical to make sure Cloud SQL is reachable from On-Prem
- We would need a DB User Account for logging in from Cloud SQL to On-Prem and handling credentials for that.
- To prevent overload of the server, this process should be done in OFF Hours.
- DB Owner for the set up Databases needs to be accessed and modified if required. This is required for Publisher to Distributor Flow.
- Snapshot Agent and Log Reader Agent should already be running and not stopped.
- Cloud SQL DB should be HA by default
- Authentication to Cloud SQL can also be done using AD accounts.
References
- https://learn.microsoft.com/en-us/sql/relational-databases/replication/tutorial-replicating-data-between-continuously-connected-servers?view=sql-server-ver16
- https://cloud.google.com/solutions/migrating-data-from-sql-server-to-cloud-sql-for-sql-server
- https://docs.google.com/document/d/1Wh1hICYSaDjS6yN64vUb4k2hCS9fM5wd_rFHF0HPeW0/edit?pli=1
- https://cloud.google.com/sql/docs/quotas#fixed-limits



















