Você está na página 1de 1

SQL Q&A I/O Errors, Database Mirroring, and More Paul S.

Randal

Q I've started running regular consistency checks on the databases that I manage, and I've even added some SQL Agent alerts to catch any I/ errors that user !ueries encounter. I don't kno" i# the logic I've im$lemented around the checks and alerts "ill "ork because none o# my databases have corru$tion issues. %o" can I create some corru$tion in a test database so I can make sure everything I've set u$ "orks correctly& Also, is there anything else I should do to detect I/ errors& A In SQL Server' ())), the old trick to create a corru$t database #or testing "as to manually delete a ro" #rom the sysinde*es table o# a test database. +ut "ith SQL Server ()),, corru$ting a system table in such a manner is very di##icult. -he best "ay to corru$t a test database yoursel# is to use a he* editor to alter a data #ile "hile the database is shut do"n. %ere's "hat to do.

Shut do"n the database so the data #iles are not locked. /+e care#ul that you don't detach the database, though, because i# you corru$t the "rong $age, you may not be able to attach it again.0 Pick an o##set more than, say, 1)) $ages into the #ile /at least 213()) bytes0, but make sure it's aligned on an 213(4byte boundary /a $age boundary0. -his avoids critical metadata $ages and allocation bitma$s, letting you start the database and run 5+66 6%7685+ on it.

9rite a #e" bytes o# :eroes into the #ile at the chosen o##set. ;sing this techni!ue is almost guaranteed to introduce some $age header corru$tion errors. -hat said, the #astest "ay to create a corru$t test database is to use one that someone else has already created. <ou can #ind sam$les o# corru$t SQL Server ())) and SQL Server ()), databases /"ith e*$lanations0 on my blog /at go.microso#t.com/#"link/&LinkId=11,1,10. As #or your second !uestion concerning "hat you should do in order to detect I/ errors that "ere introduced by the I/ subsystem. errors>you should enable $age checksums. -his #eature "as introduced in SQL Server ()), as a "ay o# $rotecting an entire database $age #rom Basically, "hen a $age is "ritten to disk, the last thing SQL Server does is calculate a checksum over the "hole 28+ $age and stam$ the checksum on the $age. 9hen a $age is read #rom disk, i# it has a $age checksum, the checksum is recalculated and com$ared to the one stored on the $age. I# they don't match, something outside SQL Server corru$ted the $age and an 2(? error is raised. -he error is dis$layed to the connection that caused the $age to be read, as "ell as logged to the SQL Server error log and the 9indo"s' A$$lication 7vent Log. Page checksums are on by de#ault #or all databases created on SQL Server ()), and SQL Server ())2. %o"ever, they must be manually enabled #or databases u$graded #rom $revious versions o# SQL Server. <ou can enable $age checksums "ith this code. 6o$y 6ode ALTER DATABASE mydb SET PAGE_VERIFY CHECKSUM;

Paul S.

andal is the @anaging 5irector o# SQLskills.com and a SQL Server @AP. %e "orked on the SQL Server

Storage 7ngine team at @icroso#t #rom 1333 to ())B. Paul "rote 5+66 6%7685+/re$air #or SQL Server ()), and "as res$onsible #or the 6ore Storage 7ngine during SQL Server ())2 develo$ment. An e*$ert on disaster recovery, high availability, and database maintenance, Paul is a regular $resenter at con#erences. %e blogs at SQLskills.com/blogs/$aul. C ())2 @icroso#t 6or$oration and 6@P @edia, LL6. All rights reservedD re$roduction in $art or in "hole "ithout $ermission is $rohibited.

Você também pode gostar