Migration sql server from sql 2017 to sql 2022 with Minimal Down time
Published Jun 14 2024 01:57 AM 6,348 Views
Microsoft

Below is our suggestion for the migration activity: 

  

  1. Always on High Availability 
  2. DB Mirroring 
  3. Logshipping

SQL Always on High Availability : 

It is possible to configure a SQL Server Always On availability group with a primary replica running on SQL Server 2017 and a secondary replica running on SQL Server 2022, but there are important considerations and limitations to keep in mind: 

  1.  Backward Compatibility: SQL Server supports having replicas on different versions, but the primary replica must be on an older version than or equal to the secondary replicas. Therefore, having SQL Server 2017 as the primary and SQL Server 2022 as the secondary is valid. 
  2.  Database Upgrade Path: When you decide to upgrade the primary replica to a newer version, you need to follow a specific upgrade path to ensure minimal downtime and data integrity. Typically, this involves: 
  •   Adding the newer version as a secondary replica. 
  •   Failing over to the secondary replica running the newer version (making it the new primary). 
  •   Upgrading the former primary to the newer version. 
  •   Adding it back to the availability group. 

 

  1.  Feature Compatibility: Some features available in SQL Server 2022 might not be fully supported or behave differently when the primary replica is running on SQL Server 2017. It's essential to test the behavior of your applications and workloads thoroughly in this mixed-version environment. 
  2.  Support and Documentation: Always refer to the official Microsoft documentation for the most accurate and up-to-date information about version compatibility and supported configurations. Microsoft's official [documentation on Always On availability groups](https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/always-on-availabil...) is a good place to start. 
  3.  Licensing and Maintenance: Ensure that your licensing agreements and maintenance plans support such a configuration. Running different versions might have implications for your support agreements with Microsoft. 

Here is a high-level example of setting up such a configuration: 

  1. Install SQL Server 2017 on the primary server and configure it as the primary replica. 
  2. Install SQL Server 2022 on the secondary server and configure it as the secondary replica. 
  3. Create the availability group on SQL Server 2017 and add the database(s) to the group. 
  4. Add the SQL Server 2022 instance as a secondary replica to the availability group. 
  5. Configure synchronization and verify that the secondary replica is properly synchronized with the primary replica. 
 
Example Steps for Adding SQL Server 2022 as a Secondary Replica 
  1. On the Primary Server (SQL Server 2017): 

 

  ALTER AVAILABILITY GROUP [YourAGName] 
  ADD REPLICA ON 'SQL2022ServerName' 
  WITH (ENDPOINT_URL = 'TCP://SQL2022ServerName:5022', AVAILABILITY_MODE = ASYNCHRONOUS_COMMIT, FAILOVER_MODE = MANUAL); 

 

 

  1. On the Secondary Server (SQL Server 2022):

 

ALTER DATABASE [YourDatabaseName] SET HADR AVAILABILITY GROUP = YourAGName; 

 

 

  1. Join the Secondary Replica to the Availability Group: 

 

ALTER AVAILABILITY GROUP [YourAGName] JOIN; 

 

 

 

  1. Start Data Synchronization: 

 

  ALTER DATABASE [YourDatabaseName] SET HADR RESUME; 

 

 

Always test such configurations in a non-production environment to ensure that everything works as expected and to understand any potential issues or performance implications. 

  

https://learn.microsoft.com/en-us/sql/database-engine/availability-groups/windows/upgrading-always-o... 

  

DB Mirroring : 

Using database mirroring to migrate a SQL Server database from SQL Server 2017 to SQL Server 2022 is a viable strategy. Database mirroring provides a way to maintain a synchronized copy of your database on the new server. Here are the detailed steps to perform the migration: 

Step-by-Step Migration Process 

  1. Prepare the Environment 
  •  Install SQL Server 2022: Set up SQL Server 2022 on your new server where you want to migrate your database. 
  •  Network Configuration: Ensure that the network between the old (SQL Server 2017) and the new server (SQL Server 2022) is properly configured and both servers can communicate with each other. 
  1.  Backup the Primary Database 
  •  Full Backup: 

 

BACKUP DATABASE YourDatabaseName TO DISK = 'C:\Backup\YourDatabaseName_Full.bak'; 

 

 

  •  Transaction Log Backup: 

 

BACKUP LOG YourDatabaseName TO DISK = 'C:\Backup\YourDatabaseName_Log.trn'; 

 

 

  1.  Restore the Backup on the New Server 
  •  Copy the backup files to the new server. 
  •  Restore the Full Backup: 

 

RESTORE DATABASE YourDatabaseName FROM DISK = 'C:\Backup\YourDatabaseName_Full.bak' 
WITH NORECOVERY; 

 

 

  •  Restore the Transaction Log Backup: 

 

RESTORE LOG YourDatabaseName FROM DISK = 'C:\Backup\YourDatabaseName_Log.trn' 
WITH NORECOVERY; 

 

 

  1.  Configure Database Mirroring 
  •  On the Principal (SQL Server 2017): 

 

ALTER DATABASE YourDatabaseName 
SET PARTNER = 'TCP://SQL2022ServerName:5022'; 

 

 

  •  On the Mirror (SQL Server 2022): 

 

ALTER DATABASE YourDatabaseName 
SET PARTNER = 'TCP://SQL2017ServerName:5022'; 

 

 

  •  Security Configuration: Ensure that the database mirroring endpoints are configured correctly and that the service accounts have the necessary permissions. 
  1.  Monitor the Synchronization 
  •  Verify that the mirroring session is established and that the databases are synchronizing. You can use the following query to check the status: 

 

