前幾天碰到一個問題, SQL Server 2008 SP2 上的一個檢查數據庫完整性的維護計划失敗了, 這個維護計划沒有過任何的修改.
先查看一下執行這個維護計划的job的歷史, 有類似以下的報錯:
Executing query "DECLARE @Guid UNIQUEIDENTIFIER EXECUTE msdb..sp...".: 100% complete
End Progress DTExec: The package execution returned DTSER_FAILURE (1).
Started: 10:14:30 AM Finished : 10:14:31 AM Elapsed: 1.185 seconds.
The package execution failed. The step failed.
從這個報錯里看不出什么東西. 只知道這個job是10:14:30 AM 這個時候開始的, 執行了1.185秒就報錯了.
然后再查看一下維護計划的歷史, 只有如下的一條報錯:
Alter failed for Server 'server_name\\instance_name'
看起來有點莫名, 從維護計划生成的語句來看, 也就是dbcc checkdb之類, 為什么會有alter server的操作?
再查看一下errorlog, 發現在維護計划報錯的那一時刻, 有如下一條報錯:
Configuration option 'user options' changed from 0 to 0. Run the RECONFIGURE statement to install.
看不出個所以然, 還是打開profiler看一下吧. 於是用profiler抓到了以下的語句:
EXEC sys.sp_configure N'user options', 0 RECONFIGURE
go
EXECUTE msdb..sp_maintplan_update_log '3E94A9A2-B4DD-4BA8-88E0-065DD7F1E90C'
,'Check Database Integrity Task (server_name)','Check Database integrity on Local server connection'
,'Databases: All databases','Include indexes','','server_name','0'
,'2012-01-17T10:40:41','2012-01-17T10:40:42',0,'Alter failed for Server ''server_name''. ',''
go
看來執行過sys.sp_configure之后, 就報錯了, 干脆直接執行一下
EXEC sys.sp_configure N'user options', 0 RECONFIGURE
果不其然, 報錯了:
Configuration option 'user options' changed from 0 to 0. Run the RECONFIGURE statement to install.
Msg 5808, Level 16, State 1, Line 1
Ad hoc update to system catalogs is not supported.
從報錯信息看, 想起了sp_configure中有一個allow updates的選項, 是不是和這個有關系, 查看一下
exec sys.sp_configure 'allow updates'
go
返回的結果:
name minimum maximum config_value run_value
allow updates 0 1 1 1
看來問題就是在這里.
在SQL Server 2005及以后, 就不允許直接更新系統表了, 所以即便這個allow updates的設置是1, 並且在設置的時候沒有報錯, 但是要執行reconfigure使更改生效, 還是會報錯.
而執行維護計划的過程中,就執行了reconfigure, 所以導致維護計划的執行報錯.
那么解決的辦法很簡單, 執行個a以下語句把allow updates 改成0就可以了.
exec sp_configure 'allow updates', 0
同理, 如果執行了以下語句修改recovery internal, 再執行維護計划也是會報錯.
EXEC sp_configure 'Recovery interval', 61
go