维护计划中的收缩数据库操作失败

Tom*_*lar 3 sql-server maintenance

请参阅下面的更新

我有一个夜间数据库维护计划,它导致了一些奇怪的行为。

大约十分之 1 运行它会导致数据库不响应查询。DBM 计划大约需要 5 分钟才能完成,然后它开始响应。

错误日志似乎根本没有指出任何问题:

2013-01-13 00:00:56.73 spid23s     This instance of SQL Server has been using a process ID of 1488 since 12/28/2012 10:06:36 AM (local) 12/28/2012 6:06:36 PM (UTC). This is an informational message only; no user action is required.
2013-01-13 22:00:06.07 spid60      Configuration option 'user options' changed from 0 to 0. Run the RECONFIGURE statement to install.
2013-01-13 22:00:06.07 spid60      FILESTREAM: effective level = 0, configured level = 0, file system access share name = 'MSSQLSERVER'.
2013-01-13 22:01:03.78 spid64      DBCC CHECKDB (RackAttackNorthAmerica) WITH no_infomsgs executed by sa found 0 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 57 seconds.  Internal database snapshot has split point LSN = 0000942b:000000d9:0001 and first LSN = 0000942b:000000d8:0001.
2013-01-13 22:02:33.13 spid80      I/O is frozen on database model. No user action is required. However, if I/O is not resumed promptly, you could cancel the backup.
2013-01-13 22:02:33.13 spid81      I/O is frozen on database msdb. No user action is required. However, if I/O is not resumed promptly, you could cancel the backup.
2013-01-13 22:02:33.13 spid82      I/O is frozen on database RackAttackNorthAmerica. No user action is required. However, if I/O is not resumed promptly, you could cancel the backup.
2013-01-13 22:02:34.13 spid83      I/O is frozen on database master. No user action is required. However, if I/O is not resumed promptly, you could cancel the backup.
2013-01-13 22:02:34.48 spid83      I/O was resumed on database master. No user action is required.
2013-01-13 22:02:34.48 spid80      I/O was resumed on database model. No user action is required.
2013-01-13 22:02:34.48 spid81      I/O was resumed on database msdb. No user action is required.
2013-01-13 22:02:34.70 spid82      I/O was resumed on database RackAttackNorthAmerica. No user action is required.
2013-01-13 22:02:35.07 Backup      Database backed up. Database: master, creation date(time): 2012/12/28(10:05:56), pages dumped: 379, first LSN: 685:336:83, last LSN: 685:384:1, number of dump devices: 1, device information: (FILE=1, TYPE=VIRTUAL_DEVICE: {'{6E5AF82F-6BBD-4343-9DA3-286FD7EA5C0E}4'}). This is an informational message only. No user action is required.
2013-01-13 22:02:35.56 Backup      Database backed up. Database: model, creation date(time): 2003/04/08(09:13:36), pages dumped: 170, first LSN: 101:1440:37, last LSN: 101:1464:1, number of dump devices: 1, device information: (FILE=1, TYPE=VIRTUAL_DEVICE: {'{6E5AF82F-6BBD-4343-9DA3-286FD7EA5C0E}1'}). This is an informational message only. No user action is required.
2013-01-13 22:02:35.69 Backup      Database backed up. Database: msdb, creation date(time): 2008/07/09(16:46:27), pages dumped: 1948, first LSN: 1647:152:131, last LSN: 1647:216:1, number of dump devices: 1, device information: (FILE=1, TYPE=VIRTUAL_DEVICE: {'{6E5AF82F-6BBD-4343-9DA3-286FD7EA5C0E}2'}). This is an informational message only. No user action is required.
2013-01-13 22:02:35.77 Backup      Database backed up. Database: RackAttackNorthAmerica, creation date(time): 2011/01/21(10:37:38), pages dumped: 193713, first LSN: 37940:102:1, last LSN: 37946:493:1, number of dump devices: 1, device information: (FILE=1, TYPE=VIRTUAL_DEVICE: {'{6E5AF82F-6BBD-4343-9DA3-286FD7EA5C0E}3'}). This is an informational message only. No user action is required.
2013-01-13 22:06:48.94 Backup      Database backed up. Database: RackAttackNorthAmerica, creation date(time): 2011/01/21(10:37:38), pages dumped: 168202, first LSN: 37974:59:36, last LSN: 37974:83:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'D:\DB_Backups\RackAttackNorthAmerica_backup_2013_01_13_220612_2311062.bak'}). This is an informational message only. No user action is required.
Run Code Online (Sandbox Code Playgroud)

我不太确定诊断问题需要哪些信息。

请让我知道你需要什么,我会尽我所能得到它。

我设法找到了这个错误,不确定它是否有帮助。

Executing the query "DBCC SHRINKDATABASE(N'RackAttackNorthAmerica', 10,..." failed with the following error: "Backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized. Reissue the statement after the current backup or file manipulation operation is completed.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Run Code Online (Sandbox Code Playgroud)

dm_os_waiting_tasks