SELECT 
     db_name(database_id) AS DatabaseName, 
     mirroring_state_desc, 
     mirroring_role_desc, 
     mirroring_partner_name, 
     mirroring_partner_instance 
   FROM 
      sys.database_mirroring; 

 

 

  1. Failover to the New Server (SQL Server 2022) 
  •  Once the database is fully synchronized, you can perform a manual failover to make the SQL Server 2022 instance the principal server. 

 

ALTER DATABASE YourDatabaseName SET PARTNER FAILOVER;

 

  1.  Update Applications and Services 
  •  Point your applications and services to the new SQL Server 2022 instance. 
  •  Update connection strings to reflect the new server name or IP address. 
  1. Remove Mirroring (Optional) 
  •  If you no longer need mirroring after the migration, you can remove the mirroring configuration. 

 

-- On the Principal (now SQL Server 2022) 
ALTER DATABASE YourDatabaseName SET PARTNER OFF; 
-- On the Mirror (SQL Server 2017) 
ALTER DATABASE YourDatabaseName SET PARTNER OFF; 

 

Considerations and Best Practices 

  • Compatibility: Ensure that your database and applications are compatible with SQL Server 2022. Test in a non-production environment before migrating. 
  • Downtime: Plan for a maintenance window, as there might be a brief downtime during the failover. 
  • Backup and Restore: Always have a recent backup before starting the migration. 

Using database mirroring can provide a smooth transition with minimal downtime, ensuring that your data remains consistent throughout the migration process. 

https://learn.microsoft.com/en-us/sql/database-engine/database-mirroring/database-mirroring-sql-serv... 

  

Log Shippig : 

Using log shipping to upgrade from SQL Server 2017 to SQL Server 2022 involves setting up log shipping between the two servers, synchronizing them, and then performing a cutover. Here are the steps to perform the migration using log shipping: 

Step-by-Step Migration Process 

  1.  Prepare the Environment 
  •  Install SQL Server 2022: Set up SQL Server 2022 on your new server. 
  •  Network Configuration: Ensure that the network between the old (SQL Server 2017) and the new server (SQL Server 2022) is properly configured and both servers can communicate with each other. 
  1.  Configure Log Shipping 
  •  Full Backup of the Primary Database (SQL Server 2017): 

 

BACKUP DATABASE YourDatabaseName TO DISK = 'C:\Backup\YourDatabaseName_Full.bak';

 

  •  Copy the Full Backup to the new server (SQL Server 2022). 
  •  Restore the Full Backup on the New Server (SQL Server 2022): 

 

RESTORE DATABASE YourDatabaseName FROM DISK = 'C:\Backup\YourDatabaseName_Full.bak' 
WITH NORECOVERY; 

 

  •  Enable Log Shipping on the Primary Database (SQL Server 2017): 
  •    Right-click the database in SQL Server Management Studio (SSMS), go to "Properties," and select "Transaction Log Shipping." 
  •    Check "Enable this as a primary database in a log shipping configuration." 
  •    Configure the backup settings (backup path, schedule). 
  •  Configure the Secondary Server (SQL Server 2022): 
  •   Specify the new server as the secondary. 
  •   Set the path to the backup folder where transaction log backups will be copied. 
  •   Configure the restore settings to restore the logs with the `STANDBY` option (so the database can be read-only for verification purposes) or `NORECOVERY` (if you want to keep it in a restoring state). 
  1.  Start Log Shipping 
  •  Initial Transaction Log Backup: 

 

BACKUP LOG YourDatabaseName TO DISK = 'C:\Backup\YourDatabaseName_Log1.trn';

 

  •  Copy and Restore the Log Backup on SQL Server 2022: 

 

RESTORE LOG YourDatabaseName FROM DISK = 'C:\Backup\YourDatabaseName_Log1.trn' 
WITH NORECOVERY;

 

  • Schedule Regular Log Backups: Configure SQL Server Agent jobs to take regular transaction log backups on the primary and copy them to the secondary server. 
  1.  Monitor Log Shipping 

 - Monitor the log shipping status using the Log Shipping Monitor or SQL Server Management Studio to ensure that the transaction logs are being backed up, copied, and restored correctly. 

  1. Perform the Cutover to SQL Server 2022 
  • Stop All Transactions on the Primary Database (SQL Server 2017): Ensure no new transactions are occurring on the primary database. 

 

ALTER DATABASE YourDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

 

  •  Take a Final Log Backup on the Primary (SQL Server 2017): 

 

BACKUP LOG YourDatabaseName TO DISK = 'C:\Backup\YourDatabaseName_LogFinal.trn';

 

  • Copy and Restore the Final Log Backup on the Secondary (SQL Server 2022): 

 

RESTORE LOG YourDatabaseName FROM DISK = 'C:\Backup\YourDatabaseName_LogFinal.trn' 
WITH RECOVERY;

 

  • Bring the New Database Online: 

 

ALTER DATABASE YourDatabaseName SET MULTI_USER; 

 

  1. Update Applications and Services 
  • Point your applications and services to the new SQL Server 2022 instance. 
  • Update connection strings to reflect the new server name or IP address. 

Considerations and Best Practices 

  • Testing: Thoroughly test the log shipping configuration and the final cutover process in a non-production environment before doing it in production. 
  • Downtime: Plan for a maintenance window during the cutover process as there will be some downtime. 
  • Backup and Restore: Always have recent backups before starting the migration. 
  • Log Shipping Monitor: Use the Log Shipping Monitor to ensure that all log shipping processes are running smoothly. 

  

Log shipping for the upgrade provides a way to minimize downtime and ensure data consistency throughout the migration process. 

https://learn.microsoft.com/en-us/sql/database-engine/log-shipping/configure-log-shipping-sql-server... 

 

1 Comment
Co-Authors
Version history
Last update:
‎Jun 14 2024 01:56 AM
Updated by: