My Life My Dream!

守信 求实 好学 力行
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

      当某个数据库文件空间用尽,做自动增长的时候,同一时间点只能有一个用户人员可以做文件自动增长动作,其他任务必须等待,此时会出现Latch资源的等待。使用sp_helpdb查看业务数据库时发现:该数据库设置不合理,数据文件每次增长2M,日志文件每次增长10%,且分别设置了最大限制。修改为每次增长200M,不限制大小,系统恢复正常,问题解决。

SqlServer阻塞时的等待类型如下:

image

 

顺便整理一下查看阻塞、会话状态及等待类型的SQL脚本:

-- 查看SQL阻塞信息
with tmp as (
    select * from master..sysprocesses t where t.blocked != 0
    union all
    select b.* from master..sysprocesses b
        join tmp t on b.spid = t.blocked 
)
select t.spid, t.blocked, t.status, t.waittype, t.lastwaittype, t.waitresource, t.waittime
    , DB_NAME(t.dbid) DbName, t.login_time, t.loginame, t.program_name, dc.text
from (select spid from tmp group by spid) s
    join master..sysprocesses t on s.spid = t.spid
    cross apply master.sys.dm_exec_sql_text(t.sql_handle) dc



-- 查看所有会话的状态、等待类型及当前正在执行SQL脚本
select t.spid, t.kpid, t.blocked, t.status, t.waittype, t.lastwaittype, t.waitresource, t.waittime
    , DB_NAME(t.dbid) DbName, t.login_time, t.last_batch, t.loginame, t.program_name, t.hostname, t.hostprocess
, t.cmd, t.stmt_start, t.stmt_end, t.request_id, dc.text from master.sys.sysprocesses t  outer apply master.sys.dm_exec_sql_text(t.sql_handle) dc
where t.spid >= 50

 

补充,昨天又有项目发生类似问题,将SqlServer的errorlog也贴出来,问题现象就更具体了。

QQ图片20150703083102

