%3CLINGO-SUB%20id%3D%22lingo-sub-1606011%22%20slang%3D%22en-US%22%3ESQL%20Server%20Extents%2C%20PFS%2C%20GAM%2C%20SGAM%20and%20IAM%20and%20related%20corruptions%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1606011%22%20slang%3D%22en-US%22%3E%3CP%3EI%E2%80%99m%20going%20to%20start%20a%20series%20of%20posts%20talking%20about%20SQL%20Server%20allocation%20pages%20and%20corruption.%20Each%20post%20will%20have%20samples%20showing%20how%20SQL%20Server%20use%20these%20pages%20and%20scenarios%20of%20corruption.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20first%20post%20will%20talk%20about%20the%20Extents%2C%20PFS%2C%20GAM%2C%20SGAM%20and%20IAM%20and%20related%20corruptions%2C%20you%20can%20find%20all%20concepts%20from%20following%20two%20pages%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fpages-and-extents-architecture-guide%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPages%20and%20Extents%20Architecture%20Guide%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fsql-server%2Funder-the-covers-gam-sgam-and-pfs-pages%2Fba-p%2F383125%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EUnder%20the%20covers%3A%20GAM%2C%20SGAM%2C%20and%20PFS%20pages%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20there%20are%20many%20concepts%20and%20samples%2C%20I%E2%80%99m%20going%20to%20discuss%20the%20topics%20in%20three%20or%20four%20posts.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E1.Extents%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EExtents%20are%20the%20basic%20unit%20in%20which%20space%20is%20managed.%20An%20extent%20is%20eight%20physically%20contiguous%20pages%2C%20or%2064%20KB.%20This%20means%20SQL%20Server%20databases%20have%2016%20extents%20per%20megabyte.%3C%2FP%3E%0A%3CP%3ESQL%20Server%20has%20two%20types%20of%20extents%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%C2%B7%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EUniform%3C%2FSTRONG%3E%26nbsp%3Bextents%20are%20owned%20by%20a%20single%20object%3B%20all%20eight%20pages%20in%20the%20extent%20can%20only%20be%20used%20by%20the%20owning%20object.%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%C2%B7%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMixed%3C%2FSTRONG%3E%26nbsp%3Bextents%20are%20shared%20by%20up%20to%20eight%20objects.%20Each%20of%20the%20eight%20pages%20in%20the%20extent%20can%20be%20owned%20by%20a%20different%20object.%3C%2FP%3E%0A%3CP%3EUp%20to%2C%20and%20including%2C%20SQL%20Server%202014%20(12.x)%2C%20SQL%20Server%20does%20not%20allocate%20whole%20extents%20to%20tables%20with%20small%20amounts%20of%20data.%20A%20new%20table%20or%20index%20generally%20allocates%20pages%20from%20mixed%20extents.%20When%20the%20table%20or%20index%20grows%20to%20the%20point%20that%20it%20has%20eight%20pages%2C%20it%20then%20switches%20to%20use%20uniform%20extents%20for%20subsequent%20allocations.%20If%20you%20create%20an%20index%20on%20an%20existing%20table%20that%20has%20enough%20rows%20to%20generate%20eight%20pages%20in%20the%20index%2C%20all%20allocations%20to%20the%20index%20are%20in%20uniform%20extents.%20However%2C%20starting%20with%20SQL%20Server%202016%20(13.x)%2C%20the%20default%20for%20all%20allocations%20in%20the%20database%20is%20uniform%20extents.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESample%201%3C%2FSTRONG%3E%3A%20The%20first%208%20pages%20are%20stored%20in%20mixed%20extent.%3C%2FP%3E%0A%3CP%3E1)Create%20an%20empty%20database%20in%20SQL%20Server%202017%20instance%20and%20enable%20the%20mixed%20extent%20allocation.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ecreate%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edatabase%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edbtest%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ego%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ealter%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edatabase%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edbtest%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eset%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EMIXED_PAGE_ALLOCATION%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eon%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E2)Create%20a%20heap%20table%20and%20insert%20one%20row.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ecreate%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Etable%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1(c1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eint%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ec2%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evarchar(8000))%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(1%2CREPLICATE('a'%2C1000))%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E3)Let%E2%80%99s%20check%20how%20these%20rows%20and%20pages%20stored%20in%20SQL%20Server.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eht1.c1%2Cht1.c2%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ep.file_id%2Cp.page_id%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis_mixed_page_allocation%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3EFrom%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eht1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3ECROSS%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EAPPLY%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esys.fn_PhysLocCracker(%25%25physloc%25%25)%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ep%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Einner%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ejoin%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esys.dm_db_database_page_allocations(db_id()%2Cobject_id('dbo.heaptable1')%2Cnull%2Cnull%2C'detailed')%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edddpa%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eon%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ep.file_id%3Ddddpa.allocated_page_file_id%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Ep.page_id%3Ddddpa.allocated_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_0-1598163816406.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214124i6D2CEAD68791367D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_0-1598163816406.png%22%20alt%3D%22Liwei_0-1598163816406.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBecause%20there%20is%20only%201%20row%2C%20in%20one%20page%2C%20it%E2%80%99s%20stored%20in%20mixed%20extent.%3C%2FP%3E%0A%3CP%3EThe%20page%20id%20is%3A(1%3A245).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E2.PFS%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EPage%20Free%20Space%20(PFS)%3C%2FSTRONG%3E%26nbsp%3Bpages%20record%20the%20allocation%20status%20of%20each%20page%2C%20whether%20an%20individual%20page%20has%20been%20allocated%2C%20and%20the%20amount%20of%20free%20space%20on%20each%20page.%20The%20PFS%20has%201-byte%20for%20each%20page%2C%20recording%20whether%20the%20page%20is%20allocated%2C%20and%20if%20so%2C%20whether%20it%20is%20empty%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E1%20to%2050%20percent%20full%2C%2051%20to%2080%20percent%20full%2C%2081%20to%2095%20percent%20full%2C%20or%2096%20to%20100%20percent%20full%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3EAfter%20an%20extent%20has%20been%20allocated%20to%20an%20object%2C%20the%20SQL%20Server%20Database%20Engine%20uses%20the%20PFS%20pages%20to%20record%20which%20pages%20in%20the%20extent%20are%20allocated%20or%20free.%20This%20information%20is%20used%20when%20the%20SQL%20Server%20Database%20Engine%20has%20to%20allocate%20a%20new%20page.%20The%20amount%20of%20free%20space%20in%20a%20page%20is%20only%20maintained%20for%20heap%20and%20Text%2FImage%20pages.%20It%20is%20used%20when%20the%20SQL%20Server%20Database%20Engine%20has%20to%20find%20a%20page%20with%20free%20space%20available%20to%20hold%20a%20newly%20inserted%20row.%20Indexes%20do%20not%20require%20that%20the%20page%20free%20space%20be%20tracked%2C%20because%20the%20point%20at%20which%20to%20insert%20a%20new%20row%20is%20set%20by%20the%20index%20key%20values.%3C%2FP%3E%0A%3CP%3EA%20new%20PFS%2C%20GAM%20or%20SGAM%20page%20is%20added%20in%20the%20data%20file%20for%20every%20additional%20range%20that%20it%20keeps%20track%20of.%20Thus%2C%20there%20is%20a%20new%20PFS%20page%208%2C088%20pages%20after%20the%20first%20PFS%20page%2C%20and%20additional%20PFS%20pages%20in%20subsequent%208%2C088%20page%20intervals.%20To%20illustrate%2C%20page%20ID%201%20is%20a%20PFS%20page%2C%20page%20ID%208088%20is%20a%20PFS%20page%2C%20page%20ID%2016176%20is%20a%20PFS%20page%2C%20and%20so%20on.%20There%20is%20a%20new%20GAM%20page%2064%2C000%20extents%20after%20the%20first%20GAM%20page%20and%20it%20keeps%20track%20of%20the%2064%2C000-extents%20following%20it%3B%20the%20sequence%20continues%20at%2064%2C000-extent%20intervals.%20Similarly%2C%20there%20is%20a%20new%20SGAM%20page%2064%2C000%20extents%20after%20the%20first%20SGAM%20page%20and%20additional%20SGAM%20pages%20in%20subsequent%2064%2C000%20extent%20intervals.%20The%20following%20illustration%20shows%20the%20sequence%20of%20pages%20used%20by%20the%20SQL%20Server%20Database%20Engine%20to%20allocate%20and%20manage%20extents.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESample%202%3C%2FSTRONG%3E%3A%20PFS%20page%20detail%2C%20how%20does%20SQL%20Server%20map%20the%20value%20%E2%80%981%E2%80%99%2C%E2%80%992%E2%80%99%2C%E2%80%993%E2%80%99%2C%E2%80%994%E2%80%99%20to%20%E2%80%9950%20Percent%20full%E2%80%99%2C%E2%80%9980%20Percent%20full%E2%80%99%2C%E2%80%9995%20Percent%20full%E2%80%99%20and%20%E2%80%98100%20Percent%20full%E2%80%99.%3C%2FP%3E%0A%3CP%3E1)The%20first%20PFS%20page%20is%20(1%3A1).%3C%2FP%3E%0A%3CP%3E2)Run%20DBCC%20PAGE%20to%20display%20the%20content%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_1-1598163816412.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214125i27BF6FD1B3C2894D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_1-1598163816412.png%22%20alt%3D%22Liwei_1-1598163816412.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20the%20size%20of%20row%20is%201KB%2C%20the%20usage%20of%20the%20page%20is%20around%201000.0%2F8096%3D12%25%2C%20so%20it%E2%80%99s%20marked%20as%2050%20percent%20full.%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20display%20the%20content%20again%20using%20the%20parameter%201%20instead%20of%203.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_2-1598163816428.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214126i00621FEF8639F6EE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_2-1598163816428.png%22%20alt%3D%22Liwei_2-1598163816428.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20value%20is%206%3CSTRONG%3E1%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E3)Let%E2%80%99s%20keep%20inserting%20another%204%20rows.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(2%2CREPLICATE('b'%2C1000))%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(3%2CREPLICATE('c'%2C1000))%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(4%2CREPLICATE('d'%2C1000))%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(5%2CREPLICATE('e'%2C1000))%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E4)The%20total%20size%20of%205%20rows%20are%20around%205KB%2C%20the%20usage%20is%20around%205000.0%2F8096%3D61%25%2C%20which%20is%20greater%20than%2050%25%20%2C%20but%20less%20than%2080%25%2C%20so%20it%E2%80%99s%20marked%20as%2080%20percent%20full.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_3-1598163816414.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214127iEEEBC24C07802FEF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_3-1598163816414.png%22%20alt%3D%22Liwei_3-1598163816414.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20display%20the%20content%20again%20using%20the%20parameter%201%20instead%20of%203.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_4-1598163816429.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214129i14204876EBC8DBB4%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_4-1598163816429.png%22%20alt%3D%22Liwei_4-1598163816429.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20value%20is%206%3CSTRONG%3E2%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E5)Let%E2%80%99s%20keep%20inserting%20another%202%20rows.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(6%2CREPLICATE('f'%2C1000))%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(7%2CREPLICATE('g'%2C1000))%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E6)The%20total%20size%20of%207%20rows%20are%20around%207KB%2C%20the%20usage%20is%20around%207000.0%2F8096%3D86%25%2C%20which%20is%20greater%20than%2080%25%20%2C%20but%20less%20than%2085%25%2C%20so%20it%E2%80%99s%20marked%20as%2095%20percent%20full.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_5-1598163816416.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214128iFC84ACEB6EBBCFC5%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_5-1598163816416.png%22%20alt%3D%22Liwei_5-1598163816416.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20display%20the%20content%20again%20using%20the%20parameter%201%20instead%20of%203.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_6-1598163816430.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214132i94B026A323619A69%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_6-1598163816430.png%22%20alt%3D%22Liwei_6-1598163816430.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20value%20is%206%3CSTRONG%3E3%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETakeaway%3C%2FSTRONG%3E%3A%20Because%20SQL%20Server%20stop%20storing%20data%20in%20a%20page%20of%20heap%20when%20it%E2%80%99s%2095%25%2C%20you%20won%E2%80%99t%20see%20%E2%80%98100%20percent%20full%E2%80%99%20even%20if%20you%20continue%20inserting%20a%20row%20with%20size%201KB.%3C%2FP%3E%0A%3CP%3E8)For%20100%20percent%20full%2C%20please%20see%20sample%208.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E3.GAM%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGlobal%20Allocation%20Map%20(GAM)%3C%2FSTRONG%3E%3CBR%20%2F%3EGAM%20pages%20record%20what%20extents%20have%20been%20allocated.%20Each%20GAM%20covers%2064%2C000%20extents%2C%20or%20almost%204%20gigabytes%20(GB)%20of%20data.%20The%20GAM%20has%201-bit%20for%20each%20extent%20in%20the%20interval%20it%20covers.%20If%20the%20bit%20is%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E1%3C%2FSTRONG%3E%2C%20the%20extent%20is%20free%3B%20if%20the%20bit%20is%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E0%3C%2FSTRONG%3E%2C%20the%20extent%20is%20allocated%2C%20either%20in%20GAM%20or%20SGAM.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESample%203%3C%2FSTRONG%3E%3A%20GAM%20explore%3C%2FP%3E%0A%3CP%3E1)Let%E2%80%99s%20check%20the%20GAM.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_7-1598163816418.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214131i76937D1357DD5DA0%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_7-1598163816418.png%22%20alt%3D%22Liwei_7-1598163816418.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2)What%20does%20the%20entry%20%E2%80%98(1%3A0)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E-%20(1%3A320)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3D%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EALLOCATED%E2%80%99%20stand%20for%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B(1%3A0)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Eis%20the%20first%20page%20of%20first%20extent%20in%20this%20range.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B(1%3A320)%20is%20the%20first%20page%20of%20last%20extent%20in%20this%20range.%20(1%3A327)%20is%20the%20last%20page%20of%20this%20extent.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3BAll%20the%20extents%20within%20the%20range%2C%20including%20the%20first%20extent%20and%20last%20extent%2C%20are%20allocated%20as%20mixed%20extent%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eor%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Euniformed%20extent.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETakeaway%3C%2FSTRONG%3E%3A%20we%20can%20tell%20if%20the%20extents%20and%20pages%20are%20allocated%20by%20checking%20GAM%20page%2C%20these%20extents%20maybe%20mixed%20extent%20or%20uniform%20extent.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B3)What%20does%20the%20entry%20%E2%80%98(1%3A328)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E-%20(1%3A1016)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3D%3CSPAN%3E%26nbsp%3B%20NOT%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3EALLOCATED%E2%80%99%20stand%20for%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20(1%3A328)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Eis%20the%20first%20page%20of%20first%20extent%20in%20this%20range.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20(1%3A1016)%20is%20the%20first%20page%20of%20last%20extent%20in%20this%20range.%20(1%3A1023)%20is%20the%20last%20page%20of%20this%20extent.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BAll%20the%20extents%20within%20the%20range%20are%20not%20allocated%20yet.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E4.SGAM%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EShared%20Global%20Allocation%20Map%20(SGAM)%3C%2FSTRONG%3E%3CBR%20%2F%3ESGAM%20pages%20record%20which%20extents%20are%20currently%20being%20used%20as%20mixed%20extents%20and%20also%20have%20at%20least%20one%20unused%20page.%20Each%20SGAM%20covers%2064%2C000%20extents%2C%20or%20almost%204-GB%20of%20data.%20The%20SGAM%20has%201-bit%20for%20each%20extent%20in%20the%20interval%20it%20covers.%20If%20the%20bit%20is%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E1%3C%2FSTRONG%3E%2C%20the%20extent%20is%20being%20used%20as%20a%20mixed%20extent%20and%20has%20a%20free%20page.%20If%20the%20bit%20is%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E0%3C%2FSTRONG%3E%2C%20the%20extent%20is%20not%20used%20as%20a%20mixed%20extent%2C%20or%20it%20is%20a%20mixed%20extent%20and%20all%20its%20pages%20are%20being%20used.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESample%204%3C%2FSTRONG%3E%3A%20SGAM%20explore%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20check%20the%20GAM.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_8-1598163816418.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214130i7BAB8C37EC70EC59%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_8-1598163816418.png%22%20alt%3D%22Liwei_8-1598163816418.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2)What%20does%20the%20first%20entry%20%E2%80%98(1%3A0)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E-%20(1%3A232)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3D%20NOT%20ALLOCATED%E2%80%99%20stand%20for%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20(1%3A0)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Eis%20the%20first%20page%20of%20first%20extent%20in%20this%20range.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20(1%3A232)%20is%20the%20first%20page%20of%20last%20extent%20in%20this%20range.%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E(1%3A239)%20is%20the%20last%20page%20in%20this%20extent.%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20Please%20note%3A%20%E2%80%98NOT%20ALLOCATED%E2%80%99%20is%26nbsp%3Bmisleading%2C%20you%20see%20the%20%E2%80%98NOT%20ALLOCATED%E2%80%99%20when%20the%20corresponding%20bit%20is%200%3A%20the%20extent%20is%20not%20used%20as%20a%20mixed%20extent%2C%20or%20it%20is%20a%20mixed%20extent%20and%20all%20its%20pages%20are%20being%20used.%20Please%20see%20the%20Sample%207%20for%20more%20detail.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3)What%20does%20the%20second%20entry%20%E2%80%98(1%3A240)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E-%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3D%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EALLOCATED%E2%80%99%20stand%20for%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B(1%3A240)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Eis%20the%20first%20page%20of%20first%20extent%20in%20this%20range.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3BAt%20least%20this%20extent%20is%20allocated%20as%20mixed%20extent.%20So%20do%20the%20page(1%3A240)~(1%3A247).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E4)What%20does%20the%20second%20entry%20%E2%80%98(1%3A248)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E-%20(1%3A1016)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3D%20NOT%20ALLOCATED%E2%80%99%20stand%20for%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B(1%3A248)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Eis%20the%20first%20page%20of%20first%20extent%20in%20this%20range.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B(1%3A1016)%20is%20the%20first%20page%20of%20last%20extent%20in%20this%20range.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BAll%20the%20extents%20within%20the%20range%2C%20including%20the%20first%20extent%20and%20last%20extent%2C%20are%20not%20allocated%20as%20mixed%20extent.%20So%20do%20the%20page(1%3A352)~page(1%3A1023).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETakeaway%3C%2FSTRONG%3E%3A%3C%2FP%3E%0A%3CP%3E1)%20SGAM%20only%20shows%20a%20part%20of%20mixed%20extents%2C%20not%20all%20of%20them.%20Please%20see%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3CEM%3ESample%207%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FSTRONG%3Efor%20more%20detail.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1224874087%22%20id%3D%22toc-hId-1224874087%22%3E2)%E2%80%98NOT%20ALLOCATED%E2%80%99%20is%20misleading%20%2C%20you%20see%20the%20%E2%80%98NOT%20ALLOCATED%E2%80%99%20when%20the%20corresponding%20bit%20is%200%3A%20the%20extent%20is%20not%20used%20as%20a%20mixed%20extent%2C%20or%20it%20is%20a%20mixed%20extent%20and%20all%20its%20pages%20are%20being%20used.%20Please%20see%20the%20Sample%207%20for%20more%20detail.%3C%2FH3%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%3E%3CSTRONG%3ESample%205%3C%2FSTRONG%3E%3A%20GAM%20detail%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20review%20the%20GAM%20page%20from%20different%20perspective.%3C%2FP%3E%0A%3CP%3ERun%20DBCC%20PAGE%20again%20with%20the%20parameter%201%20instead%20of%203.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_9-1598163816419.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214133i4DC698A01B8A4A01%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_9-1598163816419.png%22%20alt%3D%22Liwei_9-1598163816419.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%200000381f%20are%20reserved%2C%20the%20valid%20record%20starts%20from%20the%20fifth%20byte%3A00%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20talk%20a%20look%20at%2000000000%2000fe%3C%2FP%3E%0A%3CP%3EIt%E2%80%99s%20hex%2C%20Let%20me%20convert%20to%20binary%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_1-1598194086002.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214164iF4D7BD29E8649447%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_1-1598194086002.png%22%20alt%3D%22Liwei_1-1598194086002.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EBecause%20the%20bit%20of%20the%20extent%200~%20extent%2040(totally%2041%20extents)%20are%20all%200%2C%20they%20are%20allocated%2C%20either%20in%20GAM%20or%20SGAM.%20so%20does%20the%20page%20(1%3A0)~page(1%3A327).%3C%2FSPAN%3EIf%20the%20bit%20is%201%2C%20the%20extent%20is%20free%3B%20if%20the%20bit%20is%200%2C%20the%20extent%20is%20allocated%2C%20either%20in%20GAM%20or%20SGAM.%3C%2FP%3E%0A%3CP%3EThe%20bit%20of%20extent%2041%20is%201%2C%20so%20extent%2041%20is%20not%20allocated.%20The%20related%20page%20(1%3A328)%20is%20not%20allocated%20at%20all.%20As%20the%20rest%20of%20bits%2Fbytes%20are%201%2C(f%20stands%20for%201111)%3C%2FP%3E%0A%3CP%3EIt%20exactly%20matches%20the%20content%20of%20DBCC%20Page%20with%20parameter%203.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_10-1598163816420.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214134i538937144C9DBFE8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_10-1598163816420.png%22%20alt%3D%22Liwei_10-1598163816420.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESample%206%3C%2FSTRONG%3E%3A%20SGAM%20detail%3C%2FP%3E%0A%3CP%3ELet's%20review%20the%20SGAM%20page%20from%20a%20different%20perspective.%3C%2FP%3E%0A%3CP%3ERun%20DBCC%20PAGE%20again%20%2C%20but%20with%20the%20parameter%201%20instead%203.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_11-1598163816420.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214135i5620D10B55CFD77B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_11-1598163816420.png%22%20alt%3D%22Liwei_11-1598163816420.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%200000381f%20are%20reserved%2C%20the%20really%20record%20starts%20from%20the%20fifth%20byte%3A00%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20talk%20a%20look%20at%2000000040%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%E2%80%99s%20hex%2C%20now%20convert%20to%20binary%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_0-1598194062212.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214163i0CD43926E009F4A3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_0-1598194062212.png%22%20alt%3D%22Liwei_0-1598194062212.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EBecause%20the%20bit%20of%20the%20extent%200~extent%2029(totally%2030%20extents)%20are%20all%200%2C%20these%20extents%20are%20not%20used%20as%20a%20mixed%20extent%2C%20or%20it%20is%20a%20mixed%20extent%20and%20all%20its%20pages%20are%20being%20used.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20The%20pages%20in%20extent%200~29%20are%20(1%3A0)~(1%3A239).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20The%20first%20page%20of%20extent%2029%20is%20(1%3A232).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20The%20bit%20of%20extent%2030%20is%201%2C%20so%20the%20extent%20is%20used%20as%20a%20mixed%20extent%2C%20so%20does%20the%20page(1%3A240)~page(1%3A247)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20The%20bit%20of%20extent%2031%20is%200%2C%20so%20the%20extent%20is%20used%20as%20a%20mixed%20extent%2C%20so%20the%20extent%20is%20not%20used%20as%20a%20mixed%20extent%2C%20or%20it%20a%20mixed%20extent%20and%20all%20its%20pages%20are%20being%20used.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20exactly%20matches%20the%20content%20of%20DBCC%20Page%20with%20parameter%203.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_12-1598163816421.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214136i61560911DF01431D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_12-1598163816421.png%22%20alt%3D%22Liwei_12-1598163816421.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETakeaway%3C%2FSTRONG%3E%3A%20You%20can%20tell%20if%20the%20extent%20is%20allocated%20by%20checking%20the%20GAM%20and%20SGAM%20page%2C%20but%20you%20can%E2%80%99t%20tell%20if%20it%E2%80%99s%20mixed%20extent%20or%20uniformed%20extent.%20You%20need%20to%20combine%20the%20info%20with%20IAM%20page.%20I%E2%80%99m%20going%20to%20cover%20the%20topic%20in%20next%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fsql-server-support%2Fsql-server-iam-page%2Fba-p%2F1637065%22%20target%3D%22_self%22%3Epost%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESample%207%3C%2FSTRONG%3E%3A%20Insert%20more%20rows%20to%20make%20the%20heaptable1%20has%208%20pages%20to%20observe%20how%20GAM%20and%20SGAM%20work.%3C%2FP%3E%0A%3CP%3E1)Insert%20another%207%20rows%2C%20the%20size%20of%20each%20row%20is%20around%208KB.%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(8%2CREPLICATE('i'%2C8000))%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E--page%202%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(9%2CREPLICATE('i'%2C8000))%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E--page%203%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(10%2CREPLICATE('j'%2C8000))%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E--page%204%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(11%2CREPLICATE('k'%2C8000))%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E--page%205%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(12%2CREPLICATE('l'%2C8000))%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E--page%206%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(13%2CREPLICATE('m'%2C8000))%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E--page%207%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Einsert%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheaptable1%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalues(14%2CREPLICATE('n'%2C8000))%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E--page%208%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E2)There%20are%208%20pages%20now.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_13-1598163816421.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214137iED24EC9DB9F9A6E9%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_13-1598163816421.png%22%20alt%3D%22Liwei_13-1598163816421.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3)Extent%20and%20page%20type%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eallocated_page_file_id%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%5BFileID%5D%2Callocated_page_page_id%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%5BPageID%5D%2Cpage_type_desc%2Cextent_page_id%2F8%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EExtentID%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis_mixed_page_allocation%2Cextent_page_id%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%5BFirst%20Page%20in%20Extent%5D%2Cextent_page_id%2B7%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%5BLastPage%20in%20Extent%5D%2Cis_allocated%26nbsp%3BFrom%3CSPAN%3E%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Esys.dm_db_database_page_allocations(db_id()%2Cobject_id('dbo.heaptable1')%2Cnull%2Cnull%2C'detailed')%3CSPAN%3E%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Eorder%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eby%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eallocated_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_14-1598163816432.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214138i8F5A2D3D49175B15%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_14-1598163816432.png%22%20alt%3D%22Liwei_14-1598163816432.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThese%20pages%20belong%20to%20two%20different%20mixed%20extents%2C%20which%20are%20expected.%3C%2FP%3E%0A%3CP%3E4)GAM%20also%20reflects%20the%20change.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_15-1598163816423.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214139iD6B5F2D20F4B6DFA%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_15-1598163816423.png%22%20alt%3D%22Liwei_15-1598163816423.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E5)Let%E2%80%99s%20check%20the%20SGAM%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_16-1598163816423.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214140i023729D595CFBA1E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_16-1598163816423.png%22%20alt%3D%22Liwei_16-1598163816423.png%22%20%2F%3E%3C%2FSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%E2%80%98(1%3A328)%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E-%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3D%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EALLOCATED%E2%80%99%20is%20marked%20as%20mixed%20extent%2C%20which%20makes%20sense.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B(1%3A0)%26nbsp%3B%20%26nbsp%3B-%26nbsp%3B%20%26nbsp%3B(1%3A320)%20is%20marked%20as%20'NOT%20ALLOCATED'%2C%20however%20we%20already%20now%20that%20the%20page%3A245%2C246%2C247%20are%20allocated%20in%20mixed%20extent.(See%20Sample%204)%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESample%208%3C%2FSTRONG%3E%3A%20100%20Percent%20full.%20(Please%20review%20sample%202)%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_17-1598163816424.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214141iC89384387F241B94%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_17-1598163816424.png%22%20alt%3D%22Liwei_17-1598163816424.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPage%20247%2C328%2C329%2C330%2C331%2C332%20and%20323%20are%20almost%20full%20because%20every%20row%20in%20pages%20is%20more%20than%208KB.%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20check%20the%20PFS%20page.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_18-1598163816425.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214142i3B940080EE42B902%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_18-1598163816425.png%22%20alt%3D%22Liwei_18-1598163816425.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDisplay%20again%20using%20the%20parameter%201%20instead%20of%203.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Liwei_19-1598163816432.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214143i301C8E102C94CD4D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Liwei_19-1598163816432.png%22%20alt%3D%22Liwei_19-1598163816432.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20may%20restore%20the%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2Fattachments%2Fgxcuf89792%2FSQLServerSupport%2F1027%2F2%2Fdbtest20200823.zip%22%20target%3D%22_self%22%3Ebackup%3C%2FA%3E%20file%20and%20give%20it%20a%20try.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1606011%22%20slang%3D%22en-US%22%3E%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%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1606011%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EStorage%20Engine%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

