If your business environment requires that the production server always be accessible, you may want to consider using a standby SQL Server. This lesson describes how to set up and use a standby SQL Server as well as how to restore the production server once the problem has been resolved. This lesson also introduces the use of clustering in the Enterprise Edition of SQL Server.
After this lesson, you will be able to
- Set up a standby SQL Server computer and restore a production server
Estimated lesson time: 30 minutes
If you determine that a standby SQL Server is appropriate for your business environment, you must decide on its purpose and then create and maintain it.
NOTE
In previous versions of SQL Server, a standby server was implemented by setting the no chkpt. on recovery option to true for databases on the standby server. This database option is no longer supported in SQL Server 7. The RECOVERY, NORECOVERY, and STANDBY options of the RESTORE statement now provide this functionality.
A standby SQL Server is a second server that mirrors the production server. You can use a standby SQL Server to replace a production server in case of a failure or to provide a read-only copy of one or more databases for decision support applications. In addition, a standby server can be used to validate database integrity by running the Database Consistency Checker (DBCC) without increasing the load on the primary server.
Create a standby SQL Server by backing up the databases and transaction logs on the production server and then restoring them to another SQL Server, using the STANDBY option with the RESTORE statement.
When you restore backups to a standby SQL Server, consider the following facts and guidelines:
Do not recover the database until you replace the production server with the standby SQL Server.
TIP
An alternative to restoring the databases when initially creating them on the standby server is to copy database files from one server to another and then attach them to the standby server by using either the sp_attach_db or sp_attach_single_file_db system stored procedure.
The syntax for the RESTOREstatement is as follows:
RESTORE {DATABASE | LOG}{database_name | @database_name_var} FROM <backup_device> [, ...n] [[,] MOVE 'logical_file_name' TO 'operating_system_file_name'] [WITH NORECOVERY | RECOVERY | STANDBY = undo_file_name}] ] |
The STANDBY option specifies the name of an undo file. This file contains the information used to define the state of the database before transactions in an unknown state are rolled back. This allows the database to be available for read-only operations before a recovery has been performed to fully recover the database.
Be aware of the following when specifying the undo file.
The following example restores a database backup and a transaction log backup to a standby server. The database on the standby server is available in read-only mode, and additional transaction logs can be applied. This example assumes that the standby server and production server use the same locations for the database files.
USE MASTER RESTORE DATABASE nwcopy FROM nwcomplete WITH STANDBY = 'c:\mssql7\standby\nwundo.ldf' RESTORE LOG nwcopy FROM nwlogbackup WITH STANDBY = 'c:\mssql7\standby\nwundo.ldf' |
To maintain the standby SQL Server, you must regularly restore all additional transaction log backups to it. Restoring transaction logs ensures that the standby SQL Server is consistent with the production server. Consider the following facts and guidelines when you maintain a standby SQL Server:
The standby SQL Server can function as a read-only copy of the production server, reducing the amount of activity on the production server. Using the standby SQL Server in this way has the following additional advantages:
Another use for a standby SQL Server is to determine the point at which a database became corrupted. You can use the STANDBY option to review the contents of the database for corruption or bad data as each transaction log backup is applied.
The following steps illustrate how to troubleshoot data corruption:
You will typically use a standby SQL Server as a replacement for a production server to minimize down time. Follow these steps to bring a standby SQL Server on line to replace a production server:
If the standby SQL Server has been used as a read-only server and you do not have additional transaction logs to restore, perform a manual recovery on the standby SQL Server by executing the RESTORE DATABASE WITH RECOVERY statement. At this point, the standby SQL Server is recognized as the production server.
You will typically restore the production server after the problem is resolved. To restore the production server, you must perform the following steps:
Clustering describes using multiple Windows NT Servers to provide increased reliability and capacity. Clustering is available in the Enterprise Edition of SQL Server running on Windows NT Enterprise Edition. In a clustered installation of SQL Server, clients connect to a virtual server, instead of connecting to an actual Windows NT Server as is done with a typical installation of SQL Server. Virtual servers appear externally to be regular Windows NT Servers when they are in fact a group of servers working together. The servers in a cluster monitor each other's status. If an application failure is due to a server failure, another server takes over. This process is known as failing over, or failover.
In a mission-critical environment where high availability of SQL Server databases is required and a Windows NT Server Enterprise Edition cluster is available, the Enterprise Edition of SQL Server installed with failover support provides the most scalable and reliable solution. For more information about clustering see Books online "Configuring SQL Server Failover Support"
You can use a standby SQL Server to replace a production server in case of a failure or to provide a read-only copy of one or more databases for decision support applications. In addition, a standby server can be used to validate database integrity by running the Database Consistency Checker (DBCC) without increasing the load on the primary server. The Enterprise Edition of SQL Server can be run on a Windows NT Server Enterprise Edition cluster.