Upload
grsrik
View
219
Download
0
Embed Size (px)
Citation preview
8/10/2019 Checkdb_stepbystep
1/4
The question I ask in an interview is:
"You get an error in the logs indicating that you have a torn page or
checksum error. What do you do?"
Half the candidates look confused. Of the rest, roughly 90% tell e to run!"## #H$#!" with one of the re&air o&tions' (hen I challenge the to
e)&lain how #H$#!" &erfors the re&air, none are a*le to answer,unaware of the daage they ight *e doing.
+o here is how to use !"## #H$#!", and what to do when you have a tornor corru&t &age.
So How Do I Use It?The &riary &ur&ose is to check for consistency errors, and should ideally *e
run every day.
The *asic synta) is:
DBCCCHECKDB ('DB Name')WITHNO_INFOMSGS
O-IO/++ &revents an e)cessive nu*er of inforational essages
fro *eing generated. There are several other o&tions, *ut this is the synta)
you should ai to use as it &erfors all integrity checks.
This ay take a long tie on large data*ases and you ay want to s&ecify
the 1H2+I#34-O42 o&tion. This checks &hysical on5disk structures, *utoits the internal logical checks. The synta) is:
DBCCCHECKDB ('DB Name')WITHPHYSICAL_ONLY
It Has Found A Problem - What Do I Do?2ou do have *acku&s don6t you7 2ou ight *e lucky8 a non5clustered inde)can *e dro&&ed and re*uilt *ut actual data, such as a clustered inde),
cannot.
"y far the *est o&tion is to restore fro a *acku&, *ut let6s look at how you
investigate which &ages are affected and what ty&e of data is affected:
4ook at the out&ut fro !"## #H$#!". 2ou ay see soething like this:
Object ID !""#$#%& *e+ ID ! ,a-tt. ID /$0#!&!!$%%0 a11.c 2t ID/$0#!&!#/&3!3 (t4,e I5-.6 *ata)7 Pa8e (&7%0%%) c.21* .t be ,-.ce99e*: See .t;e-e--.-9
8/10/2019 Checkdb_stepbystep
2/4
M98 "%$% Le=e1 &3 State %" Le &Tab1e e--.-7 Object ID !""#$#%& *e+ ID ! ,a-tt. ID /$0#!&!!$%%0 a11.c 2tID /$0#!&!#/&3!3 (t4,e I5-.6 *ata) ,a8e (&7%0%%): Te9t (IS_OFF (B>F_IOE?? ,B>F5@b9tat))
8/10/2019 Checkdb_stepbystep
3/4
Automatic Re!air "!tionsirst let e e&hasi?e the i&ortance of running a *acku& "$O@$ you go
any further.
Have a look at the out&ut of the original #H$#!". It will s&ecify the
iniu re&air level.
R!IR#R$%I&'If the iniu re&air level is @$13I@-@$">I4! you have *een lucky.
The synta) is
DBCCCHECKDB('DB Name'?EPAI?_?EB>ILD)
R!IR#&&(W#')#&(**
This atte&ts to re&air all errors. +oeties the only way to re&air an erroris to deallocate the affected &age and odify &age links so that it looks like
the &age never e)isted. This has the desired effect of restoring thedata*ase6s structural integrity *ut eans that soething has *een deleted
hence the 344O(-!3T3-4O++=. There are likely to *e issues with
referential integrity, not to ention the i&ortant data that ay now *eissing.
The synta) is
DBCCCHECKDB('DB Name'?EPAI?_ALLOW_DATA_LOSS)
/ake sure you run !"## #H$##O+T@3IT+ afterwards so you are aware
of referential integrity issues and can take the a&&ro&riate action.
And Finall#/y original reason for writing this was to stress that the correct action when
faced with corru&tion is nearly always to restore fro a *acku&. Only use the
autoatic re&air o&tions as a last resort, and with full understanding of thedaage this ay do.
Aust as i&ortant is that regular *acku&s are an essential &art of a !"36s
res&onsi*ilities, and you should use the >44 recovery odel with regular
log *acku&s for all *ut the ost trivial data*ases.
!"## #H$#!" is a &owerful tool, *ut also very dangerous in the wronghands.
/ay*e instead of adding the @$13I@-344O(-!3T3-4O++ o&tion, /icrosoft
should have created a se&arate !"## coand called:
8/10/2019 Checkdb_stepbystep
4/4
DBCC DELETE_DATA_BECA>SE_I_CO>LDNT_BE_BOTHE?ED_TO_TAKE_A_BACK>P
3 *it harsh &erha&s, *ut at least &eo&le would know for sure what ight
ha&&en when they hit B'r