Presentation is loading. Please wait.

Presentation is loading. Please wait.

Danny Tambs – Senior Consultant Microsoft.

Similar presentations


Presentation on theme: "Danny Tambs – Senior Consultant Microsoft."— Presentation transcript:

1

2 Danny Tambs – Dannyt@microsoft.com Senior Consultant Microsoft

3 Session Objective(s): Overview of Partial Database Availability Demonstrate Recovery Methods Key Takeaways Partial database availability can shorten downtime when a failure occurs. Partial DB should be designed in from project start. Demos Recovery of a R/O Filegroup. Recovery of a R/W Filegroup.

4 Enables a database to be brought online fast after a disaster when one or more Filegroups are lost. Enables a given database to be quickly restored and brought online while other missing data can be restored later. Eg: Large OLTP database with small amount of transaction supporting data but huge volumes of history data.

5 VLDB systems Typically over 1 TB since the time to restore the whole database means significant downtime. Solutions using multiple filegroups where the main application functionality resides in small No.# of filegroups. Eg: An OLTP database with a relatively small amount of working data but a proportionaly huge amount of historical data. Not meant as a substitute for a sound backup strategy.

6 1. After the database fails examine error log to determine the physical filename that failed to load. Error : 17207, Unable to open the physical file "C:\Data\MyFG_Database3_1_sec.ndf". Operating system error 2: "2(error not found)". 2. Determine the logical filename that the physical filename maps to by querying the system catalog. 3. Alter Database - set the logical filename to offline 4. Alter Database - set Database to online 5. DATABASE NOW ONLINE ! Continue operating with Partial Availability. 6. Restore Missing filegroup(s) as time permits. 7. Restore Tran Log & recover DB if read/write filegroup. 8. Database now fully Online.

7 ALTER DATABASE MYDB SET ONLINE GO PrimaryFG1FG2 File1mdfFile1mdfFile2ndfFile2ndfFile3ndfFile3ndfFile4ndfFile4ndf File5ldfFile5ldf Arrays 123 Database = ONLINE Database = OFFLINE ALTER DATABASE MYDB MODIFY FILE (NAME=‘LOGICAL FILE4’, OFFLINE) GO BACKUP LOG MYDB TO DISK=‘…FILE’ GO RESTORE DATABASE MYDB FILE=‘LOGICAL FILE4’ FROM DISK WITH FILE=1, NORECOVERY GO RESTORE LOG MYDB FROM DISK =‘…FILE’ WITH RECOVERY GO FilegroupOFFLINEFilegroupOFFLINE Fix HW Issue Database = ONLINE - PARTIAL Database cannot be opened Command: Status:

8 Partial command under SQL2000 was less flexible. Nothing to do with setting a file offline and bringing the DB Online. Used to restore a file group to a different location to recover lost data. Needed to restore the mdf file as well as required file group. Once the database was brought online any unrestored filegroups could not be restored. Could not really be used to bring a database online quickly in order to reduce downtime.

9 Many Enhancements. SQL 2005 – we can now set a file to OFFLINE and bring database ONLINE. Unaffected file groups are still available for read/write operations. Commands against online file groups will execute. Only Commands against offline file groups will fail. Typical Errors: 945, 8653, 17207, 5120, 17204 Piecemeal restore - Unrestored filegroups can now be restored at a later time.

10 ALTER DATABASE database_name MODIFY FILE ( NAME = logical_file_name [, OFFLINE ] ) EG: ALTER DATABASE MyFG_Database MODIFY FILE (NAME = 'MyFG_Database3_sec', OFFLINE) *Set the unavailable file offline to be able to set the database online.

11 ALTER DATABASE database_name SET ONLINE EG: ALTER DATABASE MyFG_Database SET ONLINE *Once unavailable files are to OFFLINE use this command to set the database to online state.

12

13 Must specify PARTIAL in the 1 st restore of the sequence. RESTORE DATABASE DB_name FROM DISK =... WITH PARTIAL Involves a series of restore sequences, starting with the primary filegroup. Can also restore one or more secondary filegroups when restoring the primary. After the restore sequence is finished recovered files can be brought online directly. Other Files can be restored while the database is online. SQL Server 2005 Enterprise Edition only.

14 RESTORE DATABASE database_name FROM DISK = physical_filename [WITH, PARTIAL] EG: RESTORE DATABASE [MyFG_Database] FILEGROUP='Primary' FROM DISK = N'C:\...\F1_backup.bak' WITH PARTIAL Used for piecemeal restore of MDF and NDF files. When Completed, DB is online.

