Repair Microsoft SQL database/table lessons.
- January 16th, 2014
- Write comment
I was getting the following kinds of errors after an errant update to a Microsoft SQL Server (2005 in this case) while running a “DBCC CHECKDB”:
DBCC results for ‘Transactions’.
Msg 8928, Level 16, State 1, Line 1
Object ID 37575172, index ID 0, partition ID 72057594038845440, alloc unit ID 72057594042843136 (type In-row data): Page (1:1169) could not be processed. See other errors for details.
Msg 8939, Level 16, State 98, Line 1
Table error: Object ID 37575172, index ID 0, partition ID 72057594038845440, alloc unit ID 72057594042843136 (type In-row data), page (1:1169). Test (IS_OFF (BUF_IOERR, pBUF->bstat)) failed. Values are 29493257 and -4.
Msg 8928, Level 16, State 1, Line 1
Object ID 37575172, index ID 0, partition ID 72057594038845440, alloc unit ID 72057594042843136 (type In-row data): Page (1:1309) could not be processed. See other errors for details.
Msg 8939, Level 16, State 98, Line 1
Table error: Object ID 37575172, index ID 0, partition ID 72057594038845440, alloc unit ID 72057594042843136 (type In-row data), page (1:1309). Test (IS_OFF (BUF_IOERR, pBUF->bstat)) failed. Values are 29493257 and -4.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1337), slot 12 should be pointed to by forwarding row page (1:1169), slot 20. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1337), slot 38 should be pointed to by forwarding row page (1:1169), slot 32. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1337), slot 41 should be pointed to by forwarding row page (1:1169), slot 41. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 5 should be pointed to by forwarding row page (1:1169), slot 45. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 7 should be pointed to by forwarding row page (1:1309), slot 43. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 23 should be pointed to by forwarding row page (1:1169), slot 56. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 24 should be pointed to by forwarding row page (1:1169), slot 59. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 29 should be pointed to by forwarding row page (1:1169), slot 62. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 33 should be pointed to by forwarding row page (1:1309), slot 66. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1339), slot 25 should be pointed to by forwarding row page (1:1309), slot 38. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1340), slot 17 should be pointed to by forwarding row page (1:1309), slot 51. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1340), slot 20 should be pointed to by forwarding row page (1:1309), slot 22. Did not encounter forwarding row. Possible allocation error.
There are 49003 rows in 821 pages for object “Transactions”.
CHECKDB found 0 allocation errors and 16 consistency errors in table ‘Transactions’ (object ID 37575172).
Here is what I did/tried and what eventually worked:
Put the database in single user mode:
ALTER DATABASE databasename SET SINGLE_USER
Examined and saved some of the contents of a corrupt page:
DBCC PAGE (‘tablename’, 1, pagenumber, 3) WITH TABLERESULTS
Tried to rebuild the indexes in the corrupt table:
DBCC DBREINDEX (“tablename”, ” “, 70)
Tried to repair the database without data loss:
DBCC CHECKDB(‘databasename’, REPAIR_REBUILD)
Eventually gave in and repaired the database with possible data loss:
DBCC CHECKDB(‘databasename’, REPAIR_ALLOW_DATA_LOSS);
Enabled multi-user mode:
ALTER DATABASE databasename SET MULTI_USER
Fortunately, it doesn’t look like much data was lost, since there was no backup.