I’m going to start a series of posts talking about SQL Server allocation pages and corruption. Each post will have samples showing how SQL Server use these pages and scenarios of corruption.

 

The first post will talk about the Extents, PFS, GAM, SGAM and IAM and related corruptions, you can find all concepts from following two pages:

Pages and Extents Architecture Guide

Under the covers: GAM, SGAM, and PFS pages

 

As there are many concepts and samples, I’m going to discuss the topics in three or four posts.

 

1.Extents

Extents are the basic unit in which space is managed. An extent is eight physically contiguous pages, or 64 KB. This means SQL Server databases have 16 extents per megabyte.

SQL Server has two types of extents:

·         Uniform extents are owned by a single object; all eight pages in the extent can only be used by the owning object.

·         Mixed extents are shared by up to eight objects. Each of the eight pages in the extent can be owned by a different object.

Up to, and including, SQL Server 2014 (12.x), SQL Server does not allocate whole extents to tables with small amounts of data. A new table or index generally allocates pages from mixed extents. When the table or index grows to the point that it has eight pages, it then switches to use uniform extents for subsequent allocations. If you create an index on an existing table that has enough rows to generate eight pages in the index, all allocations to the index are in uniform extents. However, starting with SQL Server 2016 (13.x), the default for all allocations in the database is uniform extents.

 

