%3CLINGO-SUB%20id%3D%22lingo-sub-1607111%22%20slang%3D%22en-US%22%3ESQL%20Server%20GAM%20corruption%20samples%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1607111%22%20slang%3D%22en-US%22%3E%3CH3%20id%3D%22toc-hId-1224904839%22%20id%3D%22toc-hId-1224904839%22%3ESQL%20Server%20Extents%2C%20PFS%2C%20GAM%2C%20SGAM%20and%20IAM%20and%20related%20corruptions-2%3C%2FH3%3E%0A%3CP%3EIn%20previous%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fsql-server-support%2Fsql-server-extents-pfs-gam-sgam-and-iam-and-related-corruptions%2Fba-p%2F1606011%22%20target%3D%22_self%22%3Epost%3C%2FA%3E%2C%20we%20discussed%20the%20PFS%2C%20GAM%20and%20SGAM%20pages.%20Today%2C%20I%E2%80%99m%20going%20show%20you%20two%20related%20corruptions%20on%20these%20pages.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESQL%20Server%20checks%20the%20bit%20in%20PFS%2C%20GAM%2C%20SGAM%20and%20IAM%20are%20checked%20when%20new%20pages%20are%20allocated.%20It%20guarantees%20that%20it%20does%20not%20store%20data%20to%20a%20wrong%20page%2Fextent.%3C%2FP%3E%0A%3CP%3EThese%20pages%20are%20crucial%20to%20SQL%20Server%2C%20SQL%20Server%20considers%20it%20as%20a%20corruption%20if%20they%20are%20messed%20up.%3C%2FP%3E%0A%3CP%3EI%E2%80%99m%20going%20to%20use%20the%20same%20database%20I%20used%20in%20previous%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20may%20restore%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2Fattachments%2Fgxcuf89792%2FSQLServerSupport%2F1027%2F2%2Fdbtest20200823.zip%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ebackup%3C%2FA%3E%26nbsp%3Bfile%20and%20give%20it%20a%20try.%20Please%20note%2C%20restoring%20database%20will%20consume%20some%20pages%20and%20change%20the%20PFS%2C%20GAM%2C%20SGAM%20and%20IAM.%20You%20may%20get%20a%20different%20view%20from%20my%20mine.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%20me%20show%20you%20some%20of%20the%20content%20of%20GAM%20and%20SGAM%20before%20the%20corruption%20samples.%3C%2FP%3E%0A%3CP%3EHere%20are%20the%20GAM%20and%20SGAM%20page%20result%3A%3C%2FP%3E%0A%3CP%3E1.GAM%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_0-1598239416070.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214223iD1FEB7425E9EF1F3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_0-1598239416070.png%22%20alt%3D%22Liwei_0-1598239416070.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2.SGAM%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_1-1598239416071.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214224iC3405C5CC081E3DD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_1-1598239416071.png%22%20alt%3D%22Liwei_1-1598239416071.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3.We%20can%20tell%20that%20the%20extent%20of%20page(1%3A352)%20and%20extents%20greater%20than%20that%20have%20not%20been%20allocated.%3C%2FP%3E%0A%3CP%3E4.Let%E2%80%99s%20take%20a%20dive%20into%20the%20GAM%20page.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_2-1598239416072.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214225i297C452E9B0E840E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_2-1598239416072.png%22%20alt%3D%22Liwei_2-1598239416072.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E5.%E2%80%9800000000%2000f0%E2%80%99%20interpretation%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_3-1598239416073.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214226iE21DA2723ECC2CC8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_3-1598239416073.png%22%20alt%3D%22Liwei_3-1598239416073.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E5)Pages%20and%20extents%20of%20heaptable1%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%26nbsp%3Ballocated_page_file_id%26nbsp%3Bas%26nbsp%3B%5BFileID%5D%2Callocated_page_page_id%26nbsp%3Bas%26nbsp%3B%5BPageID%5D%2Cpage_type_desc%2Cextent_page_id%2F8%26nbsp%3Bas%26nbsp%3BExtentID%2C%26nbsp%3Bis_mixed_page_allocation%2Cextent_page_id%26nbsp%3Bas%26nbsp%3B%5BFirst%20Page%20in%20Extent%5D%2Cextent_page_id%2B7%26nbsp%3Bas%26nbsp%3B%5BLastPage%20in%20Extent%5D%2Cis_allocated%26nbsp%3BFrom%26nbsp%3B%26nbsp%3Bsys.dm_db_database_page_allocations(db_id()%2Cobject_id('dbo.heaptable1')%2Cnull%2Cnull%2C'detailed')%26nbsp%3B%26nbsp%3Border%26nbsp%3Bby%26nbsp%3Ballocated_page_page_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_4-1598239416083.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214228iD2E8BA4BF7DE83F3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_4-1598239416083.png%22%20alt%3D%22Liwei_4-1598239416083.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20will%20find%20all%20the%20data%20in%20this%20backup%20file%20dbtest20200823.zip.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E1.Now%20let%E2%80%99s%20discuss%20the%20first%20corruption%20scenario%3A%20error%208903%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E1)The%20page%20245%2C246%2C247%2C328%2C329%2C330%2C331%2C332%2C333%20belongs%20to%20the%20table%20heaptable1.%3C%2FP%3E%0A%3CP%3E2)Extent%2030%20and%2041%20have%20these%20pages.%3C%2FP%3E%0A%3CP%3E3)These%20two%20extents%20are%20marked%20as%20allocated%20in%20GAM.%20What%20happen%20if%20the%20extents%20are%20marked%20as%20%E2%80%98not%20allocated%E2%80%99%3F%3C%2FP%3E%0A%3CP%3EThe%20answer%20is%20%3A%20that%20extent%20will%20be%20consider%20as%20corrupted%20and%20DBCC%20Checkdb%20may%20report%20the%208903%20error%3A%3C%2FP%3E%0A%3CP%3EMsg%208903%2C%20Level%2016%2C%20State%201%2C%20Line%2022%3C%2FP%3E%0A%3CP%3EExtent%20(xx%3Axx)%20in%20database%20ID%20xx%20is%20allocated%20in%20both%20GAM%20(xx%3Axx)%20and%20SGAM%20(xx%3Axx).%3C%2FP%3E%0A%3CP%3E4)It%20usually%20happens%20when%20disks%20or%20other%20hardware%20run%20into%20issue%E2%80%A6%3C%2FP%3E%0A%3CP%3E5)Here%20is%20the%20result%20of%20DBCC%20PAGE%20after%20the%20GAM%20page%20in%20data%20file%20is%20messed%20up%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_5-1598239416081.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214227iE5D13A98E491208F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_5-1598239416081.png%22%20alt%3D%22Liwei_5-1598239416081.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E6)%E2%80%9900000000%2000f2%E2%80%99%20interpretation.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_6-1598239416075.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214230i0E54BE70DAEA1DA4%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_6-1598239416075.png%22%20alt%3D%22Liwei_6-1598239416075.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E7)DBCC%20PAGE%20of%20GAM%20with%20parameter%203.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_7-1598239416075.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214229i9D025784293C2248%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_7-1598239416075.png%22%20alt%3D%22Liwei_7-1598239416075.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E8)Here%20is%20the%20result%20of%20DBCC%20CHECKDB%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_8-1598239416076.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214231i815F74A0023651DF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_8-1598239416076.png%22%20alt%3D%22Liwei_8-1598239416076.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E9)Why%20(1%3A312)%20is%20marked%20as%20corruption%3F%3C%2FP%3E%0A%3CP%3EBecause%20I%20messed%20up%20the%20%E2%80%9900000000%2000f0ffff%E2%80%99%3A%20I%20replaced%20it%20with%20%E2%80%9800000000%2000f2ffff%E2%80%98.%3C%2FP%3E%0A%3CP%3EThe%20extent(1%3A328)%20is%20actually%20allocated%2C%20but%20%E2%80%9800000000%2000f2ffff%E2%80%98%20conflicts%20the%20fact.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETakeaway%3C%2FSTRONG%3E%3A%20When%20SQL%20Server%20set%20a%20bit%20of%20extent%20to%200%20in%20GAM%20to%20allocate%20an%20extent%2C%20it%20also%20set%20the%20bits%20in%20other%20allocation%20pages%2C%20like%20SGAM%2C%20IAM%20etc%2C%20that%E2%80%99s%20the%20normal%20behavior.%3C%2FP%3E%0A%3CP%3EIf%20the%20bits%20in%20these%20allocation%20pages%20conflict%20each%20other%2C%20SQL%20Server%20considers%20it%E2%80%99s%20corruption%20scenario.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EQuestion%3C%2FSTRONG%3E%3A%20is%20the%20command%20%E2%80%98dbcc%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Echeckdb(dbtest%2Crepair_rebuild)%E2%80%99%20able%20to%20fix%20the%20issue%3F%20Why%3F%3C%2FP%3E%0A%3CP%3EPlease%20download%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2Fattachments%2Fgxcuf89792%2FSQLServerSupport%2F1028%2F1%2Fdbtest20200823_error8903.zip%22%20target%3D%22_self%22%3Edbtest20200823_error8903.zip%3C%2FA%3E%20and%20give%20it%20a%20try.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E2.Now%20let%E2%80%99s%20discuss%20the%20second%20corruption%20scenario%3A%20error%208905%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E1).The%20extent%20id%20of%20page(1%3A352)%20is%2044%2C%20it%E2%80%99s%20not%20allocated%20yet.%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EWhat%20if%20the%20extent%2044(or%20the%20extent%20after%2044)%20is%20marked%20as%20allocated%20only%20in%20GAM%3F%3C%2FP%3E%0A%3CP%3EThe%20answer%20is%20%3A%20that%20extent%20will%20be%20consider%20as%20corrupted%20and%20DBCC%20Checkdb%20may%20report%20the%208905%20error%3A%3C%2FP%3E%0A%3CP%3EMsg%208905%2C%20Level%2016%2C%20State%201%2C%20Line%2013%3C%2FP%3E%0A%3CP%3EExtent%20(xxx%3Axxx)%20in%20database%20ID%20xx%20is%20marked%20allocated%20in%20the%20GAM%2C%20but%20no%20SGAM%20or%20IAM%20has%20allocated%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2)It%20usually%20happens%20when%20disks%20or%20other%20hardware%20run%20into%20issue%E2%80%A6%3C%2FP%3E%0A%3CP%3E3)Here%20is%20the%20result%20of%20DBCC%20PAGE%20after%20the%20GAM%20page%20in%20data%20file%20is%20messed%20up%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_9-1598239416082.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214234i252E1AD48DD26F95%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_9-1598239416082.png%22%20alt%3D%22Liwei_9-1598239416082.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E4)%E2%80%9900000000%2000f0ffff%20fe%E2%80%99%20interpretation.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_0-1598316884080.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214552iB79BE98C5F319FDA%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_0-1598316884080.png%22%20alt%3D%22Liwei_0-1598316884080.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E5)DBCC%20PAGE%20of%20GAM%20with%20parameter%203.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_11-1598239416079.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214232i65CD7AE46F753C82%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_11-1598239416079.png%22%20alt%3D%22Liwei_11-1598239416079.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E6)Here%20is%20the%20result%20of%20DBCC%20CHECKDB%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_12-1598239416080.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214235iBACFCA21434063BB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_12-1598239416080.png%22%20alt%3D%22Liwei_12-1598239416080.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E7)Why%20(1%3A512)%20is%20marked%20as%20corruption%3F%3C%2FP%3E%0A%3CP%3EBecause%20I%20messed%20up%20the%20%E2%80%9900000000%2000f0ffff%20ff%E2%80%99%3A%20I%20replaced%20it%20with%20%E2%80%9800000000%2000f0ffff%20fe%E2%80%99.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETakeaway%3C%2FSTRONG%3E%3A%20When%20SQL%20Server%20set%20a%20bit%20of%20extent%20to%200%20in%20GAM%20to%20allocate%20an%20extent%2C%20it%20also%20sets%20the%20bits%20in%20other%20allocation%20pages%2C%20like%20SGAM%2C%20IAM%20etc%2C%20that%E2%80%99s%20the%20normal%20behavior.%3C%2FP%3E%0A%3CP%3EIf%20the%20bit%20is%20only%20set%20in%20GAM%2C%20but%20not%20in%20SGAM%20or%20IAM%2C%20then%20there%20is%20erroneous%20info%20in%20the%20allocation%20pages%2C%20it%E2%80%99s%20a%20corruption!%20SQL%20Server%20detects%20it%20and%20raise%20an%20error.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EQuestion%3C%2FSTRONG%3E%3A%20Is%20the%20command%20%E2%80%98dbcc%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Echeckdb(dbtest%2Crepair_rebuild)%E2%80%99%20able%20to%20fix%20the%20issue%3F%20Why%3F%3C%2FP%3E%0A%3CP%3EPlease%20download%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2Fattachments%2Fgxcuf89792%2FSQLServerSupport%2F1028%2F2%2Fdbtest20200823_error8905.zip%22%20target%3D%22_self%22%3Edbtest20200823_error8905.bak%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20give%20it%20a%20try.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1607111%22%20slang%3D%22en-US%22%3E%3CH1%20class%3D%22message-subject%22%20id%3D%22toc-hId--1283614202%22%3E%3CSPAN%20class%3D%22lia-message-read%22%3E%3CA%20id%3D%22link_6%22%20class%3D%22page-link%20lia-link-navigation%20lia-custom-event%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fsql-server-support%2Fsql-server-extents-pfs-gam-sgam-and-iam-and-related-corruptions%2Fba-p%2F1606011%22%20target%3D%22_blank%22%3ESQL%20Server%20Extents%2C%20PFS%2C%20GAM%2C%20SGAM%20and%20IAM%20and%20related%20corruptions-2%3C%2FA%3E%3C%2FSPAN%3E%3C%2FH1%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1607111%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EStorage%20Engine%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