07/01/2015 16:44:56,spid55,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x000000000097DB88 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000007C2E08. Not continuing to wait.
07/01/2015 16:44:47,spid51,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D2FC3AC0<c/> page 1:117692<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594070827008<c/> task 0x000000000053F708 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000007C34C8. Not continuing to wait.
07/01/2015 16:44:41,spid77,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D2FC3AC0<c/> page 1:117692<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594070827008<c/> task 0x00000000F380DB88 : 0<c/> waittime 300<c/> flags 0x1a<c/> owning task 0x00000000007C34C8. Not continuing to wait.
07/01/2015 16:44:32,spid60,未知,Timeout occurred while waiting for latch: class 'LOG_MANAGER'<c/> id 000000000C980AE0<c/> type 4<c/> Task 0x00000000007C34C8 : 0<c/> waittime 300<c/> flags 0x1a<c/> owning task 0x00000000007C2E08. Continuing to wait.
07/01/2015 16:43:56,spid54,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000BD674E08 : 0<c/> waittime 300<c/> flags 0x1a<c/> owning task 0x00000000007C2E08. Not continuing to wait.
07/01/2015 14:46:39,spid62,未知,Autogrow of file 'cwbase001_log' in database 'cwbase001' took 568576 milliseconds.  Consider using ALTER DATABASE to set a smaller FILEGROWTH for this file.
07/01/2015 14:45:54,spid66,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000007A9DC8 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000007C2E08. Not continuing to wait.
07/01/2015 14:45:46,spid70,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000CAFE1880<c/> page 1:113858<c/> stat 0xc0010b<c/> database id: 10<c/> allocation unit Id: 72057594070827008<c/> task 0x00000000BD674748 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000BD674508. Not continuing to wait.
07/01/2015 14:45:28,spid59,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000CAFE1880<c/> page 1:113858<c/> stat 0xc0010b<c/> database id: 10<c/> allocation unit Id: 72057594070827008<c/> task 0x00000000007C2BC8 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000BD674508. Not continuing to wait.
07/01/2015 14:45:24,spid67,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000CAFE1880<c/> page 1:113858<c/> stat 0xc0010b<c/> database id: 10<c/> allocation unit Id: 72057594070827008<c/> task 0x00000000F380CBC8 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000BD674508. Not continuing to wait.
07/01/2015 14:44:54,spid65,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x000000000053EE08 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000007C2E08. Not continuing to wait.
07/01/2015 14:44:40,spid64,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000CAFE1880<c/> page 1:113858<c/> stat 0xc0010b<c/> database id: 10<c/> allocation unit Id: 72057594070827008<c/> task 0x00000000BD674E08 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000BD674508. Not continuing to wait.
07/01/2015 14:43:54,spid63,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x000000000053F708 : 0<c/> waittime 300<c/> flags 0x1a<c/> owning task 0x00000000007C2E08. Not continuing to wait.
07/01/2015 14:43:50,spid60,未知,Timeout occurred while waiting for latch: class 'LOG_MANAGER'<c/> id 000000000C980AE0<c/> type 4<c/> Task 0x00000000007A9288 : 0<c/> waittime 300<c/> flags 0x1a<c/> owning task 0x00000000BD674508. Continuing to wait.
07/01/2015 14:43:13,spid54,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000CAFE1880<c/> page 1:113858<c/> stat 0xc0010b<c/> database id: 10<c/> allocation unit Id: 72057594070827008<c/> task 0x00000000B2F4C988 : 0<c/> waittime 300<c/> flags 0x1a<c/> owning task 0x00000000BD674508. Not continuing to wait.
07/01/2015 14:42:54,spid53,未知,Timeout occurred while waiting for latch: class 'LOG_MANAGER'<c/> id 000000000C980AE0<c/> type 4<c/> Task 0x00000000007C2E08 : 0<c/> waittime 300<c/> flags 0x1a<c/> owning task 0x00000000BD674508. Continuing to wait.
07/01/2015 13:01:53,spid18s,未知,Autogrow of file 'cwbase001_log' in database 'cwbase001' took 961310 milliseconds.  Consider using ALTER DATABASE to set a smaller FILEGROWTH for this file.
07/01/2015 13:01:53,spid60,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000B2F4CBC8 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid90,未知,A time-out occurred while waiting for buffer latch -- type 4<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000F535C2C8 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid113,未知,A time-out occurred while waiting for buffer latch -- type 4<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000F380D048 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid111,未知,A time-out occurred while waiting for buffer latch -- type 4<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000B2F4D4C8 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid114,未知,A time-out occurred while waiting for buffer latch -- type 4<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000F535CE08 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid125,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000F380DB88 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid120,未知,A time-out occurred while waiting for buffer latch -- type 4<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000F535C748 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid55,未知,A time-out occurred while waiting for buffer latch -- type 4<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000F380CBC8 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid117,未知,A time-out occurred while waiting for buffer latch -- type 4<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000007A9288 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid59,未知,A time-out occurred while waiting for buffer latch -- type 4<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000BD674E08 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid109,未知,A time-out occurred while waiting for buffer latch -- type 4<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x000000000053EE08 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid66,未知,A time-out occurred while waiting for buffer latch -- type 4<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000007C2E08 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid106,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x000000000053F708 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 13:01:50,spid57,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000BD675DC8 : 0<c/> waittime 300<c/> flags 0x1a<c/> owning task 0x00000000B2F4C2C8. Not continuing to wait.
07/01/2015 12:56:50,spid109,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x000000000053EE08 : 0<c/> waittime 300<c/> flags 0x1a<c/> owning task 0x00000000F380D048. Not continuing to wait.
07/01/2015 12:51:17,spid75,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000CAFE1880<c/> page 1:113858<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594070827008<c/> task 0x000000000053FB88 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000007C3B88. Not continuing to wait.
07/01/2015 12:51:17,spid88,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000CAFE1880<c/> page 1:113858<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594070827008<c/> task 0x00000000F535D708 : 0<c/> waittime 300<c/> flags 0x1a<c/> owning task 0x00000000007C3B88. Not continuing to wait.
07/01/2015 12:45:53,spid54,未知,A time-out occurred while waiting for buffer latch -- type 2<c/> bp 00000000D9FD9540<c/> page 1:3783<c/> stat 0xc00109<c/> database id: 10<c/> allocation unit Id: 72057594043629568<c/> task 0x00000000F380D288 : 0<c/> waittime 300<c/> flags 0x3a<c/> owning task 0x00000000F380D048. Not continuing to wait.