YourSQLDba低版本的一个Bug的浅析
2020-05-08 17:07 潇湘隐者 阅读(450) 评论(0) 编辑 收藏 举报帮人分析解决一个YourSQLDba备份报错问题,个人觉得有点意思,顺手记录一下分析思路,大体解决思路如下:
首先,找到YourSQLDba作业YourSQLDba_FullBackups_And_Maintenance的报错邮件或者作业的错误日志信息,检查YourSQLDba出错的详细信息。
YOURSQLDBA.MAINT.ShowHistoryErrors 96
发现YourSQLDba在更新统计信息是遇到错误,如下所示
<Exec>
<ctx>yMaint.UpdateStats</ctx>
<inf>update statistics selected</inf>
<cmd>update statistics [model].[dbo].[ServiceBrokerQueue] WITH sample 100 PERCENT</cmd>
<err>Error 2706, Severity 16, level 6 : Table 'ServiceBrokerQueue' does not exist.</err>
</Exec>
检查发现这个对象是queue,根本不是表,所以更新统计信息会出错。
那么YourSQLDba怎么会更新queue对象的统计信息呢?我首先检查了一下YourSQLDba的版本信息。当前数据库服务器上的YourSQLDba是相当老的一个版本了。然后我就去检查YourSQLDba的代码
Exec YourSQLDba.Install.PrintVersionInfo
========================================
YourSQLDba version: 5.0.2 2012-06-12
YourSQLDba更新统计信息是通过[yMaint].[UpdateStats]来更新统计,于是检查代码,发现获取要更新统计信息的对象是通过下面脚本获取的。首先将要更新统计信息的对象放到临时表#TableNames中去,然后生成更新统计信息的脚本。
-- makes query boilerplate with replacable parameter identified by
-- labels between '<' et '>'
-- this query select table for which to perform update statistics
truncate table #TableNames
set @sql =
'
set nocount on
;With
TableSizeStats as
(
select
object_schema_name(Ps.object_id, db_id('<DbName>')) as scn --collate <srvCol>
, object_name(Ps.object_id, db_id('<DbName>')) as tb --collate <srvCol>
, Sum(Ps.Page_count) as Pg
From
sys.dm_db_index_physical_stats (db_id('<DbName>'), NULL, NULL, NULL, 'LIMITED') Ps
Group by
Ps.object_id
)
Insert into #tableNames (scn, tb, seq, sampling)
Select
scn
, tb
, row_number() over (order by scn, tb) as seq
, Case
When pg > 200001 Then '10'
When Pg between 50001 and 200000 Then '20'
When Pg between 5001 and 50000 Then '30'
else '100'
End
From
TableSizeStats
where (abs(checksum(tb)) % <SpreadUpdStatRun>) = <seqStatNow>
'
这个脚本会将queue类型的对象也放入临时表,所以明显是个Bug,不过YourSQLDba后续的版本已经Fix掉这个Bug了。如下所示,后续的版本就加上条件过滤了,只获取表和视图的数据。所以遇到这个问题,只需要升级YourSQLDba的版本就好了
-- makes query boilerplate with replacable parameter identified by
-- labels between "<" et ">"
-- this query select table for which to perform update statistics
truncate table #TableNames
set @sql =
'
Use [<DbName>]
set nocount on
;With
TableSizeStats as
(
select
object_schema_name(Ps.object_id) as scn --collate <srvCol>
, object_name(Ps.object_id) as tb --collate <srvCol>
, Sum(Ps.Page_count) as Pg
From
sys.dm_db_index_physical_stats (db_id("<DbName>"), NULL, NULL, NULL, "LIMITED") Ps
Where ( OBJECTPROPERTYEX ( Ps.object_id , "IsTable" ) = 1
Or OBJECTPROPERTYEX ( Ps.object_id , "IsView" ) = 1)
Group by
Ps.object_id
)
Insert into #tableNames (scn, tb, seq, sampling)
Select
scn
, tb
, row_number() over (order by scn, tb) as seq
, Case
When Pg > 5000001 Then "0"
When Pg between 1000001 and 5000000 Then "1"
When Pg between 500001 and 1000000 Then "5"
When pg between 200001 and 500000 Then "10"
When Pg between 50001 and 200000 Then "20"
When Pg between 5001 and 50000 Then "30"
else "100"
End
From
TableSizeStats
where scn is not null and tb is not null and (abs(checksum(tb)) % <SpreadUpdStatRun>) = <seqStatNow>
'
![](https://images.cnblogs.com/cnblogs_com/kerrycode/1913302/o_240731062102_kerrycode.png)
扫描上面二维码关注我
如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.