waiting_task_address    session_id  exec_context_id wait_duration_ms    wait_type   resource_address    blocking_task_address   blocking_session_id blocking_exec_context_id    resource_description
0x0000000003FAE508  3   0   4907732 XE_DISPATCHER_WAIT  NULL    NULL    NULL    NULL    NULL
0x0000000003FAE988  15  0   11555964    BROKER_EVENTHANDLER NULL    NULL    NULL    NULL    NULL
0x00000000040E8748  5   0   33  LAZYWRITER_SLEEP    NULL    NULL    NULL    NULL    NULL
0x0000000004102508  6   0   9962    LOGMGR_QUEUE    0x0000000003413528  NULL    NULL    NULL    NULL
0x0000000004102748  17  0   1480291018  BROKER_TRANSMITTER  NULL    NULL    NULL    NULL    NULL
0x000000000411C508  4   0   199 REQUEST_FOR_DEADLOCK_SEARCH 0x00000000089A01F8  NULL    NULL    NULL    NULL
0x000000000411C748  10  0   741 SLEEP_TASK  NULL    NULL    NULL    NULL    NULL
0x0000000004136508  7   0   1480284374  KSOURCE_WAKEUP  NULL    NULL    NULL    NULL    NULL
0x0000000004150508  12  0   55058   CHECKPOINT_QUEUE    0x00000000034135A0  NULL    NULL    NULL    NULL
0x0000000004150BC8  NULL    NULL    12814   FT_IFTS_SCHEDULER_IDLE_WAIT NULL    NULL    NULL    NULL    NULL
0x000000000416A508  11  0   1480314263  ONDEMAND_TASK_QUEUE 0x00000000033F3BE0  NULL    NULL    NULL    NULL
0x000000000416A988  16  0   1480291026  BROKER_TRANSMITTER  NULL    NULL    NULL    NULL    NULL
0x0000000004904748  2   0   17621   XE_TIMER_EVENT  NULL    NULL    NULL    NULL    NULL
0x00000000804222C8  9   0   705 SQLTRACE_BUFFER_FLUSH   NULL    NULL    NULL    NULL    NULL
Run Code Online (Sandbox Code Playgroud)

更新:

数据库收缩已删除。还在挂。我 99% 是重建索引任务。以下是生成的 SQL 中的一些示例行

ALTER INDEX [childCategories] ON [dbo].[category] REBUILD PARTITION = ALL WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = OFF, ONLINE = OFF, SORT_IN_TEMPDB = OFF ) 
ALTER INDEX [mfgID] ON [dbo].[category] REBUILD PARTITION = ALL WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = OFF, ONLINE = OFF, SORT_IN_TEMPDB = OFF ) 
Run Code Online (Sandbox Code Playgroud)

2013-07-09 更新:所以我在这个维护计划中继续遇到问题。几个月前删除了收缩操作,并修改了重建索引任务。我继续出现故障,并且由该数据库驱动的网站在每次故障时都会继续停机几分钟。我设法挖掘了作业历史任务,现在更新统计任务似乎失败了。请参阅下面的日志:

Executed as user: WORKGROUP\WNN1106$. ...
Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 31% complete  End Progress  Progress: 2013-07-08 23:04:37.03
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[news]
WITH FULLSCAN  ".: 32% complete  End Progress  Progress: 2013-07-08 23:04:37.03
  Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 33% complete  End Progress  Progress: 2013-07-08 23:04:42.65
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[orderItems]
WITH FULLSC...".: 33% complete  End Progress  Progress: 2013-07-08 23:04:42.65
  Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 34% complete  End Progress  Progress: 2013-07-08 23:04:42.74
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[orderItemType]
WITH FUL...".: 35% complete  End Progress  Progress: 2013-07-08 23:04:42.74
  Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 36% complete  End Progress  Progress: 2013-07-08 23:04:42.74
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[orderPaymentType]
WITH ...".: 37% complete  End Progress  Progress: 2013-07-08 23:04:42.74
  Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 37% complete  End Progress  Progress: 2013-07-08 23:05:43.25
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[orders]
WITH FULLSCAN  ".: 38% complete  End Progress  Progress: 2013-07-08 23:05:43.25
  Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 39% complete  End Progress  Progress: 2013-07-08 23:05:43.30
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[orders_deleted]
WITH FU...".: 40% complete  End Progress  Progress: 2013-07-08 23:05:43.30
  Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 41% complete  End Progress  Progress: 2013-07-08 23:05:43.30
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[orderSource]
WITH FULLS...".: 41% complete  End Progress  Progress: 2013-07-08 23:05:43.30
  Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 42% complete  End Progress  Progress: 2013-07-08 23:05:43.55
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[orderSplit]
WITH FULLSC...".: 43% complete  End Progress  Progress: 2013-07-08 23:05:43.55
  Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 44% complete  End Progress  Progress: 2013-07-08 23:05:43.60
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[paymentProcessType]
WIT...".: 45% complete  End Progress  Progress: 2013-07-08 23:05:43.60
  Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 45% complete  End Progress  Progress: 2013-07-08 23:05:43.64
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[priceHistory]
WITH FULL...".: 46% complete  End Progress  Progress: 2013-07-08 23:05:43.64
  Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 47% complete  End Progress  Progress: 2013-07-08 23:05:43.71
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[priceUpdate]
WITH FULLS...".: 48% complete  End Progress  Progress: 2013-07-08 23:05:43.71
  Source: Update Statistics Task