SQL Server Extents, PFS, GAM, SGAM and IAM and related corruptions-2

In previous post, we discussed the PFS, GAM and SGAM pages. Today, I’m going show you two related corruptions on these pages.

 

SQL Server checks the bit in PFS, GAM, SGAM and IAM are checked when new pages are allocated. It guarantees that it does not store data to a wrong page/extent.

These pages are crucial to SQL Server, SQL Server considers it as a corruption if they are messed up.

I’m going to use the same database I used in previous .

 

You may restore the backup file and give it a try. Please note, restoring database will consume some pages and change the PFS, GAM, SGAM and IAM. You may get a different view from my mine.

 

Let me show you some of the content of GAM and SGAM before the corruption samples.

Here are the GAM and SGAM page result:

1.GAM

Liwei_0-1598239416070.png

 

2.SGAM

Liwei_1-1598239416071.png

 

3.We can tell that the extent of page(1:352) and extents greater than that have not been allocated.

4.Let’s take a dive into the GAM page.

Liwei_2-1598239416072.png

 

5.‘00000000 00f0’ interpretation:

Liwei_3-1598239416073.png

 

5)Pages and extents of heaptable1

select allocated_page_file_id as [FileID],allocated_page_page_id as [PageID],page_type_desc,extent_page_id/8 as ExtentID, is_mixed_page_allocation,extent_page_id as [First Page in Extent],extent_page_id+7 as [LastPage in Extent],is_allocated From  sys.dm_db_database_page_allocations(db_id(),object_id('dbo.heaptable1'),null,null,'detailed')  order by allocated_page_page_id