Sample 1: The first 8 pages are stored in mixed extent.

1)Create an empty database in SQL Server 2017 instance and enable the mixed extent allocation.

create database dbtest

go

alter database dbtest set MIXED_PAGE_ALLOCATION on

2)Create a heap table and insert one row.

create table heaptable1(c1 int, c2 varchar(8000))

insert heaptable1 values(1,REPLICATE('a',1000))    

 

3)Let’s check how these rows and pages stored in SQL Server.

select ht1.c1,ht1.c2, p.file_id,p.page_id, is_mixed_page_allocation

From heaptable1 as ht1 CROSS APPLY sys.fn_PhysLocCracker(%%physloc%%) as p inner join sys.dm_db_database_page_allocations(db_id(),object_id('dbo.heaptable1'),null,null,'detailed') as dddpa

on p.file_id=dddpa.allocated_page_file_id and

p.page_id=dddpa.allocated_page_page_id

Liwei_0-1598163816406.png

 

Because there is only 1 row, in one page, it’s stored in mixed extent.

The page id is:(1:245).

 

2.PFS

Page Free Space (PFS) pages record the allocation status of each page, whether an individual page has been allocated, and the amount of free space on each page. The PFS has 1-byte for each page, recording whether the page is allocated, and if so, whether it is empty, 1 to 50 percent full, 51 to 80 percent full, 81 to 95 percent full, or 96 to 100 percent full.