Executing query "use [RackAttackNorthAmerica]  ".: 49% complete  End Progress  Progress: 2013-07-08 23:05:43.75
  Source: Update Statistics Task

Executing query "UPDATE STATISTICS [dbo].[priceUpdateCAD]
WITH FU...".: 50% complete  End Progress  Progress: 2013-07-08 23:0...  The package execution fa...  The step failed.
Run Code Online (Sandbox Code Playgroud)

我不应该在每晚备份中执行更新统计任务吗?或者这指向一个不同的问题?

2013-07-09 更新:

维护计划记录到文件中。

这是 2013-07-08 的条目:

Execute T-SQL Statement Task (WNN1106)
Execute TSQL on Local server connection
Execution time out: 120
Task start: 2013-07-08T23:01:10.
Task end: 2013-07-08T23:03:11.
Failed:(-1073548784) Executing the query "ALTER INDEX [email] ON [dbo].[customerFeedback] RE..." failed with the following error: "Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Run Code Online (Sandbox Code Playgroud)

相关 SQL:

ALTER INDEX [email] ON [dbo].[customerFeedback] REBUILD PARTITION = ALL WITH ( PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF, ONLINE = OFF, SORT_IN_TEMPDB = OFF )
Run Code Online (Sandbox Code Playgroud)

这是 2013-07-04 的条目:

Failed:(-1073548784) Executing the query "ALTER INDEX [cEmail] ON [dbo].[orders] REBUILD PAR..." failed with the following error: "Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Run Code Online (Sandbox Code Playgroud)

相关 SQL:

ALTER INDEX [cEmail] ON [dbo].[orders] REBUILD PARTITION = ALL WITH ( PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF, ONLINE = OFF, SORT_IN_TEMPDB = OFF )
Run Code Online (Sandbox Code Playgroud)

这是 2013-07-03 的条目:

Failed:(-1073548784) Executing the query "ALTER INDEX [email] ON [dbo].[customerFeedback] RE..." failed with the following error: "Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Run Code Online (Sandbox Code Playgroud)

相关 SQL:

ALTER INDEX [email] ON [dbo].[customerFeedback] REBUILD PARTITION = ALL WITH ( PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF, ONLINE = OFF, SORT_IN_TEMPDB = OFF )
Run Code Online (Sandbox Code Playgroud)

所有维护计划任务均由 GUI 向导工具生成。正如您所看到的,它们每次都在不同的步骤上失败。

我应该在这里做什么?

我应该增加超时时间吗?或者只是需要更长的时间才能失败?

我应该修改查询吗?ALLOW_ROW_LOCKS = 关?在线=开启?

我应该完全删除重建索引任务吗?

我应该完全删除更新统计任务吗?

感谢您的输入,

托马斯

Mik*_*Fal 9

您看到的是由于DBCC SHRINKDB操作而阻塞。这导致您的数据库不响应。收缩操作在磁盘上移动您的数据页,以便在数据文件中创建要收缩的空间。因此,引擎必须使用页锁或表锁来移动适当的数据页。虽然这些应该是短期的,但它们可以阻止查询。

此外,收缩操作是文件操作(就像添加、修改或删除数据文件一样)并且不能在执行任何类型的备份时运行。这就是为什么您看到有关文件命令的其他错误必须序列化的原因。

要观察阻塞情况,您可以在运行时运行 sp_who2(或更好的sp_whoisactiveDBCC SHRINKDB。确定命令正在运行的 spid,您应该会看到它导致阻塞(如果有足够的活动)。

不幸的是,没有办法避免阻塞。这与其他原因一起,是您不应该执行任何类型的自动收缩操作的原因。解决问题的最佳计划是从维护计划中删除任何“收缩数据库”任务。

根据JohnS链接的Paul Randall 的优秀文章,最佳实践是尽可能避免缩小数据库。如果必须缩小文件,则应使用以下经验法则:

  1. 手动执行收缩,以便您可以监控其进度并根据需要进行管理。如果它正在中断用户进程,您可以以最小的影响终止收缩。中断收缩不会“回滚”任何页面移动,您将保留收缩已经取得的任何进展。
  2. 将收缩增量保持在较小的值,以最大程度地减少页面移动并保持维护/收缩期可管理。


Joh*_*hnS 7

我 100% 同意 Aaron。您的数据库收缩操作应该被删除。我真的希望 Microsoft 将其从维护任务的选项中删除。它不应该是自动化的,因为它可能弊大于利。有关此主题的更多信息,请参阅 Paul Randal 的这篇博文。

http://www.sqlskills.com/blogs/paul/why-you-should-not-shrink-your-data-files/