Liwei_4-1598239416083.png

 

You will find all the data in this backup file dbtest20200823.zip.

 

1.Now let’s discuss the first corruption scenario: error 8903

1)The page 245,246,247,328,329,330,331,332,333 belongs to the table heaptable1.

2)Extent 30 and 41 have these pages.

3)These two extents are marked as allocated in GAM. What happen if the extents are marked as ‘not allocated’?

The answer is : that extent will be consider as corrupted and DBCC Checkdb may report the 8903 error:

Msg 8903, Level 16, State 1, Line 22

Extent (xx:xx) in database ID xx is allocated in both GAM (xx:xx) and SGAM (xx:xx).

4)It usually happens when disks or other hardware run into issue…

5)Here is the result of DBCC PAGE after the GAM page in data file is messed up:

Liwei_5-1598239416081.png

 

6)’00000000 00f2’ interpretation.

Liwei_6-1598239416075.png

 

7)DBCC PAGE of GAM with parameter 3.

Liwei_7-1598239416075.png

 

8)Here is the result of DBCC CHECKDB:

Liwei_8-1598239416076.png

 

 

 

9)Why (1:312) is marked as corruption?

Because I messed up the ’00000000 00f0ffff’: I replaced it with ‘00000000 00f2ffff‘.

The extent(1:328) is actually allocated, but ‘00000000 00f2ffff‘ conflicts the fact.

 