After an extent has been allocated to an object, the SQL Server Database Engine uses the PFS pages to record which pages in the extent are allocated or free. This information is used when the SQL Server Database Engine has to allocate a new page. The amount of free space in a page is only maintained for heap and Text/Image pages. It is used when the SQL Server Database Engine has to find a page with free space available to hold a newly inserted row. Indexes do not require that the page free space be tracked, because the point at which to insert a new row is set by the index key values.

A new PFS, GAM or SGAM page is added in the data file for every additional range that it keeps track of. Thus, there is a new PFS page 8,088 pages after the first PFS page, and additional PFS pages in subsequent 8,088 page intervals. To illustrate, page ID 1 is a PFS page, page ID 8088 is a PFS page, page ID 16176 is a PFS page, and so on. There is a new GAM page 64,000 extents after the first GAM page and it keeps track of the 64,000-extents following it; the sequence continues at 64,000-extent intervals. Similarly, there is a new SGAM page 64,000 extents after the first SGAM page and additional SGAM pages in subsequent 64,000 extent intervals. The following illustration shows the sequence of pages used by the SQL Server Database Engine to allocate and manage extents.

 

Sample 2: PFS page detail, how does SQL Server map the value ‘1’,’2’,’3’,’4’ to ’50 Percent full’,’80 Percent full’,’95 Percent full’ and ‘100 Percent full’.

