Depending on the environment, the upgrade to SQL
Server 2008 can be complex, particularly when technologies such as
replication and clustering are involved. In this section, rather than
attempt to cover all of the possible upgrade issues, I've aimed for the
more modest task of providing you with an insight into the various
upgrade techniques.
Depending on the
availability of spare hardware and the allowed downtime, you can choose
one of two upgrade techniques. The first is known as an in-place
upgrade, in which an entire instance of SQL Server 2000 or 2005 along
with all of its databases are upgraded in one action. Alternatively, you
can use the side-by-side
technique, in which individual databases can be migrated one at a time
for more control. Both of these techniques have their advantages and
disadvantages, as you'll see shortly.
Before we look at the
details of in-place versus side-by-side, let's discuss the importance of
analyzing the target database/instance before upgrading by using SQL
Server's Upgrade Advisor tool.
1. Upgrade Advisor
Each new
version of SQL Server contains behavioral changes, some major, some
minor. In any case, even small, subtle changes can significantly impact
application behavior. Regardless of the upgrade technique, a crucial
step in preparing for an upgrade to SQL Server 2008 is to analyze the
upgrade target and determine whether any issues require attention.
Together with the appropriate upgrade technique, such analysis is
essential in minimizing unexpected issues, making the upgrade process as
smooth as possible.
SQL Server 2008, like
2005, includes an Upgrade Advisor tool, which you can use to examine
existing 2000 and/or 2005 instances to determine whether any issues will
prevent an upgrade from completing (blocking issues) or
backward-compatibility issues that may lead to application failure after
the upgrade. The Upgrade Advisor tool can be used to examine all SQL Server components, including Analysis
Services, Reporting Services, Integration Services, and the core
database engine itself.
The Upgrade Advisor has
two main components: an analysis wizard and a report viewer. Use the
wizard to select an upgrade target (SQL Server components, instances,
and databases) and begin the analysis. Once complete, the report viewer
can be used to view the details of the analysis, as shown in figure 1.
Like the 2005
version, the Upgrade Advisor tool can analyze trace files and
Transact-SQL (T-SQL) scripts. You perform this analysis as a proactive
measure to identify possible issues with application-generated data
access code or T-SQL scripts, such as backup scripts used in scheduled
maintenance plans.
Running the Upgrade
Advisor produces a list of tasks that fall into two categories: those
that must be completed before an upgrade can be performed, and those for
attention once the upgrade is complete. Rather than list all of the
possible post-upgrade tasks, here are the recommended ones for the core
database engine:
Compatibility level check—Post-upgrade, the compatibility level
of the database is left at the pre-upgrade version. Although this is
advantageous in minimizing the possibility of applications breaking due
to the use of older language syntax that's no longer compatible with SQL
Server 2008, some new functionality and performance optimizations won't
be available until the new compatibility level is applied. Leaving an
upgraded database at a previous compatibility level should be seen as an
interim migration aid, with application code updated as soon as
possible after installation. You can change the compatibility level of
an upgraded database using the sp_dbcmptlevel stored procedure, or via the database properties in Management Studio, as shown in figure 2.
Max Worker Threads—If you're upgrading from SQL Server 2000, is kept at the default value of 255. After the upgrade, change this
value to 0, which allows SQL Server to determine the appropriate value
based on the number and type of CPUs available to the instance.
Statistics update—Although
SQL Server 2008 can work with statistics generated from earlier
versions, I recommend you perform a full statistics update to take
advantage of the query optimizer improvements in SQL Server 2008.
Configuration check—Like 2005, SQL Server 2008 complies with the secure by default installation mode, whereby certain features are disabled upon installation. Depending on the installation, certain required features may need to be manually enabled postinstallation.
DBCC UPDATEUSAGE—Databases upgraded from SQL Server 2000 may report incorrect results when using the sp_spaceused procedure. Running the UPDATEUSAGE command will update the catalog views used by this procedure, thus fixing this inaccuracy.
Before looking at
the upgrade methods, note that regardless of the method you choose,
performing a test upgrade is crucial in identifying possible issues.
Test upgrades provide an opportunity to
Determine the length of the upgrade process, crucial in planning downtime for the real upgrade.
Determine
application behavior after the upgrade. This will allow you to set the
database compatibility level to SQL Server 2008 and ensure applications
work as expected.
Performance-test
applications on the upgraded database. If performance is poor, a test
upgrade provides a chance of investigating the reasons prior to the
production upgrade.
Last
but not least, complex upgrades involving components such as
replication are certainly not something you want to be doing the first
time in production!
So, with these points in mind, let's take a look at the two upgrade methods, starting with the in-place method.
2. In-place upgrade
The in-place
upgrade method upgrades an instance, and all of its databases, in a
single irreversible action. For simple, small database instances, it
provides the easiest and quickest upgrade method and has the following
additional benefits:
Applications
connecting to any of the databases don't need modification. The
instance name remains the same (if upgrading from a named instance), so
no connection strings need to be changed.
No additional hardware is required. The instance executables and data are changed in place.
Despite these benefits, there are some significant downsides to this method, making it unsuitable for a range of scenarios:
All of the
instance's databases have to be upgraded at once. There's no option to
upgrade only some. If one of the databases (or its applications) needs
modification before upgrading, then all of the other instance databases
will have to wait before the upgrade can proceed.
A
failed upgrade, or one that produces unexpected results, can't be
rolled back, short of running up new hardware and restoring old backup
files, or using a virtualization snapshot rollback process.
Because the rollback
options are limited with this method, it's critical that you complete a
full backup and DBCC check on all databases before beginning the
upgrade. If database activity occurs after the full backup, make
transaction log backups immediately prior to the upgrade.
To begin the
in-place upgrade, select Upgrade from SQL Server 2000 or SQL Server 2005
from the Installation menu of the SQL Server Installation Center.
For greater control of the upgrade process, you can choose one of several side-by-side upgrade methods.
3. Side-by-side upgrade
In contrast to an in-place upgrade, which upgrades all databases for a given instance, a side-by-side upgrade is a per database method:
A SQL Server 2008 instance is installed as a new
installation (compared to an upgrade). The new instance can be
installed on either the same server as the instance to be upgraded
(legacy instance), or on a new server.
Each
database to be upgraded is migrated from the legacy instance to the new
2008 instance, using one of several methods I'll describe shortly.
Databases are migrated individually on their own schedule, and possibly
to different destination servers.
Once
the new 2008 instance is up and running, the legacy instance is
decommissioned, or retained in an offline state for rollback purposes if
required.
The
side-by-side upgrade method offers several advantages over the in-place
method. The major advantage is that if something goes wrong with the
upgrade, or unexpected results render the upgrade a failure, the legacy
instance is still available and unchanged for rollback purposes.
Further, the upgrade is granular; individual databases can be migrated
with others remaining on the original server, migrated to a different
server, or migrated at a later point.
Disadvantages and complexities of this method when compared to the in-place method are as follows:
Application connection strings will need to be modified to point to the new instance name.
Security
settings, maintenance plans, and SQL Server Agent jobs will need to be
re-created on the new 2008 instance, either manually or from a script.
If
the new 2008 instance is on the same server as the legacy instance, the
capacity of the server to run both instances in parallel must be taken
into account. A possible workaround for this issue is to limit the
resources of one of the instances, such as the maximum memory and CPU
affinity, for the period of time that both are actively running.
Downtime
is typically longer than for an in-place method; there are several
techniques used to limit this.
Side-by-side upgrades are
often scheduled for the same time as server replacements—that is, the
new server is purchased, installed, configured, and loaded with a new
instance of SQL Server 2008, and databases are migrated from the legacy
instance. At the completion of this process, the legacy server is
decommissioned, cycled back to lower environments, or used for other
purposes.
The method used to migrate
databases as part of a side-by-side upgrade is an important
consideration in determining the rollback and downtime implications for
the upgrade, particularly for larger databases. Let's walk through the
major methods used, beginning with backup/restore.
Backup/restore
The backup/restore
method is straightforward and keeps the original database in place for
rollback purposes. A full database backup is made on the legacy database
and restored to the new SQL Server 2008 instance. As part of the
restore process, SQL Server will upgrade the internal structures of the
database as necessary.
Attach/detach
The attach/detach
method involves detaching the legacy database and attaching to the new
2008 instance. Similar to a restore, SQL Server will upgrade the
internal structure as part of the attach process. To keep the original
database available for rollback, you can copy the database files to the
new server before attaching them to the new 2008 instance. After the
copy is complete, the database can be reattached to the legacy instance
for rollback purposes if required.
Transaction log backup/restore
Depending on the size of
the database to be migrated, the time involved in copying either the
data files or backup files in the previous two methods may exceed the
downtime targets. For example, if the backup file was hundreds of
gigabytes and had to be copied over a slow network link, the copy could
take many hours to complete. To reduce downtime, a third method can be
used involving transaction log backups. This method is similar to
setting up log shipping and involves these steps:
A
full database backup of the legacy database is taken and copied to the
new SQL Server 2008 instance. The legacy database remains online and in
use throughout the copy process.
The legacy database is restored on the new 2008 instance WITH NORECOVERY.
Finally,
at the moment of migration, users are disconnected from the legacy
database, and a transaction log backup is made and copied to the 2008
instance.
The transaction log backup is restored WITH RECOVERY.
At this point, application connection strings are redirected to the 2008 instance and users are reconnected.
There are several
variations of this method. If the transaction rate is very high, the
size of the transaction log backup in step 3 may be very large; if so,
regular transaction log backups can be made leading up to this step,
reducing the size (and therefore copy time) of the final transaction log
backup. If using this method, restore all but the last of the
transaction log backups WITH NORECOVERY.
Transactional replication
This method is similar to the transaction log backup/restore but involves replication:
Transactional replication is set up from the legacy instance to the new 2008 instance.
At the moment of migration, replication is stopped and applications are redirected to the new 2008 instance.
Optionally,
replication can then be set up in the reverse direction to support a
rollback scenario—that is, data entered on the new 2008 instance
post-migration is copied to the legacy database instance to prevent data
loss in the event of a rollback.
Other techniques
Other migration techniques include using the Copy Database wizard
(in Management Studio, right-click a database and choose Tasks >
Copy Database) and manually creating the database on the new 2008
instance from script and performing bulk copy operations.
Table 1 compares the attributes of the various upgrade techniques.
Table 1. Upgrade options compared
Upgrade technique | Complexity | Rollback options | App reconfig | Downtime |
---|
In-place | Lowest | No | No | Lowest |
Side-by-side | | | | |
—Backup/restore | Medium | Yes | Yes | Highest |
—Detach/copy/attach | Medium | Yes | Yes | Highest |
—Filegroup restore | Medium | Yes | Yes | Moderate |
—T-Log backup/restore | Medium | Yes | Yes | Lowest |
—Transaction replication | Highest | Yes | Yes | Lowest |
The side-by-side upgrade
method offers much more flexibility and granularity than the
all-or-nothing in-place approach. In all cases, regardless of the
upgrade method, planning is crucial for a successful upgrade.