1002-001-004 Database Server Migration Guide
Contents Database Server Migration Guide REQUIREMENTS AND RECOMMENDATION DISCLAIMER... 3 INTRODUCTION... 4 OBJECTIVE... 4 PRE-MIGRATION CHECKLIST... 4 DATABASE MIGRATION CHECKLIST... 7 REFERENCES... 11 2
REQUIREMENTS AND RECOMMENDATION DISCLAIMER Whilst every effort has been made to ensure that the information and content within this document is accurate, up-to-date and reliable, Gulf Solution Group disclaims any and all liability as to any results or conditions arising after the application of this information. Actions taken from information in the document are solely at the user's own risk. The user should thoroughly test the information in a nonproduction environment first before applying it to LIVE environment This document also contains links to third-party sites which are not under the control of gulf solution and gulf solution is not responsible for the contents on any linked site or any link contained in a linked site, or any changes or updates to such sites. Gulf solution is providing these links to you only as a convenience, and the inclusion of any link does not imply that gulf solution endorses or accepts any responsibility for the content on such third-party sites Performance and response time are affected by many factors related to hardware (such as RAM, processor speed, and hard disk subsystem performance), network configuration (such as NIC performance, cable type, topology, operating system, parameters, and traffic), and the database (such as size, number of concurrent users, and the type of activities each user is performing). In addition, network and workstation operating systems, third-party software products, and our own products are continuously updated with new features and options, which often place greater demands on hardware. Gulf Solutions Group staff may provide limited informal guidance based on information made available. However, neither these system requirements nor our staff's guidance constitute a guarantee of compatibility, outcome, or performance. We encourage organizations to consult their own IT System's Staff or external experts to ensure optimum results. Comprehensive technical consulting services are available through Gulf Solutions Group and under a separate consulting arrangement; our consultants evaluate the installation of all Gulf Solutions Group applications and recommend optimal hardware/system configuration options. Email support@gulfsolution.com for more information. 3
INTRODUCTION Many times we get requests to migrate a single user database or multiple user databases to different server. At the time of migrating databases, there are chances that we can miss some important steps, for example trustworthy property, dependent jobs, linked server, logins etc. There are also chances we are missing important DBA items which can hurt SQL Server performance. As a solution to decrease making mistakes during the migration process there is a checklist that should follow for the database migration. In addition, there are steps which should be taken which can enhance the database performance after the migration. OBJECTIVE The objective of this document is to provide the guidelines for the SQL Server Database migration from one server to another. PRE-MIGRATION CHECKLIST 1. Analyze the disk space of the target server for the new database, if the disk space is not enough add more space on the target server Script to Check the Disk and Database Size -- Procedure to check disc space exec master..xp_fixeddrives -- To Check database size exec sp_helpdb [dbname] or use [dbname] select str(sum(convert(dec(17,2),size)) / 128,10,2) + 'MB' from dbo.sysfiles 2. Confirm the data and log file location for the target server. Script to find data and log file location used by SQL Server instance SELECT name, physical_name AS current_file_location FROM sys.master_files 4
3. Collect the information about the Database properties (Auto Stats, DB Owner, Recovery Model, Compatibility level, Trustworthy option etc.) Script to Check the Disk and Database Size select sysdb.database_id, sysdb.name as 'Database Name', syslogin.name as 'DB Owner', sysdb.state_desc, sysdb.recovery_model_desc, sysdb.collation_name, sysdb.user_access_desc, sysdb.compatibility_level, sysdb.is_read_only, sysdb.is_auto_close_on, sysdb.is_auto_shrink_on, sysdb.is_auto_create_stats_on, sysdb.is_auto_update_stats_on, sysdb.is_fulltext_enabled, sysdb.is_trustworthy_on from sys.databases sysdb INNER JOIN sys.syslogins syslogin ON sysdb.owner_sid = syslogin.sid 4. Collect the information of dependent applications; make sure application services will be stopped during the database migration. To Stop SQL SERVER and SQL Server Agent using Command Prompt net stop SQL Server Agent (Instance Name) net stop SQL Server (Instance Name) To Start SQL SERVER and SQL Server Agent using Command Prompt net start SQL Server (Instance Name) net start SQL Server Agent (Instance Name) 5
You can also check http://technet.microsoft.com/en-us/library/ms175516.aspx to see how to stop application services. 5. Collect the information of database logins, users and their permissions. (Optional) 6. Check the database for the Orphan users if any Script to List Orphan Users sp_change_users_login 'report' 7. Check the SQL Server for any dependent objects (SQL Agent Jobs and Linked Servers) 8. List out all Maintenance plans and their schedules. Script to List Database Dependent Jobs select distinct name, database_name from sysjobs sj INNER JOIN sysjobsteps sjt on sj.job_id = sjt.job_id 9. List out all Linked server(s) currently being used. Script to List Linked Servers select * from sys.sysservers 10. Check the service pack. 11. Check the Edition and make sure targeted server do not have old version. See http://support.microsoft.com/kb/321185 to know how to find SQL Server version and Service pack. 6
DATABASE MIGRATION CHECKLIST These are the steps you would go through to make the change. 1. Stop the application services 2. Change the database to read-only mode (Optional) -- Script to make the database readonly USE [master] ALTER DATABASE [DBName] SET READ_ONLY WITH NO_WAIT ALTER DATABASE [DBName] SET READ_ONLY 3. Take the Full backups of all System and Application databases involved in migration 4. Restore the databases on the target server on the appropriate drives 5. Cross check the database properties as per the database property script output, change the database properties as per the pre migration- checklist Script to Change DB Owner This will change the database owner to "sa". This can be used to change owner you would like. USE databasename EXEC sp_changedbowner 'sa' Script to Turn on Trustworthy Option If trustworthy option was set, this will turn it on for the database. ALTER DATABASE database_name SET TRUSTWORTHY ON Script to Change the Database Compatibility Level When you upgrade to a new version, the old compatibility level will remain. This script shows how to change the compatibility level to SQL Server 2005 compatibility. 7
ALTER DATABASE DatabaseName SET SINGLE_USER EXEC sp_dbcmptlevel DatabaseName, 90; ALTER DATABASE DatabaseName SET MULTI_USER 6. Execute the output of Login transfer script on the target server. See Also: http://support.microsoft.com/kb/246133. 7. Check for Orphan Users and Fix Orphan Users -- Script to check the orphan user EXEC sp_change_users_login 'Report' --Use below code to fix the Orphan User issue DECLARE @username varchar(25) DECLARE fixusers CURSOR FOR SELECT UserName = name FROM sysusers WHERE issqluser = 1 and (sid is not null and sid <> 0x0) and suser_sname(sid) is null ORDER BY name OPEN fixusers FETCH NEXT FROM fixusers INTO @username WHILE @@FETCH_STATUS = 0 BEGIN EXEC sp_change_users_login 'update_one', @username, @username FETCH NEXT FROM fixusers INTO @username END CLOSE fixusers DEALLOCATE fixusers 8
8. Execute DBCC UPDATEUSAGE on the restored database. Run the DBCC UPDATEUSAGE command against the migrated database when upgrading to a newer version of SQL Server. DBCC UPDATEUSAGE('database_name') WITH COUNT_ROWS DBCC CHECKDB OR DBCC CHECKDB('database_name') WITH ALL_ERRORMSGS 9. Rebuild Indexes (Optional) As per the requirement and time window you can execute this option. This will rebuild or reorganize all indexes for a particular table. Index Rebuild: - This process drops the existing Index and Recreates the index. Index Reorganize: - This process physically reorganizes the leaf nodes of the index. -- Script for Index Rebuild USE [DBName]; ALTER INDEX ALL ON [ObjectName] REBUILD -- Script for Index Reorganize USE AdventureWorks; ALTER INDEX ALL ON [ObjectName] REORGANIZE 10. Update index statistics Script to update index statistics sp_updatestats 11. Move all the DTS packages. 9
12. Recompile procedures See also: http://www.mssqltips.com/tip.asp?tip=1260 13. Start the application services, check the application functionality and check the Windows event logs. 14. Check the SQL Server Error Log for login failures and other errors 15. Point the application to new server. 10
REFERENCES SQL Server Database Migration Checklist http://www.mssqltips.com/tip.asp?tip=1936 11
Dubai Corporate Head Office: Dubai Internet City, Building No. 2, Suite 212, Dubai - United Arab Emirates. Telephone: +971 4 3910 470 www.gulfsolution.com info@gulfsolution.com Karachi Park Avenue, Suite 404, Shahrah-E-Faisal, Karachi - Pakistan. Telephone: +92 213 4304 784 www.gulfsolution.com.pk info@gulfsolution.com.pk Bahrain Telephone : +973 3 9271 539 www.gulfsolution.com info@gulfsolution.com Database Server Migration Guide 12