码迷,mamicode.com
首页 > 数据库 > 详细

DB处于Recovery Pending状态

时间:2016-05-26 20:35:34      阅读:1748      评论:0      收藏:0      [点我收藏+]

标签:

今天修改了Service Account的密码,然后我restart Service,发现有db处于Recovery Pending状态,查看 Paul Randal 的blog,看到如下定义:

RECOVERY PENDING

  • The database will be in this state if SQL Server knows that recovery needs to be run on the database but something is preventing recovery from starting. This is different from SUSPECT because there’s nothing to say that recovery is going to fail – it just hasn’t started yet.
  • An example of this is when the database wasn’t cleanly shut down (i.e. there was at least one uncommitted transaction active at the time the database was shut down) and the log file has been deleted.

如果是Recovery 还没有开始,那么这将是一个非常好的状态。如果是出现damage,那么,惨了,可能出现数据丢失。

血泪的教训:在Service Restart 之前,一定确保DB没有在运行更新操作,并使用checkpoint保存脏数据。

 

对于Recovery Pending状态,应该如何修复,引用《How to resolve the issue of a database that was in Recovery Pending mode

This error is closely correlated to that Forcibly deletion process  of File stream file which I do think no other solution except waiting to finish recovery mode and either wise it will end with :

  • The most optimistic   probability  that it will end up with Online mode …So it will be fine and no need for any further action  ( Just you have to wait for a longer time if log file was such huge)..
  • The most pessimistic probability that it will end up with suspect  mode  ..SO it will be need to run the below process of DB Repair  but bear in mind that data loss might be there;

Stop SQL Server and remove transaction log file of this DB then restart again where DB should go with suspect mode ….If so you can run the below query

ALTER DATABASE [DB_Name] SET  SINGLE_USER WITH NO_WAIT

ALTER DATABASE [DB_Name] SET EMERGENCY;

DBCC checkdb ([DB_Name], REPAIR_ALLOW_DATA_LOSS  )

ALTER DATABASE [DB_Name] SET online;

ALTER DATABASE [DB_Name] SET  Multi_USER WITH NO_WAIT

 

在使用CheckDB命令Repair之前,查看DB的大小

select DB_NAME(mf.database_id) as DatabaseName,
    mf.type_desc as FileType,
    mf.name as FileLogicName,
    mf.physical_name as FilePhysicalName,
    mf.size as PagesCount,
    mf.size*8/1024  as Size_MB,
    mf.size*8/1024/1024.0 as Size_GB
from sys.master_files mf
where mf.database_id= db_id(Ndbname)

技术分享

 

在执行时,出现各种问题:

1,User does not have permission to alter database ‘Office365‘, the database does not exist, or the database is not in a state that allows access checks.

2,Database ‘Office365‘ cannot be opened due to inaccessible files or insufficient memory or disk space.  See the SQL Server errorlog for details.

最后,我到File Physical path下,找不到相应的MDF文件,但是Log文件是存在的,并且log文件最后修改的时间离现在有2年,可能是被遗弃的DB。而重启 Service Account ,不至于将一个18GB的MDF文件删除吧,这种情况,是什么原因?

从《Database Status》找到如下解释:

Recovery Pending state: SQL Server has encountered a resource-related error during recovery. The database is not damaged, but files may be missing or system resource limitations may be preventing it from starting. The database is unavailable. Additional action by the user is required to resolve the error and let the recovery process be completed.

附上Database Status及其 Definition

StateDefinition
ONLINE Database is available for access. The primary filegroup is online, although the undo phase of recovery may not have been completed.
OFFLINE Database is unavailable. A database becomes offline by explicit user action and remains offline until additional user action is taken. For example, the database may be taken offline in order to move a file to a new disk. The database is then brought back online after the move has been completed.
RESTORING One or more files of the primary filegroup are being restored, or one or more secondary files are being restored offline. The database is unavailable.
RECOVERING Database is being recovered. The recovering process is a transient state; the database will automatically become online if the recovery succeeds. If the recovery fails, the database will become suspect. The database is unavailable.
RECOVERY PENDING SQL Server has encountered a resource-related error during recovery. The database is not damaged, but files may be missing or system resource limitations may be preventing it from starting. The database is unavailable. Additional action by the user is required to resolve the error and let the recovery process be completed.
SUSPECT At least the primary filegroup is suspect and may be damaged. The database cannot be recovered during startup of SQL Server. The database is unavailable. Additional action by the user is required to resolve the problem.
EMERGENCY User has changed the database and set the status to EMERGENCY. The database is in single-user mode and may be repaired or restored. The database is marked READ_ONLY, logging is disabled, and access is limited to members of the sysadmin fixed server role. EMERGENCY is primarily used for troubleshooting purposes. For example, a database marked as suspect can be set to the EMERGENCY state. This could permit the system administrator read-only access to the database. Only members of the sysadmin fixed server role can set a database to the EMERGENCY state.

 

 

推荐阅读:

Troubleshooting: SCOM DW Database is in a Suspect State

Search Engine Q&A #4: Using EMERGENCY mode to access a RECOVERY PENDING or SUSPECT database

Corruption: Last resorts that people try first…

DB处于Recovery Pending状态

标签:

原文地址:http://www.cnblogs.com/ljhdo/p/5532293.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!