设为首页 收藏本站
查看: 545|回复: 0

[经验分享] SQL Server -- How to fix Database goes to suspect mode

[复制链接]

尚未签到

发表于 2018-10-14 07:09:04 | 显示全部楼层 |阅读模式
  Problem:
  Database goes to suspect mode
  Root Cause:
  Mostly, the database goes to the Suspect mode caused by the physical database files is corrupt. But there are some other reasons could also cause this issue,
  such as the database file was renamed, or the hardware failure.  We could use this statement
  “SELECT DATABASEPROPERTYEX('DB_NAME','STATUS')” just as Uri Dimant mentioned to check databases whether go to the Suspect mode,
  if it is, this statement return “SUSPECT”.

  When you see the your database in Suspect mode that a code red situation. Its not something that you>  This post will show how to recover from suspect mode, but still go through SQL-server error logs and find out the root cause of the error.
  Reason:
  At start-up, SQL Server attempts to obtain an exclusive lock on the device file. If the device is being used by another process  or if the file is missing, sql server start displaying error.
  In these cases, there is usually nothing wrong with the devices and database. For the database to recover correctly, the device must be made available, and the database status must be reset.
  Possible reason for changed to suspect mode in sql server can be
  The system cannot find the file specified.) during the creation/opening of physical device
  Failed to open device where data or log file resides
  SQL server went down/restarted in the middle of a transaction causes transactions log to be corrupted
  SQL server can not access data or log file while coming online , because of you beloved antivirus
  First Probability: Sometimes, when SQL Server data or log file gets misplaced or deleted while the SQL Server Database was in offline mode, then in that situation data cannot be recovered when you start SQL Server because of missing files. To recover SQL database from suspect mode under such circumstances, you need to place the missing files at their original location. In error log, the SQL Server error will provide correct name and path of the file that are deleted or missing from its location.

  Second Probability: Another cause of SQL Server database being in suspect mode is corrupted transaction. In this case, you might lose data and a>  Third Probability: Now, in case where you find corruption in data file, the likelihood is your Operating System or hardware is failing in their performance. For this type of failure, one must employ an extraneous solution to recover SQL database from suspect mode.
  Troubleshoot &Solution:
  1. Try to reset the db sp_resetstatus 'dbname'
  EXEC sp_resetstatus 'DATABASE_NAME'
  2. If db not comes online then follow the steps.
  3. Take the db into emergency and single user mode.
  4. check the database consistance if any error found repair the db.
  ALTER DATABASE DATABASE_NAME SET EMERGENCY
  DBCC checkdb('DATABASE_NAME')
  ALTER DATABASE DATABASE_NAME SET SINGLE_USER WITH ROLLBACK IMMEDIATE
  --DBCC CHECKDB ('DATABASE_NAME') WITH NO_INFOMSGS, ALL_ERRORMSGS
  --Some data will be loss after run the below command, be carefule to execute it.
  DBCC CheckDB ('DATABASE_NAME', REPAIR_ALLOW_DATA_LOSS)
  5. bring the db into multi user mode.
  ALTER DATABASE DATABASE_NAME SET MULTI_USER
  6. Finally reset the status.
  EXEC sp_resetstatus 'DATABASE_NAME'
  7. Check the DB status, it should be in normal status
  SELECT NAME,STATE_DESC FROM SYS.DATABASES
  WHERE STATE_DESC in ('SUSPECT','RECOVERY_PENDING')
  GO
  8. Rebuild Index for table
  ALTER INDEX ALL ON [YourTableName] REBUILD
  9. If the issue exist.
  If the database is still marked as suspect after performing these steps, there may be other problems preventing the database from recovering.
  At this point, only option left is either restore from a good backup or set the database to emergency mode and use the bulk copy program copy the data out.
  Additionally, you may require performing one or more of the following actions:
  Modify or update statistics.
  Copy all recoverable data in the damaged table to a new table.
  Drop and recreate one or more indexes.
  Use 'sp_recompile' for recompiling your stored procedures and triggers.
  Pre-action:
  in case database goes to suspect mode can we get mail Or alert ? what actions we have to take db goes to suspect mode.
  参考:
  http://www.sqlskills.com/blogs/paul/creating-detaching-re-attaching-and-fixing-a-suspect-database/
  http://www.codeproject.com/Articles/587460/Solution-To-The-MSSQL-Server-Suspect
  https://www.mssqltips.com/sqlservertip/3191/how-to-recover-a-suspect-msdb-database-in-sql-server/
  http://www.snapdba.com/2011/11/how-to-repair-a-sql-server-20052008-database-in-suspect-mode/#.WA73wXm7odk
  https://social.msdn.microsoft.com/Forums/sqlserver/en-us/a8e9eceb-9e41-4853-a66c-f176b15208ee/suspect-mode?forum=sqltools
  https://social.msdn.microsoft.com/Forums/sqlserver/en-US/2291a9a3-ac59-4982-802f-b5450301c04c/what-is-suspect-mode-database?forum=sqlgetstarted
  https://support.microsoft.com/en-us/kb/180500
  http://blog.systoolsgroup.com/sql-suspect-database-recovery.html
  http://www.karaszi.com/sqlserver/info_corrupt_suspect_db.asp
  http://sqlusa.com/bestpractices2005/markedsuspect/
  http://www.stellarsqldatabaserecovery.com/repair-suspect-sql-server.php
  http://social.technet.microsoft.com/wiki/contents/articles/14616.troublshooting-sql-database-suspect-mode.aspx
  http://www.mytechmantra.com/LearnSQLServer/Repair_Suspect_Database_P1.html
  https://support.managed.com/kb/a398/how-to-repair-a-suspect-database-in-mssql.aspx
  脚本:
  检查Suspect DB状态:
  CheckDBStatus.ps1
  修复Suspect DB:
  RepaireSuspectDB.ps1


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-621270-1-1.html 上篇帖子: SQL Server -- 作业(Job) 浅析1 下篇帖子: 深入了解SQL Server 2008的分析服务
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表