1)The first PFS page is (1:1).

2)Run DBCC PAGE to display the content:

Liwei_1-1598163816412.png

 

As the size of row is 1KB, the usage of the page is around 1000.0/8096=12%, so it’s marked as 50 percent full.

Let’s display the content again using the parameter 1 instead of 3.

Liwei_2-1598163816428.png

 

The value is 61.

3)Let’s keep inserting another 4 rows.

insert heaptable1 values(2,REPLICATE('b',1000))    

insert heaptable1 values(3,REPLICATE('c',1000))    

insert heaptable1 values(4,REPLICATE('d',1000))    

insert heaptable1 values(5,REPLICATE('e',1000))  

4)The total size of 5 rows are around 5KB, the usage is around 5000.0/8096=61%, which is greater than 50% , but less than 80%, so it’s marked as 80 percent full.

Liwei_3-1598163816414.png

 

Let’s display the content again using the parameter 1 instead of 3.

Liwei_4-1598163816429.png

 

The value is 62.

 

5)Let’s keep inserting another 2 rows.

insert heaptable1 values(6,REPLICATE('f',1000))    

insert heaptable1 values(7,REPLICATE('g',1000))

 

6)The total size of 7 rows are around 7KB, the usage is around 7000.0/8096=86%, which is greater than 80% , but less than 85%, so it’s marked as 95 percent full.

