[日常工作] SQLSERVER 数据库出问题..搜索到的有用的网页信息
(Check out my Pluralsight online training course: SQL Server: Detecting and Correcting Database Corruption.)
This is a question that I was sent over email that I thought would make a good post, and I’m waiting to do a user group presentation in Australia at 2am, so this will keep me busy :-)
Imagine you come to work in the morning and notice that some new rows have been entered into the msdb.dbo.suspect_pages table during the night. Usually the first thing you’re going to do is run DBCC CHECKDB, but if your database is a few TB, that could be several hours before you know where the problem is, and which table may have lost data. You want to find out which table is involved as soon as possible so you can explore your disaster recovery options.
Another scenario is troubleshooting a poorly performing query workload, running my script to look at the currently waiting threads using sys.dm_os_waiting_tasks, seeing a lot of PAGELATCH_EX waits and needing to figure out which table is involved from the page ID in the resource_description column in the sys.dm_os_waiting_tasks output.
Going back to the first scenario, getting the data from the suspect_pages table is easy:
|
1
2
|
SELECT * FROM [msdb].[dbo].[suspect_pages];GO |
database_id file_id page_id event_type error_count last_update_date----------- ----------- -------------------- ----------- ----------- -----------------------6 1 295 2 2 2014-09-25 01:18:22.910 |
Finding the table name requires first using DBCC PAGE. The syntax for DBCC PAGE is:
dbcc page ( {'dbname' | dbid}, filenum, pagenum [, printopt={0|1|2|3} ]) |
You can just use print option 0, as that just displays the page’s header. You also must enable trace flag 3604 to get any output from DBCC PAGE – it’s perfectly safe. So taking the values from our suspect_pages output, that gives us:
|
1
2
3
4
|
DBCC TRACEON (3604);DBCC PAGE (6, 1, 295, 0);DBCC TRACEOFF (3604);GO |
PAGE: (1:295)BUFFER:BUF @0x00000004FD8C7980bpage = 0x00000004A2D14000 bhash = 0x0000000000000000 bpageno = (1:295)bdbid = 6 breferences = 0 bcputicks = 0bsampleCount = 0 bUse1 = 55116 bstat = 0x809blog = 0x15ab215a bnext = 0x0000000000000000 PAGE HEADER:Page @0x00000004A2D14000m_pageId = (1:295) m_headerVersion = 17 m_type = 17m_typeFlagBits = 0x0 m_level = 0 m_flagBits = 0x8200m_objId (AllocUnitId.idObj) = 84 m_indexId (AllocUnitId.idInd) = 256Metadata: AllocUnitId = 72057594043432960Metadata: PartitionId = 72057594039042048 Metadata: IndexId = 0Metadata: ObjectId = 245575913 m_prevPage = (0:0) m_nextPage = (0:0)pminlen = 8008 m_slotCnt = 1 m_freeCnt = 83m_freeData = 8107 m_reservedCnt = 0 m_lsn = (35:200:9)m_xactReserved = 0 m_xdesId = (0:0) m_ghostRecCnt = 0m_tornBits = 1093512791 DB Frag ID = 1 Allocation StatusGAM (1:2) = ALLOCATED SGAM (1:3) = ALLOCATEDPFS (1:1) = 0x64 MIXED_EXT ALLOCATED 100_PCT_FULL DIFF (1:6) = CHANGEDML (1:7) = NOT MIN_LOGGED |
We’re interested in the output beginning Metadata:. Those fields are not stored on the page itself. When I rewrote DBCC PAGE for SQL Server 2005, I added the Metadata:output to make it easier to find the object and index ID that the page is part of (as these used to be the m_objId and m_indexId fields in SQL Server 7.0 and 2000).
The Metadata: ObjectId field is what we want. If you see it is 99, then stop as that means the damaged page is part of the allocation system and not part of a table and you’ll need to wait for DBCC CHECKDB to complete to know the extent of the damage.
If you see the ObjectId is 0, that means there was no metadata found. This could be because:
- The table that the page was part of has been deleted since the page corruption was logged
- The system catalogs are corrupt in some way
- The page is corrupt and so incorrect values were used to look up the metadata
In any case, you’ll need to wait for DBCC CHECKDB to complete to know the extent of the damage.
If the ObjectId is not 0 or 99, we can plug it into the OBJECT_NAME function to give us the name of the table:
|
1
2
|
SELECT OBJECT_NAME (245575913);GO |
--------------------------------------------------------------------------------------------------------------------------------NULL |
If you get the result above, then there are two possibilities:
- You are in the wrong database context
- The metadata for the database is corrupt, so wait for DBCC CHECKDB to complete
It’s most likely #1 that’s the problem, at least in my experience with helping people out. You can get the database name by taking the database_id in the suspect_pagesoutput and plugging it into the DB_NAME function. Go into the correct database context and try again.
|
1
2
3
4
|
USE [company];GOSELECT OBJECT_NAME (245575913);GO |
--------------------------------------------------------------------------------------------------------------------------------CustomerNames |
So there you go – hope this helps!
PS1 Kenneth Fisher commented with some neat code that will do the job on 2012 and 2014 using the new sys.dm_db_database_page_allocations DMF – check it out. That will work as long as there aren’t any metadata or allocation bitmap corruptions.
PS2 Wayne Sheffield reminded me over email and in a comment that DBCC PAGE doesn’t need 3604 if you use the WITH TABLERESULTS option and programmatically crack the DBCC PAGE results.
Related Posts
- Corruption: Last resorts that people try first…
- EMERGENCY-mode repair: the very, very last resort
- Disaster recovery 101: fixing metadata corruption without a backup
- Using the Dedicated Admin Connection to fix Msg 8992: corrupt system tables
- Creating, detaching, re-attaching, and fixing a SUSPECT database
命令语法信息
So what’s the syntax?
dbcc traceon(3604)
dbcc page ( {‘dbname’ | dbid}, filenum, pagenum [, printopt={0|1|2|3} ])
The filenum and pagenum parameters are taken from the page IDs that come from various system tables and appear in DBCC or other system error messages. A page ID of, say, (1:354) has filenum = 1 and pagenum = 354.
The printopt parameter has the following meanings:
- 0 – print just the page header
- 1 – page header plus per-row hex dumps and a dump of the page slot array (unless its a page that doesn’t have one, like allocation bitmaps)
- 2 – page header plus whole page hex dump
- 3 – page header plus detailed per-row interpretation
[日常工作] SQLSERVER 数据库出问题..搜索到的有用的网页信息的更多相关文章
- [转]SqlServer数据库同步方案详解
SqlServer数据库同步是项目中常用到的环节,若一个项目中的数据同时存在于不同的数据库服务器中,而这些数据库需要被多个不同的网域调用时,配置 SqlServer数据库同步是个比较好的解决方案.Sq ...
- SQLSERVER数据库备份操作和还原操作做了什么
SQLSERVER数据库备份操作和还原操作做了什么 看了这篇文章:还原/备份时做了些什么 自己也测试了一下,下面说的错误日志指的是SQLSERVER ERRORLOG 一般在C:\Program Fi ...
- 关于在Java中链接SQLServer数据库中失败的原因分析
首先声明:笔者是Java的初学者,并且一值是走在自学的道路上,长久以来只有“度娘”相伴.(加入了各种Java学习群,基本没有热心帮人解决问题的.可以理解-_-!!!)大神级的人物就不必看拙文了,没有什 ...
- 数据科学工作者(Data Scientist) 的日常工作内容包括什么
数据科学工作者(Data Scientist) 的日常工作内容包括什么 众所周知,数据科学是这几年才火起来的概念,而应运而生的数据科学家(data scientist)明显缺乏清晰的录取标准和工作内容 ...
- DBA日常工作内容和职责
1.统计数据库总容量 按表空间分别统计: 总容量(单位为M): 2.计算用户下所有对象大小 3计算USERS表空间的大小 4计算该USERS表空间对象大小 ---------------------- ...
- 采用Hibernate框架的研发平台如何能够真正兼容Oracle和sqlServer数据库
都说Hibernate框架的使用可以很容易的让你的研发平台支持多种不同类型的数据库,但实践表明,这里的“容易”,是相对的. 想让研发平台支持多种数据库,并不是一件简单的事,也可以这么说:并不是只要使用 ...
- SQLSERVER 数据库性能的的基本
SQLSERVER 数据库性能的基本 很久没有写文章了,在系统正式上线之前,DBA一般都要测试一下服务器的性能 比如你有很多的服务器,有些做web服务器,有些做缓存服务器,有些做文件服务器,有些做数据 ...
- SQLSERVER 数据库性能的的基本 MVC + EF + Bootstrap 2 权限管理
SQLSERVER 数据库性能的基本 很久没有写文章了,在系统正式上线之前,DBA一般都要测试一下服务器的性能 比如你有很多的服务器,有些做web服务器,有些做缓存服务器,有些做文件服务器,有些做数据 ...
- SQLServer数据库镜像配置
目录 一.目标...2 二.前提条件.限制和建议...2 三.设置概述...2 四.安装Sql Server 2008 enterprise X64.3 4.1.安装.NET3.5.3 4.2.安装时 ...
随机推荐
- c#总结:datatable的方法大全
最近在做一个数据处理,保存到datatable中,在过程中了解了datatable一些用法,总结一下: //定义 DataTable dt = new DataTable(); //写入列名: htT ...
- matlab GUI工作原理
例如,用GUIDE创建名为ceshi的GUI程序,其m文件的主函数有如下形式.那么,打开该GUI时,它到底是怎么运行的呢?以下略作小结,欢迎大家补充 function varargout = cesh ...
- idea ssm项目出现日志中文乱码,封装的json中的msg字段中文乱码(但是json封装的bean中的字段不乱码)等其他各种项目下的中文乱码解决方案
开头划重点!(敲黑板):rebuild和mvn package的循环往复好几次的操作是解决这个问题的最主要的方法! 经过多次试验,发现这样做就可以正常显示中文了 我说为什么有时候乱码,有时候中文正常, ...
- Zabbix实战-简易教程--订阅类
一.需求提出 最近数据中心有一个新的需求,有一批后台任务需要在每天固定时间点运行(凌晨8:00),现在希望能够把这个任务执行的结果定时上报给他. 说明:执行的任务为一个sql查询,查询出来的是每个任务 ...
- 公网API安全--OAuth认证
之前写过一个基于签名的公网API访问安全控制,另一种方式是基于OAuth认证协议做安全控制. 说明 用户访问A客户端,使用B的服务及资源.B只有征得用户的授权,才允许A客户端使用B上用户的资源和服务. ...
- CAN总线的显性电平为什么能覆盖隐性电平?
摘要:在CAN总线中,显性电平是强驱动,隐性电平时弱驱动,因此当有的节点发送显性电平有的节点发送隐性电平时,总线上呈现的肯定是强驱动的状态,这就是CAN总线显性电平可以覆盖隐性电平的原因. 大家都知道 ...
- 基于Vue+Spring MVC+MyBatis+Shiro+Dubbo开发的分布式后台管理系统
本文项目代码: 服务端:https://github.com/lining90567/dubbo-demo-server 前端:https://github.com/lining90567/dubbo ...
- 结对测试 vs 随机测试
在接口测试过程中,最关键的是对参数的各种情况进行测试. 随机测试是指随机选择一些参数值来测. 结对测试是指parewise算法生成较高“性价比”的组合情况来测. 随机测试存在的问题 随机,这两个字本身 ...
- 关于摄像头PCB图设计经验谈
摄像头PCB设计,因为客观原因等.容易引起干扰这是个涉及面大的问题.我们抛开其它因素,仅仅就PCB设计环节来说,分享以下几点心得,供参考交流: 1.合理布置电源滤波/退耦电容:一般在原理图中仅画出若干 ...
- c语言数字图像处理(六):二维离散傅里叶变换
基础知识 复数表示 C = R + jI 极坐标:C = |C|(cosθ + jsinθ) 欧拉公式:C = |C|ejθ 有关更多的时域与复频域的知识可以学习复变函数与积分变换,本篇文章只给出DF ...