Takeaway: When SQL Server set a bit of extent to 0 in GAM to allocate an extent, it also set the bits in other allocation pages, like SGAM, IAM etc, that’s the normal behavior.

If the bits in these allocation pages conflict each other, SQL Server considers it’s corruption scenario.

 

Question: is the command ‘dbcc checkdb(dbtest,repair_rebuild)’ able to fix the issue? Why?

Please download the dbtest20200823_error8903.zip and give it a try.

 

2.Now let’s discuss the second corruption scenario: error 8905

1).The extent id of page(1:352) is 44, it’s not allocated yet.  What if the extent 44(or the extent after 44) is marked as allocated only in GAM?

The answer is : that extent will be consider as corrupted and DBCC Checkdb may report the 8905 error:

Msg 8905, Level 16, State 1, Line 13

Extent (xxx:xxx) in database ID xx is marked allocated in the GAM, but no SGAM or IAM has allocated it.

 

2)It usually happens when disks or other hardware run into issue…

3)Here is the result of DBCC PAGE after the GAM page in data file is messed up:

 

Liwei_9-1598239416082.png

 

4)’00000000 00f0ffff fe’ interpretation.

Liwei_0-1598316884080.png

5)DBCC PAGE of GAM with parameter 3.

Liwei_11-1598239416079.png

 

6)Here is the result of DBCC CHECKDB:

Liwei_12-1598239416080.png

 

7)Why (1:512) is marked as corruption?

Because I messed up the ’00000000 00f0ffff ff’: I replaced it with ‘00000000 00f0ffff fe’.

 

Takeaway: When SQL Server set a bit of extent to 0 in GAM to allocate an extent, it also sets the bits in other allocation pages, like SGAM, IAM etc, that’s the normal behavior.

If the bit is only set in GAM, but not in SGAM or IAM, then there is erroneous info in the allocation pages, it’s a corruption! SQL Server detects it and raise an error.

 

Question: Is the command ‘dbcc checkdb(dbtest,repair_rebuild)’ able to fix the issue? Why?

Please download the dbtest20200823_error8905.bak and give it a try.