sqlserver 问题处理

Posted Qtong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlserver 问题处理相关的知识,希望对你有一定的参考价值。

##阻塞

use master
declare @spid int,@bl int
DECLARE s_cur CURSOR FOR
select 0 ,blocked
from (select * from sysprocesses where blocked>0 ) a
where not exists(select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid)
union select spid,blocked from sysprocesses where blocked>0
OPEN s_cur
FETCH NEXT FROM s_cur INTO @spid,@bl
WHILE @@FETCH_STATUS = 0
begin
if @spid =0
select ‘引起数据库阻塞的是: ‘+ CAST(@bl AS VARCHAR(10)) + ‘进程号,其执行的SQL语法如下‘
else
select ‘进程号SPID:‘+ CAST(@spid AS VARCHAR(10))+ ‘被‘ + ‘进程号SPID:‘+ CAST(@bl AS VARCHAR(10)) +‘阻塞,其当前进程执行的SQL语法如下‘
DBCC INPUTBUFFER (@bl )
FETCH NEXT FROM s_cur INTO @spid,@bl
end
CLOSE s_cur
DEALLOCATE s_cur

####block
SELECT t1.resource_type,
‘database‘ = DB_NAME(resource_database_id),
‘blk object‘ = t1.resource_associated_entity_id,
t1.request_mode, t1.request_session_id,
t2.blocking_session_id,
t2.wait_duration_ms,
(SELECT SUBSTRING(text, t3.statement_start_offset/2 + 1,
(CASE WHEN t3.statement_end_offset = -1
THEN LEN(CONVERT(nvarchar(max),text)) * 2
ELSE t3.statement_end_offset
END - t3.statement_start_offset)/2)
FROM sys.dm_exec_sql_text(sql_handle)) AS query_text,
t2.resource_description
FROM
sys.dm_tran_locks AS t1,
sys.dm_os_waiting_tasks AS t2,
sys.dm_exec_requests AS t3
WHERE
t1.lock_owner_address = t2.resource_address AND
t1.request_request_id = t3.request_id AND
t2.session_id = t3.session_id;

##内存(最大限制)
select *,CAST(cntr_value/1024.0 as decimal(20,1)) MemoryMB
from master.sys.sysperfinfo
where counter_name=‘Total Server Memory (KB)‘
select *,CAST(cntr_value/1024.0 as decimal(20,1)) MemoryMB
from master.sys.sysperfinfo
where counter_name=‘Target Server Memory (KB)‘

##等待统计
SELECT wait_type, waiting_tasks_count, wait_time_ms, max_wait_time_ms, signal_wait_time_ms
FROM sys.dm_os_wait_stats
ORDER BY wait_type;
##快照
select * from sys.databases isread



























































以上是关于sqlserver 问题处理的主要内容,如果未能解决你的问题,请参考以下文章

sqlserver 处理连接池问题

SqlServer遇到SPN_Service Principal name问题的处理方法

SqlServer遇到SPN_Service Principal name问题有哪些处理方法

WGCLOUD数据源监测连不上sqlserver数据库问题处理

sqlserver设计视图修改表时不允许保存更改的问题处理

sqlserver设计视图修改表时不允许保存更改的问题处理