需要以下代码的帮助,因为它因截断错误而失败
发生截断错误。命令已中止。
create table monCacheQuality (
ServerName sysname
,CollectionDateTime smalldatetime not null
,PhysicalWrites decimal(15, 0) not null
,PhysicalReads decimal(15, 0) not null
,LogicalReads decimal(15, 0) not null
,CacheQuality decimal(15, 0) not null
,CacheHitPct decimal(15,4) not null
)
-- Main code starts here
declare @physical_read1 decimal(15, 0)
,@logical_read1 decimal(15, 0)
,@physical_write1 decimal(15, 0)
,@cache_search1 decimal (15,4)
declare @physical_read2 decimal(15, 0)
,@logical_read2 decimal(15, 0)
,@physical_write2 decimal(15, 0)
,@cache_search2 decimal (15,4)
while (1=1)
begin
select @physical_write1 = PhysicalWrites
,@physical_read1 = PhysicalReads
,@logical_read1 = LogicalReads
,@cache_search1 = CacheSearches
from master..monDataCache
waitfor delay '00:00:20' -- Log every 20 sec
select @physical_write2 = PhysicalWrites
,@physical_read2 = PhysicalReads
,@logical_read2 = LogicalReads
,@cache_search2 = CacheSearches
from master..monDataCache
insert monCacheQuality
select @@servername as ServerName
,getUTCdate()
,@physical_write2 - @physical_write1
,@physical_read2 - @physical_read1
,@logical_read2 - @logical_read1
,case
when @physical_read2 - @physical_read1 = 0
then - 1
else (@logical_read2 - @logical_read1) / (@physical_read2 - @physical_read1)
end as CacheQuality
,100-(((@physical_read2-@physical_read1)/(@cache_search2-@cache_search1))*100) as CacheHitPct
end
以防万一有人想为 Sybase ASE 15 及更高版本设置缓存质量,以下脚本将有所帮助:
脚本的更改可以快速运行而无需查询 MDA 表的开销,并且通过切换到
int
数据类型来解决截断问题。:CacheID = 0
最后一个更改只是物理读取 = 0 时的逻辑更改,这样我们就保存了逻辑读取。
then @logical_read2 - @logical_read1