特种部队3,补中益气丸,幻想影院-206电影,电影节信息大全,影讯分享

操作系统是Windows2008R2 ,数据库是SQL2014 64位。

  近阶段服务器呈现过几回死机,管理员反应机器内存运用率100%导致机器卡死。所以做了个监测服务器的软件实时记载CPU数据,几日调查得出数据如下:

  SQL优化办法:

  1、检查衔接目标

USE master

GO

--假如要指定数据库就把注释去掉

SELECT * FROM sys.[sysprocesses] WHERE [spid]>50 --AND DB_NAME([dbid])='gposdb'

  

  当时衔接目标有67个其间‘WINAME’的主机名,‘jTDS’的进程名不属于已知常用软件,找到这台主机并处理衔接问题。在360流量防火墙中检查有哪个软件衔接了服务器IP,除之。

2、然后运用下面句子看一下各项目标是否正常,是否有堵塞,正常情况下查找成果应该为空。

SELECT TOP 10

[session_id],

[request_id],

[start_time] AS '开端时刻',

[status] AS '状况',

[command] AS '指令',

dest.[text] AS 'sql句子',

DB_NAME([database_id]) AS '数据库名',

[blocking_session_id] AS '正在堵塞其他会话的会话ID',

[wait_type] AS '等候资源类型',

[wait_time] AS '等候时刻',

[wait_resource] AS '等候的资源',

[reads] AS '物理读次数',

[writes] AS '写次数',

[logical_reads] AS '逻辑读次数',

[row_count] AS '回来成果行数'

FROM sys.[dm_exec_requests] AS der

CROSS APPLY

sys.[dm_exec_sql_text](der.[sql_handle]) AS dest

WHERE [session_id]>50 AND DB_NAME(der.[database_id])='gposdb'

ORDER BY [cpu_time] DESC

检查是哪些SQL句子占用较大能够运用下面代码

--在SSMS里挑选以文本格式显现成果

SELECT TOP 10

dest.[text] AS 'sql句子'

FROM sys.[dm_exec_requests] AS der

CROSS APPLY

sys.[dm_exec_sql_text](der.[sql_handle]) AS dest

WHERE [session_id]>50

ORDER BY [cpu_time] DESC

3、假如SQLSERVER存在要等候的资源,那么履行下面句子就会显现出会话中有多少个worker在等候

SELECT TOP 10

[session_id],

[request_id],

[start_time] AS '开端时刻',

[status] AS '状况',

[command] AS '指令',

dest.[text] AS 'sql句子',

DB_NAME([database_id]) AS '数据库名',

[blocking_session_id] AS '正在堵塞其他会话的会话ID',

der.[wait_type] AS '等候资源类型',

[wait_time] AS '等候时刻',

[wait_resource] AS '等候的资源',

[dows].[waiting_tasks_count] AS '当时正在进行等候的使命数',

[reads] AS '物理读次数',

[writes] AS '写次数',

[logical_reads] AS '逻辑读次数',

[row_count] AS '回来成果行数'

FROM sys.[dm_exec_requests] AS der

INNER JOIN [sys].[dm_os_wait_stats] AS dows

ON der.[wait_type]=[dows].[wait_type]

CROSS APPLY

sys.[dm_exec_sql_text](der.[sql_handle]) AS dest

WHERE [session_id]>50

ORDER BY [cpu_time] DESC;

4、查询CPU占用最高的SQL句子

SELECT TOP 10

total_worker_time/execution_count AS avg_cpu_cost, plan_handle,

execution_count,

(SELECT SUBSTRING(text, statement_start_offset/2 + 1,

(CASE WHEN statement_end_offset = -1

THEN LEN(CONVERT(nvarchar(max), text)) * 2

ELSE statement_end_offset

END - statement_start_offset)/2)

FROM sys.dm_exec_sql_text(sql_handle)) AS query_text

FROM sys.dm_exec_query_stats

ORDER BY [avg_cpu_cost] DESC;

5、索引缺失查询

SELECT

DatabaseName = DB_NAME(database_id)

,[Number Indexes Missing] = count(*)

FROM sys.dm_db_missing_index_details

GROUP BY DB_NAME(database_id)

ORDER BY 2 DESC;

SELECT TOP 10

[Total Cost] = ROUND(avg_total_user_cost * avg_user_impact * (user_seeks + user_scans),0)

, avg_user_impact

, TableName = statement

, [EqualityUsage] = equality_columns

, [InequalityUsage] = inequality_columns

, [Include Cloumns] = included_columns

FROM sys.dm_db_missing_index_groups g

INNER JOIN sys.dm_db_missing_index_group_stats s

ON s.group_handle = g.index_group_handle

INNER JOIN sys.dm_db_missing_index_details d

ON d.index_handle = g.index_handle

ORDER BY [Total Cost] DESC;

  找到索引缺失的表,依据查询成果中的要害次逐个树立索引。

  做完这些测验,基本能找到问题。