不正常关机引起的数据库置疑

不正常关机引起的数据库置疑

昨晚因为家里有事需要马上回家,在下班的时候马上就关机(手提电脑),生怕赶不上公交回去,

但是Windows7关机关了很久(感觉Windows7关机比WindowsXP关机速度相差太远了)

还没有关机完毕,于是本人就拔掉电源,收拾好笔记本电脑就赶公交去了

结果回到家,打开SSMS一看,杯具的事情发生了,有3个数据库置疑

马上打开SQL ERRORLOG看一下,只有一条与置疑有关的信息

1 2013-09-11 17:38:27.97 服务器         SQL Server is terminating because of a system shutdown. This is an informational message only. No user action is required.

 

上面是关机之前的信息

下面是回到家开机的时候的信息

 1 2013-09-11 18:29:06.15 spid31s     错误: 9003,严重性: 20,状态: 1 2 2013-09-11 18:29:06.15 spid31s     The log scan number (37:324:1) passed to log scan in database 'RemoteViewTest2012' is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup. 
 3 2013-09-11 18:29:06.27 spid32s     CHECKDB for database 'DBLOGTEST' finished without errors on 2013-06-10 00:00:46.493 (local time). This is an informational message only; no user action is required.
 4 2013-09-11 18:29:06.61 spid24s     CHECKDB for database 'hengshan' finished without errors on 2013-06-10 00:00:42.547 (local time). This is an informational message only; no user action is required.
 5 2013-09-11 18:29:07.20 spid29s     CHECKDB for database 'TransactionTestDb' finished without errors on 2013-06-10 00:01:01.113 (local time). This is an informational message only; no user action is required.
 6 2013-09-11 18:29:07.45 spid26s     CHECKDB for database 'Northwind' finished without errors on 2013-06-10 00:00:51.853 (local time). This is an informational message only; no user action is required.
 7 2013-09-11 18:29:08.23 spid27s     CHECKDB for database 'partionTest' finished without errors on 2013-09-10 22:52:17.883 (local time). This is an informational message only; no user action is required.
 8 2013-09-11 18:29:08.36 spid4s      Recovery is writing a checkpoint in database 'AdventureWorks' (6). This is an informational message only. No user action is required.
 9 2013-09-11 18:29:06.60 spid31s     错误: 3414,严重性: 21,状态: 110 2013-09-11 18:29:06.60 spid31s     An error occurred during recovery, preventing the database 'RemoteViewTest2012' (database ID 17) from restarting. Diagnose the recovery errors and fix them, or restore from a known good backup. If errors are not corrected or expected, contact Technical Support.
