Tuesday, 27 October 2015 00:00

SQL FAQ – How Does A Page Level Restore Improve SQL Server Recovery Provisions?

Rate this item
(0 votes)

For very large Microsoft SQL Server databases, a complete restore operation can take many hours. During this time the database cannot be used to prevent data being entered and lost as information is copied back from tape or disk. Obviously in a high-availability environment any downtime is costly, so keeping it to a minimum is essential.

Fortunately page level restore techniques can be used to keep recovery times to a minimum by reducing the amount of data that needs to copied back from the backup media. Since the release of Microsoft SQL Server 2005, DBAs have had the option of carrying out a ‘page level restore’ which allows them to recover a ‘handful’ of pages, rather than having to restore entire datasets and copy information back into the original database.

The page level restore operation is perfect for situations where data becomes corrupted during writes through a faulty disk controller, misconfigured antivirus software or an IO subsystem. Better still, restore level operations can be performed online for Enterprise editions of Microsoft SQL Server.

Prerequisites

As with any database recovery operation, page level restores are reliant on having a complete backup from which to work. If such a backup is not available, you will need to investigate an alternative method of recovering data from the server disks direct.

And although you can carry out the page level restore with the database online, you may decide to keep things safe by switching to single user mode whilst you transfer data using:

ALTER DATABASE <DBName> SET SINGLE_USER
WITH ROLLBACK AFTER 10 SECONDS
GO

This command ensures that everyone is out of the system and cannot enter until you change the mode back again. You will also want to ensure that you have the end of the log file backed up so that you have all transactions fully accounted for and to prevent any further data loss:

BACKUP LOG DBName
TO DISK = N'X:\SQLBackups\DBName_TailEnd.trn'
GO

Discovering which pages are corrupt

Usually the first sign that something is wrong will be an inconsistency error generated when a select statement is executed. The Microsoft SQL Server Messages pane will show an error like:

Msg 5242, Level 22, State 1, Line 1
An inconsistency was detected during an internal operation in database ‘DBName’(ID:9) on page (1:254).
Please contact technical support. Reference number 4.
As you would expect, the page number referenced, 254, is the corrupt page that needs to be recovered.

Carrying out a page level SQL Server recovery

The Microsoft SQL Server page recovery operation is very similar to that of a full recovery, the only difference being the use of the NORECOVERY command:

RESTORE DATABASE DBName
PAGE = 'fileid:pageid'  -- e.g. 1:254
FROM DISK = 'X:\SQLBackups\DBName_lastFull.BAK'
WITH
NORECOVERY
GO

This will the re-insert the corrupted page from backup without going through the time-consuming process of a full SQL Server recovery. You can recover more than one page at a time simply by appending additional fileid:pageid combinations separated by commas.

You can test that the data has been recovered successfully by running DBCC CHECKDB on the affected database – it should complete without error.

Finishing up the page level SQL Server recovery

Although the corrupt page has been recovered successfully, you will also need to apply the transaction logs to ensure that all data is present and correct. For each transaction log generated since your last full backup, run the RESTORE LOG command:

RESTORE LOG DBName
FROM DISK = 'X:\SQLBackups\DBName_LogFileFrom2PM.TRN'
WITH NORECOVERY
GO
RESTORE LOG DBName
FROM DISK = 'X:\SQLBackups\DBName_LogFileFrom215PM.TRN'
WITH NORECOVERY
GO

Again, note the NORECOVERY option will ensure that you restore nothing but the specified log files. Finally you need to apply the tail log backup taken in the Prerequisites section above:

RESTORE LOG DBName
FROM DISK = 'X:\SQLBackups\DBName_TailEnd.trn
WITH RECOVERY

This time you do want to recover the database, hence the WITH RECOVERY command.

At this point you can re-test the database to ensure that everything is working as it should. Once you are satisfied, switch the database back to multi-user mode to restore access for your users:

ALTER DATABASE AdventureWorks SET MULTI_USER
GO

And there you have it, corruption problems resolved without having to undergo a full SQL Server recovery. The page level restore option ensures that downtime and user inconvenience is kept to a minimum, as are the costs associated with a database outage.

Reference :http://blog.krollontrack.co.uk/concepts-explained/sql-faq-how-does-a-page-level-restore-improve-sql-server-recovery-provisions/

Last modified on Tuesday, 27 October 2015 10:57
Data Recovery Expert

Viktor S., Ph.D. (Electrical/Computer Engineering), was hired by DataRecoup, the international data recovery corporation, in 2012. Promoted to Engineering Senior Manager in 2010 and then to his current position, as C.I.O. of DataRecoup, in 2014. Responsible for the management of critical, high-priority RAID data recovery cases and the application of his expert, comprehensive knowledge in database data retrieval. He is also responsible for planning and implementing SEO/SEM and other internet-based marketing strategies. Currently, Viktor S., Ph.D., is focusing on the further development and expansion of DataRecoup’s major internet marketing campaign for their already successful proprietary software application “Data Recovery for Windows” (an application which he developed).

78 comments

  • Comment Link Carlton Friday, 30 March 2018 22:21 posted by Carlton

    Sands corners and edges of hardwood flooring.

  • Comment Link Zachery Wednesday, 28 February 2018 21:19 posted by Zachery

    I love your blog.. very nice colors & theme. Did
    you create this website yourself or did you hire someone to do it for you?
    Plz reply as I'm looking to create my own blog and would
    like to find out where u got this from. cheers

  • Comment Link Jonah Thursday, 22 February 2018 05:51 posted by Jonah

    Discover Boats for Sale, Yachts for Sale and More!

  • Comment Link Lurlene Wednesday, 21 February 2018 00:06 posted by Lurlene

    We provide free estimates for all of our services.

  • Comment Link Richie Tuesday, 20 February 2018 20:55 posted by Richie

    Las Vegas window cleaning by J & J Window Wash.

  • Comment Link Wesley Tuesday, 20 February 2018 05:18 posted by Wesley

    This article is truly a pleasant one it assists new web users, who are wishing for blogging.

  • Comment Link Reina Tuesday, 20 February 2018 00:43 posted by Reina

    We assure our cleaners will always be on time.

  • Comment Link Sabine Monday, 19 February 2018 09:18 posted by Sabine

    Typically much less is more with pressure washing.

  • Comment Link Kory Monday, 19 February 2018 06:58 posted by Kory

    And, maids used to must put on a traditional uniform.

  • Comment Link Lisa Sunday, 18 February 2018 12:52 posted by Lisa

    Then call a storage door opener repair company.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.