Liwei_5-1598163816416.png

 

Let’s display the content again using the parameter 1 instead of 3.

Liwei_6-1598163816430.png

 

The value is 63.

Takeaway: Because SQL Server stop storing data in a page of heap when it’s 95%, you won’t see ‘100 percent full’ even if you continue inserting a row with size 1KB.

8)For 100 percent full, please see sample 8.

 

 

3.GAM

Global Allocation Map (GAM)
GAM pages record what extents have been allocated. Each GAM covers 64,000 extents, or almost 4 gigabytes (GB) of data. The GAM has 1-bit for each extent in the interval it covers. If the bit is 1, the extent is free; if the bit is 0, the extent is allocated, either in GAM or SGAM.

Sample 3: GAM explore

1)Let’s check the GAM.

Liwei_7-1598163816418.png

 

2)What does the entry ‘(1:0)        - (1:320)      =     ALLOCATED’ stand for?

   (1:0)   is the first page of first extent in this range.

   (1:320) is the first page of last extent in this range. (1:327) is the last page of this extent.

   All the extents within the range, including the first extent and last extent, are allocated as mixed extent or uniformed extent. 

Takeaway: we can tell if the extents and pages are allocated by checking GAM page, these extents maybe mixed extent or uniform extent.

 3)What does the entry ‘(1:328)        - (1:1016)      =  NOT   ALLOCATED’ stand for?

    (1:328)   is the first page of first extent in this range.

    (1:1016) is the first page of last extent in this range. (1:1023) is the last page of this extent.

             All the extents within the range are not allocated yet.

 

