SQL Server AlwaysON Database Refresh
SQL Server AlwaysOn is very good functionality introduced by Microsoft as you can achieve high availability solution with actual copy of database with real time synch mode. Now as part of maintenance we might have to do database refresh (as part of regular support or if you build new system and want to restore database from existing system). I have tried to consolidate all points & steps included in doing such kind of activity. Hope this will help fellow group members
- Take Full DB Backup Source & Target.
- Stop Target System SAP Application & Database.
- Backup SAP System Profile Directory.
- Logon to Primary Node of Database and open SQL Management Console as Administrator.
- Delete Database From Availability Group (Always On High Availability à Availability Groupà <DB_CLUSTER> (Primary)àAvailability Databasesà Database)
- Delete Listener Services
- Bring your Database Offline on Primary Node.
- Logon to Secondary (Replica) Node of Database and open SQL Management Console as Administrator
- Bring your Database Offline on Secondary Node.
- Delete Data and Log Files from both Nodes.
- Restore Source Database from Disk or Tape on Primary Database Node.
- Run SWPM and select option System Copyà High Availability System à Database Instance as per your SAP Release/Version
- Need to select “Homogeneous System Copy (MS SQL Server Specific: Detach/Attach or Backup/Restore) option
- After SAP Installer runs successfully, login to SQL Management Console and delete tables (e.g. TLOCK, DBSNP, DDLOG etc) as per SAP System Copy Guide.
- Initiate Backup from Primary Node and transfer this backup to Secondary Node.
- Login to SQL Management Console on Secondary Node and check if Availability group or Listener exists (If entry still exists then simply delete it). Database (<SID>) can also be deleted from Databases as it will be restored later.
- Restore Backup taken from Primary Node with option “RESTORE WITH NORECOVERY”
- Check & Set the security settings for Always On Group.
- Create Availability Group from Primary Node.
- Add both nodes in Availability Group as Primary & Secondary during Availability Group Creation.
- Check Dashboard for the Availability Group Status if there is any error or not.
- Open Failover Cluster Manager
- Create Listener
- Check ILB IP Address and Port 59999 is properly assigned to Listener (* This is relative to Microsoft Azure Cloud Cluster)
- Check database status in both Nodes (It should be synchronized).
- Safer side execute sp_help_revlogin scripts on Primary and Secondary nodes (Similar to when initial installation was done).
- Compare and fix the SAP profile (DEFAULT) parameters from copied profile directory.
- Start SAP and perform initial check, apply license
- Perform post database refresh steps (As per SAP System Copy Guide).
Issues & Resolution: Below are the few issues I had faced/identified with their resolution while doing SQL DB RefreshIssue: During SWPM System Copy process if you face issue related to Server Princial <Domain>\<SIDADM> already exists.Resolution: This might be related to hard endpoints already existed due to prior database configuration. This can be checked and deleted as it will get created automatically later on. Below are the commands to check and fix:
- select suser_sid (‘<Domain>\<SIDADM>’)
- select * from sys.server_principals sp where sid=<Result from first query>
- SELECT p.name, e.* FROM sys.endpoints e inner join sys.server_principals p on e.principal_id = p.principal_id
- DROP ENDPOINT [Hadr_endpoint] (Run this query if you see <Domain>\<SIDADM> hard point entry in previous query)
Issue: While creating Availability Group you get error that this group name already exists.Resolution: If you want to user same Availability Group Name then open a query window and give below query to delete the entry:
- Drop availability group ‘<Group Name>’
After this you can recreate the Availability Group with same name.
Issue: While adding Secondary Node to Availability Group post-refresh if you get error that “Mirror Database “<SID>” has insufficient transaction log data to preserve the log backup chain of the principal database.Resolution: Take log backup from Primary Node and Restore it on Secondary Node using below command:
- Restore Log “<SID>” from disk = ‘Path to log backup file’ with NORECOVERY
- Continue with Availability Group Creation it will be successful