Database Administration By Adrienne Watt
The Database Environment’s Human Component Even most carefully crafted database system cannot operate without human component Effective data administration requires both technical and managerial skills DA must set data administration goals DBA is focal point for data/user interaction Need for diverse mix of skills
The Database Environment’s Human Component (continued) Contrasting Data Administrators (DA) with Database Administrator (DBA) Page 616 – in Book
The DBA’s Technical Role Rooted in following areas of operation: Evaluating, selecting, and installing DBMS and related utilities Designing and implementing databases and applications Testing and evaluating databases and applications Operating DBMS, utilities, and applications Training and supporting users Maintaining DBMS, utilities, and applications Tasks varies with the size of the database Page 623
Back up and Restore A backup is a copy of data that can be used to restore and recover the data is called a backup. Backups let you restore data after a failure. With good backups, you can recover from many failures, such as: Media failure. User errors, for example, dropping a table by mistake. Hardware failures, for example, a damaged disk drive or permanent loss of a server. Natural disasters. Backups of a database are useful for routine administrative purposes, such as copying a database from one server to another, setting up database mirroring, and archiving.
Backups continued Can be a whole database, a partial database, or a set of files or filegroups. Full backup - contains all the data in a specific database Differential backup Based on the latest full backup of the data http://msdn.microsoft.com/en-us/library/ms187048.aspx
Backup Under the Simple Recovery Model Sample Backup Strategy Under the simple recovery model, the transaction log is automatically truncated to remove any inactive virtual log files. Truncation usually occurs after each checkpoint but can be delayed under some conditions.
Backup Under the Simple Recovery Model Work-Loss exposure http://msdn.microsoft.com/en-us/library/ms191164.aspx Reduced Work-Loss exposure
Database Backup - TSQL BACKUP DATABASE database TO backup_device [ ,...n ] [ WITH with_options [ ,...o ] ] ; Option Description database Is the database that is to be backed up. backup_device [ ,...n ] Specifies a list of from 1 to 64 backup devices to use for the backup operation. You can specify a physical backup device, or you can specify a corresponding logical backup device, if already defined. To specify a physical backup device, use the DISK or TAPE option: { DISK | TAPE } = physical_backup_device_name WITH with_options [ ,...o ] Optionally, specifies one or more additional options, o. Ie. compression, description, name, format
How to: Create a Full Database Backup (Transact-SQL) example The following example backs up the complete Pubs database to disk USE Pubs; GO BACKUP DATABASE Pubs TO DISK = 'Z:\SQLServerBackups\Pubs.bak' GO http://msdn.microsoft.com/en-us/library/ms179313.aspx
Backup Under the Full Recovery Model Uses log backups to prevent data loss Backing and restoring the transaction log is required Allows you to restore a database to any point of time that is contained within a log backup http://msdn.microsoft.com/en-us/library/ms190217.aspx
Backup Under the Full Recovery Model Minimize Work Loss exposure http://msdn.microsoft.com/en-us/library/ms190217.aspx
Restoring Process of copying data from a backup and applying logged transactions to the data to roll it forward to the target recovery point. Roll Forward Process of apply logged changes to data in a database The phases of Restore Data copy Redo Undo http://msdn.microsoft.com/en-us/library/ms191253.aspx http://msdn.microsoft.com/en-us/library/ms191455.aspx
Restore Con’t Data Copy Phase Redo (Roll Forward) Phase Initializes the contents of the database Copies data from one or more full backups Redo (Roll Forward) Phase Returns the data to its original state at the recovery point Undo (Roll Back) Phase Uncommitted transaction are not consistent with database, they must be rolled back This phase could be skipped http://msdn.microsoft.com/en-us/library/ms191455.aspx
Restoring a Full Database Backup 1. Execute the RESTORE DATABASE statement to restore the full database backup, specifying: The name of the database to restore. The backup device from where the full database backup is restored. The NORECOVERY clause if you have a transaction log or differential database backup to apply after restoring the full database backup. 2. Optionally, specify: The FILE clause to identify the backup set on the backup device to restore. http://msdn.microsoft.com/en-us/library/ms189895.aspx
Restore (Transact-SQL) Restores backups taken using the BACKUP command. Example: Restoring a full database The following example restores a full database backup from the disk device. RESTORE DATABASE Pubs FROM DISK = 'Z:\SQLServerBackups\Pubs.bak'
Transaction Log Backup Only for databases that are using the full recovery model Important to take routine backps of transaction logs First create a full backup Minimizes work-loss exposure Enables truncation of the transaction log Transaction log is truncated after every log backup Frequency of log backups depends on: your tolerance for work-loss exposure How many log backups you can store, manage, and restore Routinely back up your data to limit the number of log backups needed to restore http://msdn.microsoft.com/en-us/library/ms190440.aspx
The Log Chain A continuous sequence of log backups Starts with a full backup Log chain remains intact Unbroken sequence of transaction log backups must extend up to the point of failure Database or Partial backup Sequence of log backups must extend from the end Restoring a log backup rolls forward the changes that were recorded in the transaction log http://msdn.microsoft.com/en-us/library/ms190440.aspx
Sequence of Log Backups Time Event 8:00 A.M. Back up database. Noon Back up transaction log. 4:00 P.M. 6:00 P.M. 8:00 P.M. http://msdn.microsoft.com/en-us/library/ms191429.aspx
How to Create a Transaction Log backup Execute the BACKUP LOG statement to back up the transaction log, specifying the following: The name of the database to which the transaction log that you want to back up belongs. The backup device where the transaction log backup is written. Optionally, specify: The INIT clause to overwrite the backup media, and write the backup as the first file on the backup media. If no existing media header exists, one is automatically written. The SKIP and INIT clauses to overwrite the backup media even if there are either backups on the backup media that have not yet expired, or the media name does not match the name on the backup media. The FORMAT clause, when you are using media for the first time, to initialize the backup media and rewrite any existing media header. The INIT clause is not required if the FORMAT clause is specified. http://msdn.microsoft.com/en-us/library/ms191284.aspx
Transaction Log Backup Example To permit log backups, before taking a full database backup, the database was set to use the full recovery model by using: ALTER DATABASE Pubs SET RECOVERY FULL;. BACKUP LOG Pubs TO Pubs_Log; GO This example creates a transaction log backup for the Pubs database to the previously created named backup device, Pubs_log. http://msdn.microsoft.com/en-us/library/ms191284.aspx
Restore to the Point of Failure Example Check the site: http://msdn.microsoft.com/en-us/library/ms175093.aspx For an in depth discussion on restoring to the point of failure. RESTORE: http://msdn.microsoft.com/en-us/library/ms186858.aspx