11 2013-09-11 18:29:08.66 spid31s     CHECKDB for database 'RemoteViewTest2012' finished without errors on 2013-06-10 00:00:46.493 (local time). This is an informational message only; no user action is required.
12 2013-09-11 18:29:08.83 spid20s     CHECKDB for database 'AdventureWorks' finished without errors on 2013-06-10 00:00:08.693 (local time). This is an informational message only; no user action is required.
13 2013-09-11 18:29:09.01 spid30s     CHECKDB for database 'YourSQLDba' finished without errors on 2013-06-10 00:00:46.493 (local time). This is an informational message only; no user action is required.
14 2013-09-11 18:29:10.39 spid23s     1 transactions rolled forward in database 'DLGPOS' (9). This is an informational message only. No user action is required.
15 2013-09-11 18:29:10.66 spid21s     CHECKDB for database 'AdventureWorksDW' finished without errors on 2013-06-10 00:00:35.087 (local time). This is an informational message only; no user action is required.
16 2013-09-11 18:29:10.68 spid21s     0 transactions rolled back in database 'DLGPOS' (9). This is an informational message only. No user action is required.
17 2013-09-11 18:29:10.68 spid21s     Recovery is writing a checkpoint in database 'DLGPOS' (9). This is an informational message only. No user action is required.
18 2013-09-11 18:29:10.82 spid23s     CHECKDB for database 'DLGPOS' finished without errors on 2013-06-13 23:14:53.543 (local time). This is an informational message only; no user action is required.
19 2013-09-11 18:29:13.47 spid22s     CHECKDB for database 'dbdreamlink' finished without errors on 2013-06-10 00:00:37.570 (local time). This is an informational message only; no user action is required.
20 2013-09-11 18:29:13.69 spid28s     错误: 9003,严重性: 20,状态: 121 2013-09-11 18:29:13.69 spid28s     The log scan number (276:83:1) passed to log scan in database 'GPOSDB' is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup. 
22 2013-09-11 18:29:13.69 spid28s     错误: 3414,严重性: 21,状态: 123 2013-09-11 18:29:13.69 spid28s     An error occurred during recovery, preventing the database 'GPOSDB' (database ID 14) from restarting. Diagnose the recovery errors and fix them, or restore from a known good backup. If errors are not corrected or expected, contact Technical Support.
24 2013-09-11 18:29:13.69 spid28s     CHECKDB for database 'GPOSDB' finished without errors on 2013-02-04 10:00:33.557 (local time). This is an informational message only; no user action is required.
25 2013-09-11 18:29:13.88 spid18s     24 transactions rolled forward in database 'msdb' (4). This is an informational message only. No user action is required.
26 2013-09-11 18:29:13.97 spid4s      0 transactions rolled back in database 'msdb' (4). This is an informational message only. No user action is required.
27 2013-09-11 18:29:13.97 spid4s      Recovery is writing a checkpoint in database 'msdb' (4). This is an informational message only. No user action is required.
28 2013-09-11 18:29:15.02 spid18s     CHECKDB for database 'msdb' finished without errors on 2013-06-10 00:00:49.520 (local time). This is an informational message only; no user action is required.
29 2013-09-11 18:29:16.79 spid25s     错误: 9003,严重性: 20,状态: 130 2013-09-11 18:29:16.79 spid25s     The log scan number (193:5320:1) passed to log scan in database 'Monitoring' is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup. 
31 2013-09-11 18:29:16.80 spid25s     错误: 3414,严重性: 21,状态: 132 2013-09-11 18:29:16.80 spid25s     An error occurred during recovery, preventing the database 'Monitoring' (database ID 11) from restarting. Diagnose the recovery errors and fix them, or restore from a known good backup. If errors are not corrected or expected, contact Technical Support.
33 2013-09-11 18:29:16.80 spid25s     CHECKDB for database 'Monitoring' finished without errors on 2013-06-10 00:00:47.140 (local time). This is an informational message only; no user action is required.
34 2013-09-11 18:29:38.33 spid4s      Recovery is writing a checkpoint in database 'pratice' (5). This is an informational message only. No user action is required.
35 2013-09-11 18:29:38.75 spid19s     CHECKDB for database 'pratice' finished without errors on 2013-06-10 00:00:56.963 (local time). This is an informational message only; no user action is required.
36 2013-09-11 18:29:40.27 spid4s      Recovery is complete. This is an informational message only. No user action is required.
37 2013-09-11 18:29:48.07 spid52      Using 'xpsqlbot.dll' version '2005.90.5000' to execute extended stored procedure 'xp_qv'. This is an informational message only; no user action is required.
38 2013-09-11 18:29:52.60 spid52      Using 'xpstar90.dll' version '2005.90.5000' to execute extended stored procedure 'xp_instance_regread'. This is an informational message only; no user action is required.
39 2013-09-11 18:29:53.21 spid52      Using 'xplog70.dll' version '2005.90.5000' to execute extended stored procedure 'xp_msver'. This is an informational message only; no user action is required.
40 2013-09-11 19:03:59.16 spid57      Common language runtime (CLR) functionality initialized using CLR version v2.0.50727 from C:\Windows\Microsoft.NET\Framework\v2.0.50727\.
41 2013-09-11 19:03:59.82 spid57      AppDomain 2 (pratice.dbo[runtime].1) created.
42 2013-09-11 19:10:02.86 spid59      DBCC TRACEON 3604, server process ID (SPID) 59. This is an informational message only; no user action is required.
43 2013-09-11 19:10:02.92 spid59      DBCC TRACEOFF 3604, server process ID (SPID) 59. This is an informational message only; no user action is required.

 

由于我没有做数据库备份,只能使用下面的SQL脚本来逐个数据库逐个数据库紧修复

 1 --恢复数据库置疑状态sp_resetstatus 2013-5-9           已放博客园
 2 EXEC [sys]. [sp_resetstatus] @DBName = 'GPOSDB'
 3   --重置置疑数据库的状态
 4 
 5 --sp_resetstatus 关闭数据库上的置疑标记。此过程更新 sysdatabases 中的命名数据库的模式和状态列。
 6 --在运行此过程之前,应参考 SQL Server 错误日志并解决所有问题。执行 sp_resetstatus 后停止并重新启动SQL Server。
 7 --由于某些原因,数据库可能成为置疑状态。
 8 --可能的原因包括操作系统拒绝对数据库资源的访问,以及一个或多个数据库文件不可用性或已损坏。
 9 
