Anatomy of SQL Server 17th using OrcaMDFCorruptor to intentionally damage the database

Source: Internet
Author: User
Anatomy of SQL Server 17th using orcamdfjavasuptor to intentionally damage the database (translated) improve. dkcorrupting-databases-purpose-using-orcamdf-since uptor sometimes you must first do evil before doing good. The problem is that when you want to hone your database repair skills, I have now added a javasuptor class to Orca.

Anatomy SQL Server 17th using OrcaMDF uploadtor intentionally damages the database http://improve.dk/corrupting-databases-purpose-using-orcamdf-corruptor/ sometimes you must first do evil, then do good. The problem is that when you want to hone your database repair skills, I have now added a javasuptor class to Orca.

Anatomy of SQL Server 17th using OrcaMDF uploadtor to intentionally damage the database)

Http://improve.dk/corrupting-databases-purpose-using-orcamdf-corruptor/

Sometimes you must do evil first and then do good. This is when you want to hone your database repair skills

I have now added a pluuptor class to OrcaMDF to test the new RawDatabase function. The uplotor is the same as his name-he will intentionally corrupt the database file.


Uptor itself is relatively simple. The primary uptor randomly selects some pages and simply uses 0 to completely rewrite the page.
Depending on the page type, this may cause fatal damage

I don't want to talk about anything, just in case... Do not run on your production database. This will damage your data.

Example
There are two upload uptor. CorruptFile overload methods, both of which return the integers enumerated value-a list of pageids that are rewritten to 0

The following code damages the 5% page in the AdventureWorks2008R2LT. mdf file, and then outputs the ID of each corrupted page.
You can define the percentage of page corruption. You only need to change the second parameter.

var corruptedPageIDs = Corruptor.CorruptFile(@"C:\AdventureWorks2008R2LT.mdf", 0.05);Console.WriteLine(string.Join(", ", corruptedPageIDs));

606, 516, 603, 521, 613, 621, 118, 47, 173, 579,323, 217, 358, 515, 615, 271, 176, 596, 417, 379,269, 409, 558, 103, 8, 636, 200, 361, 60, 486,366, 99, 87

To make the damage worse, you can also use the second overload method, which allows you to define an exact number of damaged pages within a definite pageid range.
The following code will definitely damage 10 pages with pageid ranging from 0 to 49, so it will damage most of the metadata, we all know that the data in the system table is basically stored on the top page of the database.

var corruptedPageIDs = Corruptor.CorruptFile(@"C:\AdventureWorks2008R2LT.mdf", 10, 0, 49);Console.WriteLine(string.Join(", ", corruptedPageIDs));

16, 4, 0, 32, 15, 14, 30, 2, 49, 9

In the above situation, I am very unfortunate to see that the following pages are filled with 0, including:

File header page, page 2 is the first GAM page, page 9 is the boot page, page 16 allocation unit metadata.

This damage level cannot be repaired even if dbcc checkdb is used. The only choice left for you is to restore data from the backup.

Alternatively, you can try OrcaMDF RawDatabase to restore as much data as possible. I will continue to introduce it here.

Dbcc traceon (3604,-1) godbcc page ([sss], 3) GODBCC is completed. If DBCC outputs an error message, contact the system administrator. PAGE: () BUFFER: BUF @ 0x0000000080FDEB80bpage = 0x0000000080A74000 bhash = 0x0000000000000000 bpageno =) bdbid = 8 breferences = 0 bcputicks = 0 bsampleCount = 0 bUse1 = 19980 bstat = 0xc00009blog = 0x32159 bnext = 0x0000000000000000PAGE HEADER: Page @ 0x0000000080A74000m_pageId =) m_headerVersion = 1 m_type = 1m_typeFlagBits = 0x4 m_level = 0 m_flagBits = 0x200m_objId (AllocUnitId. idObj) = 7 m_indexId (AllocUnitId. idInd) = 0 Metadata: AllocUnitId = 458752 Metadata: PartitionId = 458752 Metadata: IndexId = 1 Metadata: ObjectId = 7m_prevPage = (0: 0) m_nextPage =) pminlen = 73m_slotCnt = 49 m_freeCnt = 4225 m_freeData = 4331m_reservedCnt = 0 m_lsn = (1037: 459: 3) m_xactReserved = 0m_xdesId = (0: 455) m_ghostRecCnt = 0 m_tornBits =-563242027 Allocation StatusGAM () = allocated sgam () = not allocated pfs () = 0x60 MIXED_EXT ALLOCATED 0_PCT_FULL DIFF) = CHANGEDML () = NOT MIN_LOGGEDSlot 0 Offset 0x60 Length 77 Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP Record Size = 77 Memory Dump @ weight: 10004900 00000300 00000000 01000003 bytes †.. I ............. 0000000000000010: 00000000 00000000 0001001f 00000001 †................ 0000000000000020: 00570000 00010056 00000001 000b0000 hour †. W ..... V ........ 0000000000000030: 00000000 00090000 00000000 00110000 †............... 0000000000000040: 00000000 00010000 000c0000 00 00000000000000000000000000000000capacity ††††††††............. slot 0 Column 1 Offset 0x4 Length 8 Length (physical) 8 auid = 196608 Slot 0 Column 2 Offset 0xc Length 1 Length (physical) 1 type = 1 Slot 0 Column 3 Offset 0xd Length 8 Length (physical) 8 ownerid = 196608 Slot 0 Column 4 Offset 0x15 Length 4 Length (physical) 4 status = 0 Slot 0 Column 5 Offset 0x19 Length 2 Length (physical) 2 fgid = 1 pgfirst = [Binary data] Slot 0 Column 6 Offset 0x1b Length 6 Length (physical) 6 pgfirst = 0x1f0000000100pgroot = [Binary data] Slot 0 Column 7 Offset 0x21 Length 6 Length (physical) 6 pgroot = 0x570000000100pgfirstiam = [Binary data] Slot 0 Column 8 Offset 0x27 Length 6 Length (physical) 6 pgfirstiam = 0x560000000100 Slot 0 Column 9 Offset 0x2d Length 8 Length (physical) 8 pcused = 11 Slot 0 Column 10 Offset 0x35 Length 8 Length (physical) 8 pcdata = 9 Slot 0 Column 11 Offset 0x3d Length 8 Length (physical) 8 pcreserved = 17 Slot 0 Column 12 Offset 0x45 Length 4 Length (physical) 4 dbfragid = 1 Slot 0 Offset 0x0 Length 0 Length (physical) 0 KeyHashValue = (016862d84319)

Select count (*) FROM sys. [allocation_units]
-- 131
SELECT * FROM sys. [allocation_units]
SELECT * FROM sys. [system_internals_allocation_units]

Stored on the database page ([sys. system_internals_allocation_units] system table) in-depth analysis of sql2008

17th

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.