4.SGAM

Shared Global Allocation Map (SGAM)
SGAM pages record which extents are currently being used as mixed extents and also have at least one unused page. Each SGAM covers 64,000 extents, or almost 4-GB of data. The SGAM has 1-bit for each extent in the interval it covers. If the bit is 1, the extent is being used as a mixed extent and has a free page. If the bit is 0, the extent is not used as a mixed extent, or it is a mixed extent and all its pages are being used.

Sample 4: SGAM explore

Let’s check the GAM.

Liwei_8-1598163816418.png

 

2)What does the first entry ‘(1:0)        - (1:232)      = NOT ALLOCATED’ stand for?

    (1:0)   is the first page of first extent in this range.

    (1:232) is the first page of last extent in this range. (1:239) is the last page in this extent.

    Please note: ‘NOT ALLOCATED’ is misleading, you see the ‘NOT ALLOCATED’ when the corresponding bit is 0: the extent is not used as a mixed extent, or it is a mixed extent and all its pages are being used. Please see the Sample 7 for more detail.

 

3)What does the second entry ‘(1:240)      -              =     ALLOCATED’ stand for?

   (1:240)   is the first page of first extent in this range.

   At least this extent is allocated as mixed extent. So do the page(1:240)~(1:247).

 

4)What does the second entry ‘(1:248)      - (1:1016)     = NOT ALLOCATED’ stand for?

     (1:248)   is the first page of first extent in this range.

     (1:1016) is the first page of last extent in this range.

 

     All the extents within the range, including the first extent and last extent, are not allocated as mixed extent. So do the page(1:352)~page(1:1023).

 