10 ALTER DATABASE [GPOSDB] SET EMERGENCY
11 GO
12 DBCC CHECKDB ( 'GPOSDB') WITH NO_INFOMSGS ,ALL_ERRORMSGS
13 
14 
15 ALTER DATABASE [GPOSDB] SET SINGLE_USER  WITH ROLLBACK IMMEDIATE
16 
17 EXEC sys.SP_CONFIGURE 'ALLOW UPDATES' , 1
18 RECONFIGURE WITH OVERRIDE
19 GO
20 RECONFIGURE WITH OVERRIDE
21 GO
22 
23 DBCC checkdb( 'GPOSDB',REPAIR_ALLOW_DATA_LOSS )
24 GO
25 
26 ALTER DATABASE [GPOSDB] SET MULTI_USER
27 GO
28 
29 
30 ALTER DATABASE [GPOSDB] SET ONLINE
31 GO
View Code

输出的信息

  1 数据库 "RemoteViewTest2012" 上的可疑标志已经重置。
  2 配置选项 'allow updates' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
  3 警告: 数据库 'RemoteViewTest2012' 的日志已重新生成。已失去事务的一致性。RESTORE 链已断开,服务器不再有以前的日志文件的上下文,因此您需要了解它们的内容。应运行 DBCC CHECKDB 验证物理一致性。数据库已置于 dbo-only 模式。在准备使数据库可用时,需要重置数据库选项,并删除所有多余的日志文件。 
  4 RemoteViewTest2012的 DBCC 结果。
  5 Service Broker 消息 9675,状态 1: 已分析的消息类型: 14  6 Service Broker 消息 9676,状态 1: 已分析的服务约定: 6  7 Service Broker 消息 9667,状态 1: 已分析的服务: 3  8 Service Broker 消息 9668,状态 1: 已分析的服务队列: 3  9 Service Broker 消息 9669,状态 1: 已分析的会话端点: 0 10 Service Broker 消息 9674,状态 1: 已分析的会话组: 0 11 Service Broker 消息 9670,状态 1: 已分析的远程服务绑定: 0 12 sys.sysrowsetcolumns的 DBCC 结果。
 13 对象 'sys.sysrowsetcolumns'5 页中有 541 行。
 14 sys.sysrowsets的 DBCC 结果。
 15 对象 'sys.sysrowsets'1 页中有 79 行。
 16 sysallocunits的 DBCC 结果。
 17 对象 'sysallocunits'1 页中有 90 行。
 18 sys.sysfiles1的 DBCC 结果。
 19 对象 'sys.sysfiles1'1 页中有 2 行。
 20 sys.syshobtcolumns的 DBCC 结果。
 21 对象 'sys.syshobtcolumns'5 页中有 541 行。
 22 sys.syshobts的 DBCC 结果。
 23 对象 'sys.syshobts'1 页中有 79 行。
 24 sys.sysftinds的 DBCC 结果。
 25 对象 'sys.sysftinds'0 页中有 0 行。
 26 sys.sysserefs的 DBCC 结果。
 27 对象 'sys.sysserefs'1 页中有 90 行。
 28 sys.sysowners的 DBCC 结果。
 29 对象 'sys.sysowners'1 页中有 14 行。
 30 sys.sysprivs的 DBCC 结果。
 31 对象 'sys.sysprivs'1 页中有 120 行。
 32 sys.sysschobjs的 DBCC 结果。
 33 对象 'sys.sysschobjs'1 页中有 51 行。
 34 sys.syscolpars的 DBCC 结果。
 35 对象 'sys.syscolpars'7 页中有 425 行。
 36 sys.sysnsobjs的 DBCC 结果。
 37 对象 'sys.sysnsobjs'1 页中有 1 行。
 38 sys.syscerts的 DBCC 结果。
 39 对象 'sys.syscerts'0 页中有 0 行。
 40 sys.sysxprops的 DBCC 结果。
 41 对象 'sys.sysxprops'0 页中有 0 行。
 42 sys.sysscalartypes的 DBCC 结果。
 43 对象 'sys.sysscalartypes'1 页中有 27 行。
 44 sys.systypedsubobjs的 DBCC 结果。
 45 对象 'sys.systypedsubobjs'0 页中有 0 行。
 46 sys.sysidxstats的 DBCC 结果。
 47 对象 'sys.sysidxstats'2 页中有 142 行。
 48 sys.sysiscols的 DBCC 结果。
 49 对象 'sys.sysiscols'1 页中有 257 行。
 50 sys.sysbinobjs的 DBCC 结果。
 51 对象 'sys.sysbinobjs'1 页中有 23 行。
 52 sys.sysobjvalues的 DBCC 结果。
 53 对象 'sys.sysobjvalues'23 页中有 144 行。
 54 sys.sysclsobjs的 DBCC 结果。
 55 对象 'sys.sysclsobjs'1 页中有 14 行。
 56 sys.sysrowsetrefs的 DBCC 结果。
 57 对象 'sys.sysrowsetrefs'0 页中有 0 行。
 58 sys.sysremsvcbinds的 DBCC 结果。
 59 对象 'sys.sysremsvcbinds'0 页中有 0 行。
 60 sys.sysxmitqueue的 DBCC 结果。
 61 对象 'sys.sysxmitqueue'0 页中有 0 行。
 62 sys.sysrts的 DBCC 结果。
 63 对象 'sys.sysrts'1 页中有 1 行。
 64 sys.sysconvgroup的 DBCC 结果。
 65 对象 'sys.sysconvgroup'0 页中有 0 行。
 66 sys.sysdesend的 DBCC 结果。
 67 对象 'sys.sysdesend'0 页中有 0 行。
 68 sys.sysdercv的 DBCC 结果。
 69 对象 'sys.sysdercv'0 页中有 0 行。
 70 sys.syssingleobjrefs的 DBCC 结果。
 71 对象 'sys.syssingleobjrefs'1 页中有 133 行。
 72 sys.sysmultiobjrefs的 DBCC 结果。
 73 对象 'sys.sysmultiobjrefs'1 页中有 106 行。
 74 sys.sysdbfiles的 DBCC 结果。
 75 对象 'sys.sysdbfiles'1 页中有 2 行。
 76 sys.sysguidrefs的 DBCC 结果。
 77 对象 'sys.sysguidrefs'0 页中有 0 行。
 78 sys.sysqnames的 DBCC 结果。
 79 对象 'sys.sysqnames'1 页中有 91 行。
 80 sys.sysxmlcomponent的 DBCC 结果。
 81 对象 'sys.sysxmlcomponent'1 页中有 93 行。
 82 sys.sysxmlfacet的 DBCC 结果。
 83 对象 'sys.sysxmlfacet'1 页中有 97 行。
 84 sys.sysxmlplacement的 DBCC 结果。
 85 对象 'sys.sysxmlplacement'1 页中有 17 行。
 86 sys.sysobjkeycrypts的 DBCC 结果。
 87 对象 'sys.sysobjkeycrypts'0 页中有 0 行。
 88 sys.sysasymkeys的 DBCC 结果。
 89 对象 'sys.sysasymkeys'0 页中有 0 行。
 90 sys.syssqlguides的 DBCC 结果。
 91 对象 'sys.syssqlguides'0 页中有 0 行。
 92 sys.sysbinsubobjs的 DBCC 结果。
 93 对象 'sys.sysbinsubobjs'0 页中有 0 行。
 94 sys.queue_messages_1977058079的 DBCC 结果。
 95 对象 'sys.queue_messages_1977058079'0 页中有 0 行。
 96 sys.queue_messages_2009058193的 DBCC 结果。
 97 对象 'sys.queue_messages_2009058193'0 页中有 0 行。
 98 sys.queue_messages_2041058307的 DBCC 结果。
 99 对象 'sys.queue_messages_2041058307'0 页中有 0 行。
100 WebHits_ShangHai的 DBCC 结果。
101 对象 'WebHits_ShangHai'1 页中有 1 行。
102 CHECKDB 在数据库 'RemoteViewTest2012' 中发现 0 个分配错误和 0 个一致性错误。
103 DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。
View Code

 

修复完毕之后,查询了那些置疑数据库,发现数据都没有丢失,这个事情算解决完了

 

小结:

在这里要提醒大家注意的是

(1)平时要正确断开数据库链接,并正常关机

(2)定期做好数据库备份

(3)最好使用UPS保证断电的时候不会发生杯具的事情

 

我们曾经遇到过有两三个客户就是因为突然断电,刚好UPS也坏了,造成数据库置疑,幸好有数据库备份,不然就惨了 

 

当然,这个是我私人笔记本电脑,即使数据丢失损失也不大,但是大家在客户那里一定要做好数据保护工作,定期做好备份

不然的话,等杯具来临的时候损失就不是你个人可以承担的了

 

posted @ 2013-09-12 13:05  桦仔  阅读(3504)  评论(1编辑  收藏  举报