设为首页 加入收藏

TOP

SQL Server 的数据存储(SQL Server data strorage)(二)
2014-11-24 02:47:17 来源: 作者: 【 】 浏览:7
Tags:SQL Server 数据 存储 data strorage
nt, or it is a mixed extent and all its pages are being used.

SQL SERVER段申请释放算法很简单:

申请一个uniform段,DB Engine搜索GAM,找到一个为1的bit,把它标识成0;

查找一个有空闲页的mixed段,DB Engine搜索SGAM,找到一个为1的bit;

申请一个mixed段,DB Engine搜索GAM,找到一个为1的bit,把它标识成0,然后到SGAM中将该段标识为1。释放一个段,需要把该段在GAM里标识为1,在SGAM里标识为0.

PFS(Page Free Space)页记录了每一页的申请状态,不管页是否被申请,PFS都记录该页的申请状态和每一页上的空闲空间。PFS用1个字节记录每一页信息:是否被申请,是否empty,是否1~50%被使用,是否51~80%使用,是否81~95%使用,是否96~100%被使用。

在一个段被申请后,DB Engine使用PFS记录段中的页的申请/空闲状态,这些信息在db Engine申请新页时使用,页内空闲空间数量只是针对heap and Text/Image pages,只是在DB Engine在保存新数据行时查找空闲空间时使用。索引的插入不需要页内空闲空间信息,因为insert新行时的点是由索引的key值确定。

PFS页紧跟数据文件的文件头,然后是GAM页,接下来是SGAM页。大约8000页后会有另外一个PFS页,在64000个段后会有另外一个GAM和SGAM页。

三、Tracking Modified Extents(跟踪段的变化)

SQL Server用2种数据结构管理段的变化,DCM和BCM,这两种结构类似GAM和SGAM,都是用位图管理,具体描述如下:

DCM(Differential Changed Map):用来跟踪上次DB backup后所有变化的段,用位图表示段的状态,1表示该段被modified过,0表示没有被更改过。这些信息对增量备份非常有用,这是不必扫描所有的段。DCM tracks the extents that have changed since the last BACKUP DATABASE statement. If the bit for an extent is 1, the extent has been modified since the last BACKUP DATABASE statement. If the bit is 0, the extent has not been modified. Differential backups read just the DCM pages to determine which extents have been modified. This greatly reduces the number of pages that a differential backup must scan. The length of time that a differential backup runs is proportional to the number of extents modified since the last BACKUP DATABASE statement and not the overall size of the database.

BCM (Bulk Changed Map):用来跟踪上次LOG backup后所有因为bulk日志导致变更的段。用位图表示段的状态,1表示该段被modified过,0表示没有被更改过。This tracks the extents that have been modified by bulk logged operations since the last BACKUP LOG statement. If the bit for an extent is 1, the extent has been modified by a bulk logged operation after the last BACKUP LOG statement. If the bit is 0, the extent has not been modified by bulk logged operations. Although BCM pages appear in all databases, they are only relevant when the database is using the bulk-logged recovery model. In this recovery model, when a BACKUP LOG is performed, the backup process scans the BCMs for extents that have been modified. It then includes those extents in the log backup. This lets the bulk logged operations be recovered if the database is restored from a database backup and a sequence of transaction log backups. BCM pages are not relevant in a database that is using the simple recovery model, because no bulk logged operations are logged. They are not relevant in a database that is using the full recovery model, because that recovery model treats bulk logged operations as fully logged operations.

DCM和BCM都可以记录大约4G的段空间状态,他们紧邻GAM和SGAM之后。

\

摘自 footpath的专栏

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇SQL Server里查询表结构命令 下一篇SQLServer导入Excel的应用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: