惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
Forbes - Security
Forbes - Security
雷峰网
雷峰网
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
V
Visual Studio Blog
月光博客
月光博客
博客园 - Franky
有赞技术团队
有赞技术团队
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
The Register - Security
The Register - Security
S
SegmentFault 最新的问题
博客园 - 司徒正美
P
Proofpoint News Feed
Know Your Adversary
Know Your Adversary
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
Arctic Wolf
Cyberwarzone
Cyberwarzone
Simon Willison's Weblog
Simon Willison's Weblog
U
Unit 42
P
Proofpoint News Feed
Scott Helme
Scott Helme
MyScale Blog
MyScale Blog
T
Tenable Blog
Hugging Face - Blog
Hugging Face - Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
P
Palo Alto Networks Blog
V
V2EX
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tailwind CSS Blog
V
Vulnerabilities – Threatpost
Latest news
Latest news
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
Intezer
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
博客园 - 【当耐特】
B
Blog RSS Feed
N
Netflix TechBlog - Medium
Recent Announcements
Recent Announcements
NISL@THU
NISL@THU
C
Cisco Blogs
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security

博客园 - nzperfect

PAGELATCH_EX Contention on 2:1:103 SQL Server AlwaysON 同步模式的疑似陷阱 XEvent – SQL Server Log文件对磁盘的写操作大小是多少 SQL Server Log文件对磁盘的写操作大小是多少 Initializing the FallBack certificate failed . TDSSNIClient initialization failed Error after SQL Server 2012 installation: Login Failure for "SQL Server Integration Services 11.0" SSIS service SQL Server 灾难恢复31天之第6天:管理区分配页损坏处理 SQL Server 灾难恢复31天之第3天:在还原数据库时确定需要哪些备份文件 SQL Server 灾难恢复31天之第4天:备份 SQL Server 灾难恢复31天之第2天:包含数据库备份在还原时的保护 SQL Server 灾难恢复31天之第1天:DBCC CHECK命令会自动使用已经存在的数据库快照吗? 发布订阅延迟故障排查案例:分发读进程延迟 Query Hint FAST number_rows 改变SQL Server 执行计划 SQL Server 通过界面生成修改列类型脚本时的一个风险(或Bug) 是什么引起执行计划变得极其糟糕? 应该使用更新统计信息来解决它吗? 如何完整的修改一个数据库的名称 update值与原值相同时,SQL Server会真的去update还是忽略呢? How can I bring mirror database online after principal server is down ? performance monitor没有SQL Server性能计数器
SQL Server 灾难恢复31天之第5天:处理损坏的非聚集索引
nzperfect · 2013-01-11 · via 博客园 - nzperfect

说明:灾难恢复系列的文章是由 Robert Davis 写的,发布在SQLSoldier 个人认为挺不错的,所以根据自己的理解,边测试边整理,并非直接翻译,如有不准确,欢迎指正。

本篇进入数据库灾难恢复第五篇,从本篇开始,主要深入讲述一些数据page损坏的问题,先从容易修复的非聚集索引开始。

通常,处理数据损坏的情况按三个步骤进行:

1.确定损坏(使用DBCC CHECKDB)
2.确定损坏的对象及对象类型(如索引页、分配页等)
3.确定适合的修复方法

确定损坏
当我们在做一些例行完整性检查或者收到一些其它的错误或警告,如果有一个page损坏的信息,不要直接就去处理这个页面,应该先对数据库运行DBCC CHECCKDB做一下全面检查,以确定是不是其它页面造成的。

使用DBCC CHECKDB可让看到哪些page损坏,我们通过使用No_InfoMsgs选项过滤不需要的信息,同时使用All_ErrorMsgs确保返回所有错误,为了可读性,我们用TableResults 选项将其结果格式化成表,如:

DBCC CheckDB(AdventureWorksDW2012)
    With No_InfoMsgs, All_ErrorMsgs, TableResults;


从结果可以看到返回了一些错误,有些是相同的,需要我们自己找出哪些是真的错误,然后通过具体的错误信息找出对象id,索引id,分区id,分配单元id,文件及页面(object ID, index ID, partition ID, allocation unit ID, file, and page.)。

确定损坏的对象及对象类型
在执行DBCC CHECKDB之后,我们也可以通过msdb的suspect_pages去确定损坏信息,这个表每一行记录一个损坏的page,不过这个表没有对象id和索引id,只有数据库id、文件号、数据页id,如果需要更详细信息,需要用DBCC PAGE去查看了。在这里我们不用这个方法,因为之前的DBCC CHECKDB中已经有这些信息。

SELECT DB_NAME(database_id),[file_id],page_id,
CASE event_type
WHEN 1 THEN '823 or 824 or Torn Page'
WHEN 2 THEN 'Bad Checksum'
WHEN 3 THEN 'Torn Page'
WHEN 4 THEN 'Restored'
WHEN 5 THEN 'Repaired (DBCC)'
WHEN 7 THEN 'Deallocated (DBCC)'
END,
error_count,
last_update_date
FROM msdb..suspect_pages


索引ID对应索引类型:
    ID 0 = heap(堆)
    ID 1 = clustered index(聚集索引)
    ID > 1 = nonclustered index(非聚集索引)

确定适合的修复方法

从上面的结果,我们知道是需要修复一个非聚集索引,由于聚集索引或堆没有损坏,所以最简单的方法是删除再重新它。不过在这里,我们也试一下重建索引(rebuild index)和创建索引时使用Drop_Existing选项是否可以呢?

首先,我们通过下面的SQL得到表名和索引名:

Select Object_Name(object_id) As TableName, name As IndexName
From sys.indexes
Where object_id = 341576255
and index_id = 2


然后试试Rebuild index

-- Rebuild the index??
Alter Index IX_FactResellerSales_CurrencyKey
    On dbo.FactResellerSales
    Rebuild;

结果:

The statement has been terminated.
Msg 824, Level 24, State 2, Line 2
SQL Server detected a logical consistency-based I/O error: incorrect pageid (expected 1:7171; actual 0:0). It occurred during a read of page (1:7171) in database ID 5 at offset 0x00000003806000 in file 'D:\SQL2012\Data\AdventureWorksDW2008R2_Data.mdf'.  Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.

再试创建索引时用Drop_Existing,结果得到同样的结果:

最后我们用删除再重新创建,修复成功:

我们再次运行DBCC CHECKDB,已经没有错误了:

修复完成。

总结
本篇展示的是一个比较容易修复的非聚集索引问题,当我们到一个损坏的page信息时,不要慌,也不要急着直接去修复这个page,而是按照本文的三个步骤来确定最终需要修复谁,在下一篇将会讲述其它的损坏类型:分配页损坏。

下载文中示例用到的数据库及示例SQL.

SQL Server 灾难恢复31天之第6天:管理区分配页损坏处理