SQL Server Database Migration Checklist – For Successful DBAs
Migrating a database is very critical and time bound process, if anything goes wrong then its very difficult to rollback things and move back to existing environment again. So its very important to prepare a checklist before migrating a database and also keep a rollback plan ready in case of migration failure.
At some point of time we have to migrate old version of database server to new version of database server because of technology and feature enhancements, business requirements changes or hardware upgradation etc. We have two options for database migration, either we can go for in-place upgrade where new version of SQL Server is installed on the same machine where older version of SQL Server exists, this is automated process similar to SQL Server installation and second method is side by side migration where new version of SQL Server is installed on new system and when new system is ready, applications and other links and connectivities are pointed to it. It is a manual process where you have to copy or move each and every object from old server to new server manually.
Here I am going to list key points to keep in mind when doing side by side database migration.
- Run upgrade advisor on existing database to check the compatibility and deprecated features with respect to database and applications and make the required changes accordingly.
- Note down data file and log file locations and size and make sure new server has enough disk space available.
- Note down database recovery model, collation type and database facets.
- Note down compatibility level, database owner, linked server, full text catalogs and trustworthy settings details.
- Always keep more than one copy of latest database backup if it is feasible and you have enough storage available.
- Note down information regarding database logins, users and orphan users and permissions.
- Take a copy of all SSIS packages and config files and note down disk locations for files to move.
- Generate scripts for all SQL Server agent jobs.
- Note down all existing database maintenance plan and its properties.
- Generate all the SQL Server logins and keep it safe to deploy on new server.
- Note down windows logins and groups and permissions if any.
- Check if any Disaster recovery or high availability settings are available and make a note of that.
Once you are ready with pre-migration checklist, start performing migration.
- Make sure you stop all applications services connected with database.
- Set database to read only mode if required.
- Take the latest backup of databases.
- Restore latest copy of database on new server.
- Check and change the database compatibility level after restore.
- Migrate all the user logins and windows logins to new server.
- Check the database properties and alter it accordingly if required.
- Enable trustworthy database setting if required or keep it as default.
- Verify the orphan users and fix the same.
- Execute DBCC UPDATEUSAGE command to correct pages and row counts on migrated database.
- Execute DBCC CHECKDB on new migrated database to check the integrity of the objects.
- It is very important to rebuild all indexes on newly migrated database else you will face performance degradation while running the applications.
- Make required changes at application pointer to database and other connectivity settings.
- Update statistics on migrated database tables.
- Recompile all stored procedures, functions and triggers with sp_recompile.
- Refresh all the views available in the migrated database with sp_refershview.
- Deploy your high availability or disaster recovery plans if any on new database.
- Now test the application and correct the errors if any else celebrate success.
Queries used in Migration Checklist
– Take database backups – click here to know how to take database backups.
– Restore database backups – click here to know how to restore database backups.
– Verify compatibility level and change the same if required.
--Verify Compatibility Level SELECT name, compatibility_level, collation_name FROM sys.databases GO --Change Compatibility Level USE [master] GO ALTER DATABASE [DB_Name] SET COMPATIBILITY_LEVEL = 110 GO
– Note down Linked Servers details.
--Verify Linked Servers SELECT * FROM sys.sysservers GO
– Note down recovery model details.
--Check Recovery Model SELECT name, recovery_model_desc FROM sys.databases WHERE name = 'DBName' GO
– Note down collation setting.
--Verify Collation setting SELECT name, collation_name FROM sys.databases WHERE name = 'DBName'; GO
– Migrate all user logins and passwords – click here to know how to migrate logins and passwords.
– Verify database properties and alter the same if required.
--Check Database Properties SELECT *FROM sys.databases SD JOIN sys.syslogins SL ON SD.owner_sid = SL.sid GO
– Enable trustworthy database settings if required.
--Verify Trustworthy Settings SELECT is_trustworthy_on FROM sys.databases WHERE name = 'DBName' GO --Enable Trustworthy Database Settings if required ALTER DATABASE DBName SET TRUSTWORTHY ON GO
– Verify and fix orphan users – click here to know how to fix orphan users.
– Correct all the pages and row counts with DBCC UPDATEUSAGE command.
--Correct Pages and Row Counts DBCC UPDATEUSAGE('DBName') WITH COUNT_ROWS GO
– Check integrity of objects with DBCC CHECKDB command.
--Check Integrity of Objects DBCC CHECKDB('DBName') WITH ALL_ERRORMSGS GO
– Rebuild all indexes by creating maintenance plan or by manual query.
--Script for Index Rebuild USE DBName GO ALTER INDEX ALL ON dbo.TableName REBUILD GO
– Update database tables statistics.
--Update Database Statistics USE DBName EXEC sp_updatestats GO
– Recompile all stored procedures, functions and triggers.
--Recompile Objects USE DBName EXEC sp_recompile 'ObjectName' GO
– Refresh all the views of database.
--Refresh Views USE DBName EXEC sp_refreshview 'ViewName' GO
CLICK HERE to watch Migration Checklist.
Reference: Manzoor Siddiqui [www.SQLServerLog.com]