【问题标题】:SQL Server localdb RESTORE runs forever?SQL Server localdb RESTORE 永远运行?
【发布时间】:2021-03-31 10:23:05
【问题描述】:

我在 Windows 10 Pro 202H 上使用 Visual Studio 2019 社区 SQL Server localdb。我一直在尝试将 WideWorldImporters 数据库从 WideWorldImporters-Full.bak(从 GitHub 下载)“恢复”到我的 localdb 实例,但没有成功。

到目前为止,这已经发生了: Qyery:(*** = 我的用户名)

 USE master 
 RESTORE DATABASE WideWorldImporters 
 FROM disk = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\WideWorldImporters-Full.bak' 
 WITH MOVE 'WWI_Primary' TO 'C:\Users\***\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\WideWorldImporters.mdf', 
 MOVE 'WWI_UserData' TO 'C:\Users\***\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\WideWorldImporters_UserData.ndf', 
 MOVE 'WWI_Log' TO 'C:\Users\***\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\WideWorldImporters.ldf', 
 MOVE 'WWI_InMemory_Data_1' TO 'C:\Users\***\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\WideWorldImporters_InMemory_Data_1', 
 REPLACE

消息(窗格):

Processed 1464 pages for database 'WideWorldImporters', file 'WWI_Primary' on file 1.
Processed 53096 pages for database 'WideWorldImporters', file 'WWI_UserData' on file 1.
Processed 33 pages for database 'WideWorldImporters', file 'WWI_Log' on file 1.
Processed 3862 pages for database 'WideWorldImporters', file 'WWI_InMemory_Data_1' on file 1.

100% | No issues found
Executing query... (is running on and on) 

Output (General)  is empty

All the stuff notified in message window can be found in desitination folder:
WideWorldImportes_UserData.ndf                    (2 097 152 kb) 
WideWorldImportes.mdf                             (1 048 576 kb) 
WideWorldImportes.ldf                             (  102 400 kb) 

\WideWorldImportes_InMemory_Data_1\
filestream.hdr                                    (        1 kb) 

 \$FSLOG                                          (empty       ) 

 \$HKv2
{1E6DC7E6-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    2 048 kb)      
{3E231B6B-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (       20 kb) 
{4B9D83BE-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    2 048 kb) 
{6E82296C-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (   16 384 kb) 
{6F44D507-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    1 024 kb) 
{07FEB052-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (       20 kb) 
{7C4940C1-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    1 024 kb) 
{9A77966E-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    4 096 kb) 
{28CE0994-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (   16 384 kb) 
{63F1F945-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    2 048 kb) 
{79B6C099-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    4 096 kb) 
{122A2C90-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (   16 384 kb) 
{285FCA71-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (        4 kb) 
{421C57F0-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    4 096 kb) 
{A54BA375-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    1 024 kb) 
{C818BEE6-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (   30 836 kb) 
{CB6FF974-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    1 024 kb) 
{F6F88B52-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    1 024 kb) 
{F756E9B8-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.hkckp      (    1 024 kb) 

正在执行查询...(仍在运行,过去两个小时内文件大小没有变化)

这就是我现在的位置

我要生气了

【问题讨论】:

  • 您可以安装WhoIsActive 并查找任何阻塞进程。
  • 您是否检查过驱动器空间、tempDB 空间、日志文件增长等内容。检查 SqlServer 错误日志。
  • select * from sys.dm_exec_requests 应该会给你很多信息,尤其是blocking_session_id, wait_resource, percent_complete
  • 那不是查询,那是 RESTORE 操作。 LocalDB 是一个嵌入式 数据库,所以它的定义很慢。屏幕截图显示恢复已完成,服务器正在处理中断的事务(这表明备份是在繁忙时间进行的)。为什么不用 SQL Server Express?毕竟你已经安装了——LocalDB 是 SQL Server Express 的一个特性
  • 或者您可以使用 SQL Server Developer,它免费,但具有完整的企业功能集,例如默认并行和在线恢复。

标签: sql-server database visual-studio restore


【解决方案1】:

当您选择RESTORE WITH REPLACE 时,它已经覆盖了现有的 WideWorldImporters 数据库。当您使用替换选项完成还原时,可能存在未提交的事务,它正在尝试清理这些事务。它会在一段时间后重新上线。

您必须小心使用 REPLACE 选项。 From MSDN

REPLACE 选项影响

REPLACE 应该很少使用,并且只能在之后使用 详细的思考。恢复正常防止意外 用不同的数据库覆盖数据库。如果数据库 当前服务器上已存在 RESTORE 语句中指定的 并且指定的数据库系列 GUID 与数据库不同 family GUID 记录在备份集中,数据库没有恢复。 这是一项重要的保障措施。

REPLACE 选项会覆盖几个重要的安全检查,这些检查 恢复正常执行。覆盖的检查如下:

  • 通过备份另一个数据库来恢复现有数据库 数据库。

使用 REPLACE 选项,还原允许您覆盖现有的 数据库与备份集中的任何数据库,即使 指定的数据库名称与记录在 备份集。这可能会导致意外覆盖数据库 不同的数据库。

  • 使用完整或大容量日志恢复模式通过数据库进行恢复 未进行尾日志备份且 STOPAT 选项为 没用过。

使用 REPLACE 选项,您可能会丢失已提交的工作,因为日志 最近写的没有备份。

  • 覆盖现有文件。

例如,一个错误可能允许覆盖错误的文件 类型,例如 .xls 文件,或者正在被另一个数据库使用 那不在线。如果现有文件可能会导致任意数据丢失 被覆盖,尽管恢复的数据库是完整的。

你可以在这里阅读,如何退出恢复模式:https://www.mssqltips.com/sqlservertip/5460/sql-server-database-stuck-in-restoring-state/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-29
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    相关资源
    最近更新 更多