不正常關機引起的數據庫置疑
昨晚因為家里有事需要馬上回家,在下班的時候馬上就關機(手提電腦),生怕趕不上公交回去,
但是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,狀態: 1。 10 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,狀態: 1。 21 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,狀態: 1。 23 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,狀態: 1。 30 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,狀態: 1。 32 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
輸出的信息

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 輸出了錯誤信息,請與系統管理員聯系。
修復完畢之后,查詢了那些置疑數據庫,發現數據都沒有丟失,這個事情算解決完了
小結:
在這里要提醒大家注意的是
(1)平時要正確斷開數據庫鏈接,並正常關機
(2)定期做好數據庫備份
(3)最好使用UPS保證斷電的時候不會發生杯具的事情
我們曾經遇到過有兩三個客戶就是因為突然斷電,剛好UPS也壞了,造成數據庫置疑,幸好有數據庫備份,不然就慘了
當然,這個是我私人筆記本電腦,即使數據丟失損失也不大,但是大家在客戶那里一定要做好數據保護工作,定期做好備份
不然的話,等杯具來臨的時候損失就不是你個人可以承擔的了