欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

YourSQLDba低版本的一个Bug的浅析

程序员文章站 2022-04-14 14:00:31
帮人分析解决一个YourSQLDba备份报错问题,个人觉得有点意思,顺手记录一下分析思路,大体解决思路如下: 首先,找到YourSQLDba作业YourSQLDba_FullBackups_And_Maintenance的报错邮件或者作业的错误日志信息,检查YourSQLDba出错的详细信息。 YO... ......

帮人分析解决一个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://www.cnblogs.com/kerrycode/p/12851659.html