简体   繁体   English

SQL Server:如何附加/修复分离/损坏的数据库?

[英]SQL Server: How to attach / repair a detached / damaged database?

A database server crashed.数据库服务器崩溃。 I was able to get the mdf and the log file and I am trying to mount it on another server.我能够获得 mdf 和日志文件,我正在尝试将它安装在另一台服务器上。 I don't have backup as it was a development database.我没有备份,因为它是一个开发数据库。

When I try to attach the mdf and ldf files, Sql Server Management Studio give me this error:当我尝试附加 mdf 和 ldf 文件时,Sql Server Management Studio 给我这个错误:

    TITLE: Microsoft SQL Server Management Studio
    ------------------------------

    Attach database failed for Server

    ------------------------------

    Could not redo log record (457:14202:19), for transaction ID (0:478674), on page (1:519205), database 'WSS_Content_5555' (database ID 15). Page: LSN = (370:463:113), type = 1. Log: OpCode = 2, context 2, PrevPageLSN: (298:40524:64).
    Restore from a backup of the database, or repair the database.
    During redoing of a logged operation in database 'WSS_Content_5555', an error occurred at log record ID (457:14202:19).
    Typically, the specific failure is previously logged as an error in the Windows Event Log service.
    Restore the database from a full backup, or repair the database.
    Could not open new database 'WSS_Content_5555'.
    CREATE DATABASE is aborted. (Microsoft SQL Server, Error: 3456)

I don't know how to repair the database.我不知道如何修复数据库。 Does it need to be attached before beeing repaired?维修前需要安装吗? In that case, how can I attach it?在这种情况下,我该如何附加它?

You can try a workaround.您可以尝试一种解决方法。 In short:简而言之:

  1. Create a dummy DB with the same name (may need to remove the real DB first, save the original files or rename then).创建一个同名的虚拟数据库(可能需要先删除真正的数据库,保存原始文件或重命名)。
  2. Take the dummy off line (detach and (set offline or stop the SQL service)).将虚拟离线(分离和(设置离线或停止 SQL 服务))。
  3. Delete dummy files, replace then with the real DB files.删除虚拟文件,然后用真正的 DB 文件替换。
  4. Try to re-attach de DB尝试重新附加de DB

Edit编辑

As by OP comment note you also can need to rebuild the log (if you lost transactions)根据 OP 注释说明,您还可能需要重建日志(如果您丢失了事务)

  1. ALTER DATABASE [MyDatabase ] REBUILD LOG ON (NAME='MyDatabaseLog',FILENAME='D:\\Microsoft SQL Server\\YourDataPath\\Data\\Logfile.ldf') ALTER DATABASE [MyDatabase] REBUILD LOG ON (NAME='MyDatabaseLog',FILENAME='D:\\Microsoft SQL Server\\YourDataPath\\Data\\Logfile.ldf')

    and put the DB in multiple users log (taking the DB off can require you to put it in single use mode)并将 DB 放入多个用户日志中(取下 DB 可能需要您将其置于单次使用模式)

  2. ALTER DATABASE [nomdb] SET MULTI_USER ALTER DATABASE [nomdb] SET MULTI_USER

For all the gore details you can refer to the Paul Randal Article有关所有血腥细节,您可以参考Paul Randal 文章

(Note in this article the author uses EMERGENCY MODE to (attempt) repair the transaction log) (注意本文作者使用 EMERGENCY MODE 来(尝试)修复事务日志)

I already used it with success but depending on the extent of the damage or others details it can be a impossible task.我已经成功地使用了它,但根据损坏程度或其他细节,这可能是一项不可能完成的任务。 Consider restoring a backup.考虑恢复备份。

Note this stunts are fine in a development server but you really need to plan (and drill) for disaster recovery in a prodution server.请注意,此特技在开发服务器中很好,但您确实需要计划(和演练)生产服务器中的灾难恢复。

A database server crashed.数据库服务器崩溃。 I was able to get the mdf and the log file and I am trying to mount it on another server.我能够获得 mdf 和日志文件,我正在尝试将它安装在另一台服务器上。 I don't have backup as it was a development database.我没有备份,因为它是一个开发数据库。

When I try to attach the mdf and ldf files, Sql Server Management Studio give me this error:当我尝试附加 mdf 和 ldf 文件时,Sql Server Management Studio 给我这个错误:

    TITLE: Microsoft SQL Server Management Studio
    ------------------------------

    Attach database failed for Server

    ------------------------------

    Could not redo log record (457:14202:19), for transaction ID (0:478674), on page (1:519205), database 'WSS_Content_5555' (database ID 15). Page: LSN = (370:463:113), type = 1. Log: OpCode = 2, context 2, PrevPageLSN: (298:40524:64).
    Restore from a backup of the database, or repair the database.
    During redoing of a logged operation in database 'WSS_Content_5555', an error occurred at log record ID (457:14202:19).
    Typically, the specific failure is previously logged as an error in the Windows Event Log service.
    Restore the database from a full backup, or repair the database.
    Could not open new database 'WSS_Content_5555'.
    CREATE DATABASE is aborted. (Microsoft SQL Server, Error: 3456)

I don't know how to repair the database.我不知道如何修复数据库。 Does it need to be attached before beeing repaired?维修前是否需要安装? In that case, how can I attach it?在这种情况下,我该如何附加它?

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

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