15 Can be ONLINE or OFFLINE Offline – All Editions Online – SQL Enterprise Edition Only Offline piecemeal restore The database is online after the partial-restore Filegroups that have not yet been restored remain offline, but can be restored as needed after taking the database offline. Online piecemeal restore After the partial-restore sequence, the database is online, and the primary filegroup and any recovered secondary filegroups are available (ONLINE). Other Filegroups to be restored are offline, but can be restored as needed while the database remains online.

16 Works with all recovery models. Recovery ModelNotes Simple Recovery-Any as yet unrestored read/write filegroups cannot be restored. (No Tran Log) - Only Read only Filegroups can be restored Full and Bulk Logged-Any as yet unrestored read/write filegroups can be restored. -Transaction Log must be restored to make the DB consistent.

17 Use sys.master_files system catalogue view. Uses data in Master DB. EG. SELECT name FROM sys.master_files WHERE physical_name = ‘Physical Name‘ Logical files – known within SQL Physical names – The file on the disk Get From Error log

18 Get information about the DB files, sizes and if Read only or / Read Write. Use to easily find file to set offline. SELECT s.data_space_id as Id, g.name as Filegroup_name, s.name as Logical_name, physical_name, g.is_default AS [IsDefault], g.is_read_only AS [ReadOnly], CAST(ISNULL((select sum(gs.size)*convert(float,8) FROM sys.database_files gs WHERE gs.data_space_id = g.data_space_id), 0) AS float) AS [Size] FROM sys.filegroups AS g INNER JOIN sys.master_files AS s ON (s.data_space_id = g.data_space_id) WHERE s.type = 0 AND s.database_id = db_id() AND (s.drop_lsn IS NULL)

19 Use sys.database_files Catalog View. Determine if a file is online EG: SELECT File_id, is_read_only, -- Is this Readonly? state_desc, -- Either Online or Offline. name -- Logical Filename FROM sys.database_files

20

21 Queries against an offline filegroup will fail. REASONS Joining to tables are that not available. Tables with DRI against tables on offline filegroups. Triggers referring to unavailable tables. Partitioned Tables - where a required partition is offline. - Group related schema Functionality in related filegroups. Note :Functions and procedures are still in PRIMARY filegroup

22 Detect if a table is unavailable We know the table we want but what if the file is unavailable? Only use in filegroup to filegroup query cases. Ie boundary conditions. Use function. IsAvailable(@Schema, @Objname) Specify schema name, object_name to determine if the table is available. This is sample code and does not ship with SQL server 2005 Get the code from the white paper http://www.microsoft.com/technet/prodtechnol/ sql/bestpractice/pdbavail.mspx

23 SELECT sysob.object_idAS [ObjectId],schm.[name]AS SchemaName,sysob.[name]AS ObjectName,sysdbf.nameAS [LogicalName]-- = LOGICAL FILE NAME,sysdbf.physical_name AS [PhysicalName]-- = PHYSICAL FILE NAME,sysdbf.state_descAS [FileGroupState]-- = FILE GROUP ONLINE/OFFLINE ETC.,sysdbf.STATE FROM sys.indexes AS i INNER JOIN sys.data_spacesAS ds ON i.data_space_id = ds.data_space_id INNER JOIN sys.objectsAS sysob ON i.object_id = sysob.object_id INNER JOIN sys.database_filesAS sysdbf ON (ds.data_space_id = sysdbf.data_space_id) INNER JOIN sys.schemasAS schm ON sysob.schema_id = schm.schema_id WHERE sysob.type= 'U' AND is_ms_shipped= 0 AND sysdbf.type= 0 AND sysdbf.drop_lsn IS NULL Understand what tables are affected if a file is offline.

24 Setting a file to OFFLINE is a one way operation. Must restore to make online. When restoring a missing filegroup by using offline restore the database is unavailable for user interaction. Only Secondary files (*.ndf) can be set to OFFLINE state. Queries against OFFLINE filegroups will fail. Setting a file in a filegroup to OFFLINE affects the entire filegroup.

25 Keep your *.mdf files as small as possible. Makes the first mdf restore faster. Keep your minimal functionality to be online in the MDF for fast initial restore. (critical tables, procs, Functions, reference tables.) Restore other FG later. Backup the DB transaction logs often. Record the mapping of logical to physical file names. Have a clear and well rehearsed partial DB recovery plan.

26 Whitepaper – Partial Database Availability http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/pdbav ail.mspx Customer Advisory Team Blog Site http://blogs.msdn.com/sqlcat/archive/2005/10/27/how-can-sql- server-2005-online-piecemeal-restore-improve-availability.aspx MSDN http://msdn2.microsoft.com/en-us/library/ms177425.aspx

27

28 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.


Download ppt "Danny Tambs – Senior Consultant Microsoft."

Similar presentations


Ads by Google