What is mean by Pages and Extents in SQL Server
The fundamental unit of data storage in SQL Server is the page. The disk space allocated to a data file (.mdf or .ndf) in a database is logically divided into pages numbered contiguously from 0 to n. Disk I/O operations are performed at the page level. That is, SQL Server reads or writes whole data pages.
Extents are a collection of eight physically contiguous pages and are used to efficiently manage the pages. All pages are organized into extents.
Page
Every piece of data in SQL Server is stored in 8 KB database pages.
A page is a basic unit of I/O operation.
A page starts with a 96-byte header in which all system information (the amount of free space, the page type, the page number, and the allocation unit ID of the object that owns the page) is stored.
Another part of the page is its body or data rows (8,060 bytes). The body contains all the data in rows.
The last part of the database page is row offsets that are located in reverse sequence from the sequence of the rows on the page (36 bytes).
Take a regular book: all content in it is written on pages. Similar to a book, in SQL Server all the data rows are written on pages. In a book, all pages are the same physical size. Similarly, in SQL Server all data pages are the same size - 8 kilobytes. In a book most pages contain the data - the main content of the book - and some pages contain metadata about the content - for example table of contents and index. Again, SQL Server is not different: most pages contain actual rows of data which were stored by users; these are called Data pages and text/image pages (for special cases). The Index pages contain index references about where the data is and finally there are system pages that store variety of metadata about the organization of the data (PFS, GAM, SGAM, IAM, DCM, BCM pages).
Page Types
There are several types of database pages:
- Data Page details how the data is stored inside the data files, database.
- Index Page contains index entries.
- Text and Image contains textual and image data.
- GAM (Global Allocation Map) and SGAM (Shared Global Allocation Map) contain information about whether extents are allocated.
- PFS (Page Free Space) contains information about the free space available on pages and about page allocation.
- IAM (Index Allocation Map) contains information about extents used by a table or index.
- Bulk Changed Map contains the extent information that has been modified by bulk operations since the last BACKUP LOG.
- Differential Changed Map contains the extent information that has changed since the last BACKUP DATABASE.
Extent
Eight physically contiguous pages in SQL Server database are called the extent. One page is 8 KB, therefore one extent is 64 KB.
There are two types of extents in SQL Sever:
- All eight physically contiguous pages belong and can be used only by a single object. This is a uniform extent.
- Each of the eight physically contiguous pages belongs and can be used by eight different objects. This type of extent is known as mixed.
Usually all new tables or indexes are allocated pages from mixed extents. SQL Server extent switches from mixed to uniform type only when a table or index has at least eight or more pages.
Ref:
Post a Comment
0 Comments