Takeaway:

1) SGAM only shows a part of mixed extents, not all of them. Please see the Sample 7 for more detail.

2)‘NOT ALLOCATED’ is misleading , you see the ‘NOT ALLOCATED’ when the corresponding bit is 0: the extent is not used as a mixed extent, or it is a mixed extent and all its pages are being used. Please see the Sample 7 for more detail.

 

 

 

Sample 5: GAM detail

Let’s review the GAM page from different perspective.

Run DBCC PAGE again with the parameter 1 instead of 3.

Liwei_9-1598163816419.png

 

The 0000381f are reserved, the valid record starts from the fifth byte:00

Let’s talk a look at 00000000 00fe

It’s hex, Let me convert to binary:

Liwei_1-1598194086002.png

Because the bit of the extent 0~ extent 40(totally 41 extents) are all 0, they are allocated, either in GAM or SGAM. so does the page (1:0)~page(1:327).If the bit is 1, the extent is free; if the bit is 0, the extent is allocated, either in GAM or SGAM.

The bit of extent 41 is 1, so extent 41 is not allocated. The related page (1:328) is not allocated at all. As the rest of bits/bytes are 1,(f stands for 1111)

It exactly matches the content of DBCC Page with parameter 3.

Liwei_10-1598163816420.png

 

Sample 6: SGAM detail

Let's review the SGAM page from a different perspective.

Run DBCC PAGE again , but with the parameter 1 instead 3.

Liwei_11-1598163816420.png

 

The 0000381f are reserved, the really record starts from the fifth byte:00

Let’s talk a look at 00000040 

It’s hex, now convert to binary:

Liwei_0-1598194062212.png

Because the bit of the extent 0~extent 29(totally 30 extents) are all 0, these extents are not used as a mixed extent, or it is a mixed extent and all its pages are being used.

  The pages in extent 0~29 are (1:0)~(1:239).

  The first page of extent 29 is (1:232).

  The bit of extent 30 is 1, so the extent is used as a mixed extent, so does the page(1:240)~page(1:247)

  The bit of extent 31 is 0, so the extent is used as a mixed extent, so the extent is not used as a mixed extent, or it a mixed extent and all its pages are being used.

 

It exactly matches the content of DBCC Page with parameter 3.

Liwei_12-1598163816421.png

 

Takeaway: You can tell if the extent is allocated by checking the GAM and SGAM page, but you can’t tell if it’s mixed extent or uniformed extent. You need to combine the info with IAM page. I’m going to cover the topic in next post.

 

Sample 7: Insert more rows to make the heaptable1 has 8 pages to observe how GAM and SGAM work.

1)Insert another 7 rows, the size of each row is around 8KB.

insert heaptable1 values(8,REPLICATE('i',8000))      --page 2

insert heaptable1 values(9,REPLICATE('i',8000))      --page 3

insert heaptable1 values(10,REPLICATE('j',8000))     --page 4

insert heaptable1 values(11,REPLICATE('k',8000))     --page 5

insert heaptable1 values(12,REPLICATE('l',8000))     --page 6

insert heaptable1 values(13,REPLICATE('m',8000))     --page 7

insert heaptable1 values(14,REPLICATE('n',8000))     --page 8

2)There are 8 pages now.

Liwei_13-1598163816421.png

 

3)Extent and page type

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_14-1598163816432.png

 

These pages belong to two different mixed extents, which are expected.

4)GAM also reflects the change.

Liwei_15-1598163816423.png

 

5)Let’s check the SGAM

Liwei_16-1598163816423.png    ‘(1:328)      -              =     ALLOCATED’ is marked as mixed extent, which makes sense.

   (1:0)   -   (1:320) is marked as 'NOT ALLOCATED', however we already now that the page:245,246,247 are allocated in mixed extent.(See Sample 4) 

 

Sample 8: 100 Percent full. (Please review sample 2)

Liwei_17-1598163816424.png

 

Page 247,328,329,330,331,332 and 323 are almost full because every row in pages is more than 8KB.

Let’s check the PFS page.

Liwei_18-1598163816425.png

 

Display again using the parameter 1 instead of 3.

Liwei_19-1598163816432.png

 

You may restore the backup file and give it a try.