简体   繁体   English

Sql server 数据库 疑似标记?

[英]Sql server Database Suspected marked?

我的 sql server 将一个数据库标记为可疑,在检查时我发现我的 mdf、ldf 文件丢失,但 chkdsk 没有错误,这意味着某种病毒?

http://support.microsoft.com/kb/180500 http://support.microsoft.com/kb/180500

At startup, SQL Server attempts to obtain an exclusive lock on the device file.启动时,SQL Server 尝试获取设备文件的排它锁。 If the device is being used by another process (for example, backup software) or if the file is missing , the scenario described above will be encountered.如果设备正被另一个进程(例如,备份软件)使用或文件丢失,则会遇到上述情况。 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 .要正确恢复数据库,必须使设备可用,并且必须重置数据库状态

It means someone deleted the files.这意味着有人删除了文件。

They can not be deleted when in use so it happened:它们在使用时无法删除,所以发生了:

  • when SQL Server was shut down当 SQL Server 关闭时
  • the database was closed (Express version usually)数据库已关闭(通常为 Express 版本)
  • the database was taken offline数据库已脱机

All user dbs will share the same folder (edit) by default (end edit) so this is deliberate默认情况下,所有用户 dbs 将共享同一个文件夹(编辑)(结束编辑),所以这是故意的

The more exotic options include restoring the master db where the databases/MDF files listed in the restored master db do not exist etc. But I doubt it.更奇特的选项包括还原主数据库,其中还原的主数据库中列出的数据库/MDF 文件不存在等。但我对此表示怀疑。

Either the files were deleted, or they have been moved and a master database backup restored from before the change in location.文件已被删除,或者它们已被移动并从位置更改之前恢复了主数据库备份。 In both cases the physical files can only be deleted or moved if the database is offline - either because sql server was shut down or the database was closed.在这两种情况下,只有在数据库处于脱机状态时才能删除或移动物理文件 - 因为 sql server 已关闭或数据库已关闭。

Either of these things is highly unlikely to have happened accidentally.这些事情中的任何一个都不太可能意外发生。 It's unlikely to be a generic virus or trojan as such would either have to specifically delete the files on startup before SQL Server started (assuming your database starts automatically) or shut down the database then specifically delete the files.它不太可能是通用病毒或木马,因此要么必须在 SQL Server 启动之前在启动时专门删除文件(假设您的数据库自动启动),要么关闭数据库然后专门删除文件。 Given that chkdsk doesn't report errors either it's unlikely to be a disk issue, so it's a virtual certainty that the cause of the error is deliberate database (mis)management.鉴于 chkdsk 不报告错误,也不太可能是磁盘问题,因此几乎可以肯定错误的原因是故意的数据库(错误)管理。

I think the most likely option is that a dba has decided that the files should be moved elsewhere - typically this is done for space or performance reasons - for instance if a new drive is added to a machine that is running out of space then the database could be moved to that.我认为最可能的选择是 dba 决定将文件移到其他地方 - 通常这是出于空间或性能原因而完成的 - 例如,如果将新驱动器添加到空间不足的机器上,那么数据库可以移动到那个。 For some reason a backup of the master database has subsequently been restored from a point before the move.由于某种原因,主数据库的备份随后已从移动前的某个点恢复。

My first action would be to do a full scan of the system for all mdf/ldf files and (hopefully) locate them.我的第一个动作是对系统进行全面扫描,查找所有 mdf/ldf 文件并(希望)找到它们。 I'd also do a scan of backups and look for the latest master database backup.我还会扫描备份并寻找最新的主数据库备份。 You could either then try restoring the last master backup and see if that fixed the issue (i'd back up the current master first of course), and failing that, or directly, reattach the missing files.然后您可以尝试恢复最后一个主备份并查看是否解决了问题(我当然会首先备份当前主备份),如果失败,或者直接重新附加丢失的文件。

If you cannot find the mdf/ldf files then your only option is restore from backup.如果您找不到 mdf/ldf 文件,那么您唯一的选择就是从备份中恢复。 If you don't have a backup then your database is lost.如果您没有备份,那么您的数据库就会丢失。

In SQL Server suspect database is a mode when user unable to connect with database.在 SQL Server 中,可疑数据库是用户无法连接数据库时的一种模式。 At this time user unable to perform any action and can not do anything like no open no backup and no restore etc.此时用户无法执行任何操作,也无法执行任何操作,例如不打开、不备份和不恢复等。

Possible cause for this problem can be one of the following: 1. Database is corrupted 2. Insufficient memory state.此问题的可能原因可能是以下之一: 1. 数据库已损坏 2. 内存不足状态。 3. unexpected shutdown etc. 4. OS is unable to find the database file 3. 意外关机等。 4. 操作系统找不到数据库文件

In this situation, you can check the SQL Server logs.在这种情况下,您可以检查 SQL Server 日志。 Go to Management, Click on SQL Server Logs and click on current and check the message.转到管理,单击 SQL Server 日志并单击当前并检查消息。

In my case, I got this: Error 17207, severity 16, state 1 (it is related to log file deletion or corruption)就我而言,我得到了这个:错误 17207,严重性 16,状态 1(它与日志文件删除或损坏有关)

Solution:解决方案:

Set the database into single user mode:将数据库设置为单用户模式:

Alter database dbname set single_user

Now set the database into emergency mode:现在将数据库设置为紧急模式:

Alter database dbname set emergency

Repair missing log file or corrupted log file with data loss.修复丢失的日志文件或损坏的日志文件并丢失数据。

DBCC CHECKDB ('dbname', REAPIR_ALLOW_DATA_LOSS)

Note: You may loss the data by using this command.注意:使用此命令可能会丢失数据。 It also depends on client's approval.这也取决于客户的批准。

Now set the db in multi user mode;现在将数据库设置为多用户模式;

alter database dbname set multi_user

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM