There are several things that need to be addressed when upgrading to SQL Server 2008. Once you have decided to upgrade, you have to make sure that all the features implemented in the prior version are compatible with SQL Server 2008. We will be discussing several tools in this chapter to help guide you through the upgrade process. This chapter will also explain the different upgrade strategies to help you decide the best method for your environment. Finally, we will look at configuration changes that need to be made after the upgrade to ensure that you are taking full advantage of the features offered in SQL Server 2008.
There are two main tools available to assist you in the upgrade process to SQL Server 2008. These tools help you to resolve any possible compatibility and performance issues that might exist. These tools are the Upgrade Advisor and the Upgrade Assistant.
The Microsoft SQL Server 2008 Upgrade Advisor analyzes your SQL Server 2000 and SQL Server 2005 instances and identifies configuration items that may impact your upgrade process. The Upgrade Advisor then provides links to web pages that will provide you with the information needed to resolve the conflicts before the upgrade.
The Upgrade Advisor can be installed from the first page of the SQL Server 2008 install screen or downloaded from the following URL: www.microsoft.com/downloads/details.aspx?familyid=F5A6C5E9-4CD9-4E42-A21C-7291E7F0F852&displaylang=en
.
The install is pretty straightforward (accepting the defaults should be fine). Once you have completed the install, use the following steps to produce your analysis report:
Figure 5-1. Upgrade Advisor Analysis Wizard Welcome screen
Figure 5-2. Upgrade Advisor server and components selection
Figure 5-3. Upgrade Advisor authentication
Figure 5-4. Upgrade Advisor SQL Server parameters
Figure 5-5. Upgrade Advisor confirmation screen
Figure 5-6. Upgrade Advisor rule analysis
Figure 5-7. Upgrade Advisor rule analysis completed
Figure 5-8. Upgrade Advisor analysis report
Figure 5-9. Upgrade Advisor affected objects
Upgrade Advisor is helpful in planning an upgrade, and you'll find yourself returning to it often. You don't have to rerun reports, however. You can review the reports again without rerunning the analysis by selecting Launch Upgrade Advisor Report Viewer from the application home screen.
The Upgrade Assistant is a free third-party tool you can use to determine how a database will perform after it has been upgraded from SQL Server 2000 or SQL Server 2005 to SQL Server 2008. The Upgrade Assistant also identifies compatibility issues that may not have been detected using the Upgrade Advisor. The Upgrade Assistant will create a baseline by running a trace on the SQL Server 2000 or SQL Server 2005 database that is going to be upgraded. It will then run the trace against the upgraded SQL Server 2008 database in a controlled test environment and generate a report comparing the two traces. The Upgrade Assistant and user guide can be downloaded from the scalability experts download page located at www.scalabilityexperts.com/default.asp?action=article&ID=45
.
Following is a list of the general steps involved when running the Upgrade Assistant:
Caution The Upgrade Assistant should be run in a test environment to ensure that the tests will not affect the production system. A production system may be used to capture adequate trace information, but the capture process could impact performance just as any trace on a production server could. More importantly, the Upgrade Assistant takes a backup of all of the databases (including the system databases) on the instance during the capture process. This backup by the Upgrade Assistant will break the backup sequence of each of the databases and could impact any high-availability processes you have in place.
When capturing a playback, try to perform as many actions as possible in the application to generate a trace with proper coverage. You should start the trace as soon as the backup process has completed to prevent transactions from occurring that will cause rerunning the playback on the test system to fail. Since the initial playback process backs up all the databases on the instance, make sure you have sufficient disk space to store the backups and the trace file. The trace file is generated in the same location as the backup files. You can use a network share if the server does not have enough disk space. You must be a member of the sysadmin
role to capture a playback.
Tip You can take any databases offline that you do not want backed up as a result of the playback process.
SQL Server Integration Services (SSIS) was introduced in SQL Server 2005 and uses a completely different architecture than its predecessor Data Transformation Services (DTS). SSIS provides a much more robust environment for moving and transforming data, but it also provides difficulties when upgrading packages from SQL Server 2000. You basically have two choices: You can rewrite each package to run in SSIS or use the old DTS DLLs to continue running each package. If you have a small number of fairly simple packages, it may be easy enough to rewrite the packages manually. If not, there are a few tools available to help you with the conversion process.
SQL Server 2008 provides the ability to run and manage DTS packages by downloading a couple of add-ons. We would use this approach as a last resort and use the upgrade as an opportunity to migrate your packages to SSIS. SSIS performs much more efficiently, and the add-ons may not be available in the next version of SQL Server. For more information, search for the topic “How to: Install Support for Data Transformation Services Packages” in SQL Server Books Online or MSDN (http://msdn.microsoft.com
).
In order to run DTS packages in SQL Server 2008, you must install the runtime support add-on. To install runtime support for DTS packages in SQL Server 2008, download and install the Microsoft SQL Server 2005 backward compatibility components from the Microsoft SQL Server 2008 Feature Pack web page from the Download Center located at www.microsoft.com/downloads/details.aspx?FamilyID=228de03f-3b5a-428a-923f-58a033d316e1&DisplayLang=en
.
In order to design and manage DTS Packages in SQL Server 2008, you must install the design-time support add-on. To install design-time support for DTS packages in SQL Server 2008, download the Microsoft SQL Server 2000 DTS designer components from the Feature Pack for Microsoft SQL Server 2005 web page from the Download Center located at www.microsoft.com/downloads/details.aspx?FamilyID=50b97994-8453-4998-8226-fa42ec403d17&displaylang=en
.
The DTS Package Migration Wizard is installed when you select Integration Services as a feature during your SQL Server 2008 install. The Migration Wizard allows you to upgrade existing DTS packages to an SSIS format, as long as all the objects are compatible. The Upgrade Advisor can be used to identify some of the issues that need to be resolved before migrating the packages.
Note DTS xChange is a third-party tool that can be used to migrate DTS packages to SSIS. DTS xChange does a better job than the DTS Migration Wizard. It can also convert packages that the Migration Wizard will be unable to convert. DTS xChange is not a free tool, but if you have many complex DTS packages to convert, it may be well worth the investment. The demo version can be used to migrate up to five packages and can be downloaded from the Pragmatic Works web site at www.pragmaticworks.com
.
Use the following steps to convert DTS packages to SSIS using the DTS Package Migration Wizard:
Once you have determined that your databases are compatible with SQL Server 2008, you are ready to perform an upgrade. There are two ways to perform an upgrade. The first is known as an in-place upgrade, and as the name implies, it upgrades an entire instance “in place” by converting the data files to the new format. The second approach is known as a side-by-side upgrade, which consists of installing a second instance of SQL Server and moving the data files to the new version. Both methods have their pros and cons, and the best method for one application may not be the best method for another. An in-place upgrade provides simplicity but lacks the flexibility offered by a side-by-side upgrade.
An in-place upgrade can be used to upgrade an instance of SQL Server 2000 or SQL Server 2005 directly to SQL Server 2008. Search for “Version and Edition Upgrades” on MSDN for specifics on the supported upgrade paths for each version and edition.
One of the benefits of performing an in-place upgrade is that you can use the same server and instance names. This may save you from having to track down all the connections to the database and point them to a new server or instance name. It is a fairly simple process, much like performing an installation. You do not need extra disk space to make a copy of the data files because they will be converted to the new format during the upgrade. The downside is that there is a point during the upgrade process where there is no turning back. The only back out is to reinstall the prior version of SQL Server and restore the databases from a backup that was made prior to the upgrade. You cannot restore a backup of a database that has been converted to SQL Server 2008 on a previous version. If you determine that a problem has been caused a week later by the upgrade, you will have to restore the database from a backup prior to the upgrade and hope you have a way to recover the transactions that have occurred since the upgrade.
Caution It is important to have a tested backup in a safe location, since that is the only way to back out of an in-place upgrade. You may want to take an image of the server as well and store it in a safe location to reduce the backout time.
The steps to performing an in-place upgrade include the following:
Figure 5-10. SQL Server Installation Center
Figure 5-11. Upgrade Setup Support Rules
Figure 5-12. Upgrade to a free edition or enter a product key.
Figure 5-13. Upgrade license agreement
Figure 5-14. Upgrade instance selection
Figure 5-15. Upgrade features selection
Figure 5-16. Upgrade the instance configuration
Figure 5-17. Upgrade rules
Figure 5-18. Upgrade features verification
Figure 5-19. Upgrade Progress screen
Figure 5-20. Upgrade completion
Once you have completed the upgrade, it is always a good idea to log in to the application and run some tests to make sure the upgrade was truly a success before releasing the database back into production. It will help if you have some baseline performance statistics prior to the upgrade that you can use to compare to the upgraded database. Unfortunately, some people are reluctant to change and think everything used to work better on the old version. In rare cases, some queries may actually perform worse after the upgrade. Having a baseline will help you determine if there is actually an issue, or if it is just user perception.
A side-by-side upgrade consists of installing SQL Server 2008 and moving the databases from the old instance to the new instance. The side-by-side method gives you a chance to test the effects SQL Server 2008 will have on an application before severing the ties with the old version. The new instance can be installed on a second server, or you can use the same server provided it meets the install requirements. Generally, you should take advantage of the upgrade process to upgrade the hardware as well. If the same server is used, you will need sufficient disk space to store a duplicate copy of the databases during the upgrade.
Log shipping can also be useful when performing an upgrade. If you have a large database, you can set up log shipping in advance to keep the databases in sync on the new system while the old system is still active. This will keep the downtime to a minimum, since you can keep your system online while you wait for a large data file to copy to a new server. You can copy the database to the new server and perform the upgrade in advance, so the application will only need to be offline while you restore a few transaction logs on the new server. More information about this approach can be found in SQL Server Books Online by searching for the topics “Migrating a SQL Server 2000 Log Shipping Configuration to SQL Server 2008” or “Migrating a SQL Server 2005 Log Shipping Configuration to SQL Server 2008.”
Once you have installed the new instance of SQL Server 2008, there are three methods for moving the databases to the new instance:
Note You will also need to copy any objects outside the database, such as logins and jobs, since you cannot restore system databases to a newer version of SQL Server.
The steps to performing a side-by-side upgrade include the following:
Installing SQL Server 2008 in this side-by-side approach is no different from doing a fresh install (described in Chapter 4). However, with a side-by-side upgrade, you also have to worry about migrating your database afterward. The following sections cover the three ways to perform that migration.
We prefer the detach and attach method when permanently moving databases to a new instance of SQL Server. By moving each file itself instead of a copy of the file at any given point in time, you can be sure you have captured the exact state of the database as it existed on the previous instance. Since the database is detached, it will be inaccessible for any transactions, ensuring that no data will be committed on the old system during the upgrade. Detaching the database also helps to validate that all the connections have been reconfigured to point to the new system. If a connection was missed and is still pointing to the old instance, you will encounter an error instead of actually making a connection that you think is pointing to the new instance.
You can use the sp_detach_db
stored procedure to detach a database. You should also set the database to single-user mode and immediately roll back any transactions before trying to detach the database. Listing 5-1 contains a script invoking sp_detach_db
that you can use to detach a database.
Listing 5-1. T-SQL Script to Detach a Database
USE [master]
GO
ALTER DATABASE [DatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
EXEC master.dbo.sp_detach_db 'DatabaseName'
GO
To attach a database in SQL Server 2008, you should use the CREATE DATABASE
statement with the FOR ATTACH
clause. This statement and clause replace the sp_attach_db
stored procedure that was previously used to attach a database. The sp_attach_db
stored procedure has been deprecated and will be removed in a future release. You will also need to specify the locations of the data files that are going to be attached. The complete syntax for attaching a database is shown in Listing 5-2.
Listing 5-2. T-SQL Script to Attach a Database
USE [master]
GO
CREATE DATABASE [DatabaseName] ON
( FILENAME = N'C:MSSQLDATADatabaseName.mdf' ),
( FILENAME = N'C:MSSQLDATADatabaseName_log.ldf' )
FOR ATTACH
GO
Alternatively, you can detach and attach databases using the GUI in SQL Server Management Studio. To detach a database using the GUI, you can right-click on the database you want to detach, select Tasks, and then select Detach from the context menu. This will bring up the Detach Databases screen. Select OK to detach the database. To attach a database using the GUI, you can right-click on the Databases folder and select Attach from the context menu. This will bring you to the Attach Databases screen. Selecting Add will bring up the Locate Database Files screen, which will allow you to navigate to the data file you would like to attach. Once you have selected the data file, select OK to close the Locate Database Files screen and OK once again on the Attach Databases screen to close the screen and attach the database.
Using the backup and restore method is a good way to copy the database to the new instance without impacting the availability of the current database. All you need to do is take a full backup of the current database, copy that backup to the new location, and restore it (backup and restore will be covered in Chapters 11 and 12). SQL Server will upgrade the database during the restore process. The result will be a SQL Server 2008 database that you will not be able to move back to an earlier release.
Note You won't be able to move a 2008 database back to an earlier release, even when you are running that database in a prior compatibility mode. You cannot back up and restore to go from 2008 to an earlier release, nor can you detach and attach. You can only move a database forward. You cannot migrate backward.
You can use the Copy Database Wizard to provide a user-friendly interface to copy your database to an upgraded instance of SQL Server 2008. You are given the option to make a copy of the database or completely move the database. You may also choose to copy the database by using the detach and attach method, or by using SQL Management Objects (SMO). If you use the detach and attach method from the wizard, make sure there are no users trying to access the database before running the wizard. If you use SMO, the database will remain online during the entire process. You can also choose to move any database-related objects, such as logins and jobs. We should point out that while you can copy logins using the Copy Database Wizard, for security reasons, the wizard creates the login on the destination server with a random password and then disables the login.
Note The Copy Database Wizard creates a SQL Server Agent job that executes an SSIS package. Make sure you have Integration Services installed and the SQL Server Agent running on the destination server prior to executing the Copy Database Wizard.
Use the following steps to upgrade a database using the Copy Database Wizard:
Figure 5-21. Copy Database Wizard Welcome screen
Figure 5-22. Selecting a source server
Figure 5-23. Selecting a destination server
Figure 5-24. Selecting a transfer method
Figure 5-25. Copy Database Wizard database selection
Figure 5-26. Configuring the destination database
Figure 5-27. Select related server objects
Figure 5-28. Select server objects copy options
Figure 5-29. Configuring the package
Figure 5-30. Scheduling the SSIS package
Figure 5-31. Copy Database Wizard completion
Figure 5-32. Copy Database Wizard operation progress
In order to take advantage of everything that SQL Server 2008 has to offer, there are a few steps that need to be taken after an upgrade has occurred. We will discuss each change that needs to be made and explain how it benefits you after the upgrade. Following are the steps that you should perform after any upgrade:
CHECKSUM
The first thing you should do after the upgrade is change the compatibility level of the database, assuming it is supported by the application. We have had some vendors allow us to upgrade the database, as long as we left the compatibility level set to the prior version. When upgrading a database to SQL Server 2008, the database maintains the current compatibility level. In order to take advantage of the new features offered in SQL Server 2008, you should change the compatibility level to SQL Server 2008 (100).
Note If the database compatibility level is below SQL Server 2000 (80), it will be changed automatically to SQL Server 2000 (80) during the upgrade, which is the minimum level supported in SQL Server 2008.
To view the current compatibility level, you can query the sys.databases
catalog view:
Select name, compatibility_level FROM sys.databases
The ALTER DATABASE
command replaces the sp_dbcmptlevel
procedure that was previously used to change the compatibility level. You can also change the compatibility level in the Options tab of the Database Properties dialog box that is displayed by right-clicking the database and selecting Properties.
Run the following statement to change the compatibility level to SQL Server 2008:
ALTER DATABASE [DatabaseName] SET COMPATIBILITY_LEVEL = 100
Caution Changing the compatibility level while the database is currently in use could result in the generation of an incorrect query plan and unpredictable queries. The faulty query plan may also be stored in the cache and used for multiple queries. It is recommended that you change the compatibility level when the database is in single-user mode.
The next thing you should do is run DBCC
commands to test for object integrity. The DBCC CHECKDB
command checks the integrity of the objects in a database and should be run on a regular basis. One thing that this command does not check in databases created in versions prior to SQL Server 2005 is the integrity of the data in the columns. Adding the DATA_PURITY
option causes the CHECKDB
command to look for column values that are invalid or out of range. Any database that was created in SQL Server 2005 or later will include the DATA_PURITY
check by default; but if the database is being upgraded from an earlier version, you must run the command with the DATA_PURITY
option at least once and fix any issues. Once the command has executed successfully and the issues have been resolved, an entry is made in the database header and the DATA_PURITY
option will be included by default as a part of the normal CHECKDB
operation.
The following command should be executed to perform a CHECKDB
with DATA_PURITY
:
DBCC CHECKDB ([DatabaseName]) WITH DATA_PURITY
The DBCC UPDATEUSAGE
command corrects inaccurate row and page counts for tables and indexes. Invalid counts are common in previous versions of SQL Server and can skew the results of certain commands, such as sp_spaceused
. You should always run the UPDATEUSAGE
command on databases that have been upgraded from SQL Server 2000. You do not need to run the command on a regular basis unless frequent Data Definition Language (DDL) modifications are made in the database.
The following command should be executed to update the usage counts for a given database:
DBCC UPDATEUSAGE ([DatabaseName])
When upgrading a database, the PAGE_VERIFY
option will remain the same as it was in the prior version. You should make sure this option is set to CHECKSUM
after the upgrade. The CHECKSUM
option was introduced in SQL Server 2005 and provides the highest level of integrity for the data files. When the CHECKSUM
option is enabled, a checksum of the whole page is computed and stored in the page header when the page is written to disk. When the page is read from disk, the checksum is recalculated and compared with the value in the header.
To view the current PAGE_VERIFY
option, you can query the sys.databases
catalog view:
SELECT name, page_verify_option_desc FROM sys.databases
Use the ALTER DATABASE
command to change the PAGE_VERIFY
option to CHECKSUM
:
ALTER DATABASE [DatabaseName] SET PAGE_VERIFY CHECKSUM WITH NO_WAIT
Updating the statistics after the upgrade allows the database engine to take advantage of the enhancements made in SQL Server 2008 to optimize query performance. The statistics that reside in the database were created with an earlier version of SQL Server. By recreating them with SQL Server 2008, you are allowing SQL Server to create more intelligent statistics to work with. This ultimately results in a better execution plan and faster, more efficient queries.
To update statistics, run the following script against each of the databases that have been upgraded:
USE [DatabaseName]
GO
sp_msforeachtable 'UPDATE STATISTICS ON ? WITH FULLSCAN; '
Several processes and tools are in place to help make your upgrade a success. Using the tools provided, you should be able to find and resolve any issues and conflicts that would prevent a successful upgrade. Understanding all the upgrade options will also prevent costly mistakes during the upgrade. Remember, the best upgrade method depends on the circumstances; what may work for some systems may not be the best strategy for others. Understanding all the available upgrade paths will ultimately lead to a seamless and painless upgrade.
3.14.144.216