Query #13 SQL Server Error Log(FC)

-- Shows you where the SQL Server failover cluster diagnostic log is located and how it is configured

SELECT is_enabled, [path], max_size, max_files

FROM sys.dm_os_server_diagnostics_log_configurations WITH (NOLOCK) OPTION (RECOMPILE);

-- Knowing this information is important for troubleshooting purposes

-- Also shows you the location of other error and diagnostic log files

Query #14 Cluster Node Properties

-- Get information about your cluster nodes and their status

-- (if your database server is in a failover cluster)

SELECT NodeName, status_description, is_current_owner

FROM sys.dm_os_cluster_nodes WITH (NOLOCK) OPTION (RECOMPILE);

-- Knowing which node owns the cluster resources is critical

-- Especially when you are installing Windows or SQL Server updates

Query #15 AlwaysOn AG Cluster

-- Get information about any AlwaysOn AG cluster this instance is a part of

SELECT cluster_name, quorum_type_desc, quorum_state_desc

FROM sys.dm_hadr_cluster WITH (NOLOCK) OPTION (RECOMPILE);

-- You will see no results if your instance is not using AlwaysOn AGs

-- Recommended hotfixes and updates for Windows Server 2012 R2-based failover clusters

-- http://support.microsoft.com/kb/2920151

Query #16 Hardware Info(FOR 2016)

-- Hardware information from SQL Server 2016

SELECT cpu_count AS [Logical CPU Count], scheduler_count, hyperthread_ratio AS [Hyperthread Ratio],

cpu_count/hyperthread_ratio AS [Physical CPU Count],

physical_memory_kb/1024 AS [Physical Memory (MB)], committed_kb/1024 AS [Committed Memory (MB)],

committed_target_kb/1024 AS [Committed Target Memory (MB)],

max_workers_count AS [Max Workers Count], affinity_type_desc AS [Affinity Type],

sqlserver_start_time AS [SQL Server StartTime], virtual_machine_type_desc AS [Virtual Machine Type],

softnuma_configuration_desc AS [Soft NUMA Configuration]

FROM sys.dm_os_sys_info WITH (NOLOCK) OPTION (RECOMPILE);

-- Gives you some good basic hardware information about your database server

-- Cannot distinguish between HT and multi-core

-- Note: virtual_machine_type_desc of HYPERVISOR does not automatically mean you are running SQL Server inside of a VM

-- It merely indicates that you have a hypervisor running on your host

-- Soft NUMA configuration is a newcolumnforSQL Server 2016

Query #17 System Manufacturer

-- Get System Manufacturer and model number from SQL Server Error log

EXEC sys.xp_readerrorlog 0, 1, N'Manufacturer';

-- This can help you determine the capabilities and capacities of your database server

-- Can also be used to confirm if you are running in a VM

-- This query might take a few seconds if you have not recycled your error log recently

-- This query will returnno results if your error log has been recycled since the instance was started

Query #18 Processor Description

-- Get processor description from Windows Registry

EXEC sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'HARDWARE\DESCRIPTION\System\CentralProcessor\0', N'ProcessorNameString';

-- Gives you the model number and rated clock speed of your processor(s)

-- Your processors may be running at less than the rated clock speed due

-- to the Windows Power Plan or hardware power management

-- You can use CPU-Z to get your actual CPU core speed and a lot of other useful information

-- http://www.cpuid.com/softwares/cpu-z.html

-- You can learn more about processor selection for SQL Server by following this link

-- http://www.sqlskills.com/blogs/glenn/processor-selection-for-sql-server/

Query #19 BPE Configuration

-- See if buffer pool extensions (BPE) is enabled

SELECT [path], state_description, current_size_in_kb,

CAST(current_size_in_kb/1048576.0 ASDECIMAL(10,2)) AS [Size (GB)]

FROM sys.dm_os_buffer_pool_extension_configuration WITH (NOLOCK) OPTION (RECOMPILE);

-- BPE is available in both Standlard Edition and Enterprise Edition

-- It is a more interesting feature for Standard Edition

-- Buffer Pool Extension to SSDs in SQL Server 2014

-- http://blogs.technet.com/b/dataplatforminsider/archive/2013/07/25/buffer-pool-extension-to-ssds-in-sql-server-2014.aspx

Query #20 BPE Usage

-- Look at buffer descriptors to see BPE usage by database

SELECT DB_NAME(database_id) AS [Database Name], COUNT(page_id) AS [Page Count],

CAST(COUNT(*)/128.0 ASDECIMAL(10, 2)) AS [Buffer size(MB)],

AVG(read_microsec) AS [AvgReadTime (microseconds)]

FROM sys.dm_os_buffer_descriptors WITH (NOLOCK)

WHERE database_id <> 32767

AND is_in_bpool_extension = 1

GROUPBY DB_NAME(database_id)

ORDERBY [Buffer size(MB)] DESCOPTION (RECOMPILE);

Query #21 Memory Dump Info

-- Get information on location, time and size of any memory dumps from SQL Server

SELECT [filename], creation_time, size_in_bytes/1048576.0 AS [Size (MB)]

FROM sys.dm_server_memory_dumps WITH (NOLOCK)

ORDERBY creation_time DESCOPTION (RECOMPILE);

-- This will not return any rows if you have

-- not had any memory dumps (which is a good thing)

Query #22 Database Filename and Paths

-- File names and paths for all user and system databases on instance

SELECT DB_NAME([database_id]) AS [Database Name],

[file_id], name, physical_name, [type_desc], state_desc,

is_percent_growth, growth,

CONVERT(bigint, growth/128.0) AS [Growth in MB],

CONVERT(bigint, size/128.0) AS [Total Size in MB]

FROM sys.master_files WITH (NOLOCK)

ORDER BY DB_NAME([database_id]) OPTION (RECOMPILE);

-- Things to look at:

-- Are data files and log files on different drives?

-- Is everything on the C: drive?

-- Is TempDB on dedicated drives?

-- Is there only one TempDB data file?

-- Are all of the TempDB data files the same size?

-- Are there multiple data files for user databases?

-- Is percent growth enabled for any files (which is bad)?

Query #23 Volume Info

-- Volume info for all LUNS that have database files on the current instance

SELECTDISTINCT vs.volume_mount_point, vs.file_system_type,

vs.logical_volume_name, CONVERT(DECIMAL(18,2),vs.total_bytes/1073741824.0) AS [Total Size (GB)],

CONVERT(DECIMAL(18,2),vs.available_bytes/1073741824.0) AS [Available Size (GB)],

CAST(CAST(vs.available_bytes ASFLOAT)/ CAST(vs.total_bytes ASFLOAT) ASDECIMAL(18,2)) * 100 AS [SpaceFree %]

FROM sys.master_files AS f WITH (NOLOCK)

CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.[file_id]) AS vs

ORDERBY vs.volume_mount_point OPTION (RECOMPILE);

-- Shows you the total and free space on the LUNs where you have database files

-- Being low onfreespace can negatively affect performance

Query #24 Drive Level Latency

-- Drive level latency information

SELECT tab.[Drive], tab.volume_mount_point AS [Volume Mount Point],

CASE

WHEN num_of_reads = 0 THEN 0

ELSE (io_stall_read_ms/num_of_reads)

END AS [Read Latency],

CASE

WHEN io_stall_write_ms = 0 THEN 0

ELSE (io_stall_write_ms/num_of_writes)

END AS [Write Latency],

CASE

WHEN (num_of_reads = 0 AND num_of_writes = 0) THEN 0

ELSE (io_stall/(num_of_reads + num_of_writes))

END AS [Overall Latency],

CASE

WHEN num_of_reads = 0 THEN 0

ELSE (num_of_bytes_read/num_of_reads)

END AS [Avg Bytes/Read],

CASE

WHEN io_stall_write_ms = 0 THEN 0

ELSE (num_of_bytes_written/num_of_writes)

END AS [Avg Bytes/Write],

CASE

WHEN (num_of_reads = 0 AND num_of_writes = 0) THEN 0

ELSE ((num_of_bytes_read + num_of_bytes_written)/(num_of_reads + num_of_writes))

END AS [Avg Bytes/Transfer]

FROM (SELECT LEFT(UPPER(mf.physical_name), 2) AS Drive, SUM(num_of_reads) AS num_of_reads,

SUM(io_stall_read_ms) AS io_stall_read_ms, SUM(num_of_writes) AS num_of_writes,

SUM(io_stall_write_ms) AS io_stall_write_ms, SUM(num_of_bytes_read) AS num_of_bytes_read,

SUM(num_of_bytes_written) AS num_of_bytes_written, SUM(io_stall) AS io_stall, vs.volume_mount_point

FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS vfs

INNER JOIN sys.master_files AS mf WITH (NOLOCK)

ON vfs.database_id = mf.database_id AND vfs.file_id = mf.file_id

CROSS APPLY sys.dm_os_volume_stats(mf.database_id, mf.[file_id]) AS vs

GROUP BY LEFT(UPPER(mf.physical_name), 2), vs.volume_mount_point) AS tab

ORDER BY [Overall Latency] OPTION (RECOMPILE);

-- Shows you the drive-level latency for reads and writes, in milliseconds

-- Latency above 20-25ms is usually a problem

Query #25 IO Stalls by File

-- Calculates average stalls per read, per write, and per total input/output for each database file

SELECT DB_NAME(fs.database_id) AS [Database Name], CAST(fs.io_stall_read_ms/(1.0 + fs.num_of_reads) ASNUMERIC(10,1)) AS [avg_read_stall_ms],

CAST(fs.io_stall_write_ms/(1.0 + fs.num_of_writes) ASNUMERIC(10,1)) AS [avg_write_stall_ms],

CAST((fs.io_stall_read_ms + fs.io_stall_write_ms)/(1.0 + fs.num_of_reads + fs.num_of_writes) ASNUMERIC(10,1)) AS [avg_io_stall_ms],

CONVERT(DECIMAL(18,2), mf.size/128.0) AS [FileSize (MB)], mf.physical_name, mf.type_desc, fs.io_stall_read_ms, fs.num_of_reads,

fs.io_stall_write_ms, fs.num_of_writes, fs.io_stall_read_ms + fs.io_stall_write_ms AS [io_stalls], fs.num_of_reads + fs.num_of_writes AS [total_io],

io_stall_queued_read_ms AS [Resource Governor Total Read IO Latency (ms)], io_stall_queued_write_ms AS [Resource Governor Total Write IO Latency (ms)]

FROM sys.dm_io_virtual_file_stats(null,null) AS fs

INNERJOIN sys.master_files AS mf WITH (NOLOCK)

ON fs.database_id = mf.database_id

AND fs.[file_id] = mf.[file_id]

ORDERBY avg_io_stall_ms DESCOPTION (RECOMPILE);

-- Helps determine which database files on the entire instance have the most I/O bottlenecks

-- This can help you decide whether certain LUNs are overloaded and whether you might

-- want to move some files to a different location or perhaps improve your I/O performance

Query #25 IO Warning

-- Look for I/O requests taking longer than 15 seconds in the five most recent SQL Server Error Logs

CREATE TABLE #IOWarningResults(LogDate datetime, ProcessInfo sysname, LogText nvarchar(1000));

INSERT INTO #IOWarningResults

EXEC xp_readerrorlog 0, 1, N'taking longer than 15 seconds';

INSERT INTO #IOWarningResults

EXEC xp_readerrorlog 1, 1, N'taking longer than 15 seconds';

INSERT INTO #IOWarningResults

EXEC xp_readerrorlog 2, 1, N'taking longer than 15 seconds';

INSERT INTO #IOWarningResults

EXEC xp_readerrorlog 3, 1, N'taking longer than 15 seconds';

INSERT INTO #IOWarningResults

EXEC xp_readerrorlog 4, 1, N'taking longer than 15 seconds';

SELECT LogDate, ProcessInfo, LogText

FROM #IOWarningResults

ORDER BY LogDate DESC;

DROP TABLE #IOWarningResults;

-- Finding 15 second I/O warnings in the SQL Server Error Log is useful evidence of

-- poor I/O performance (which might have many different causes)

-- Diagnostics in SQL Server help detect stalled and stuck I/O operations

-- https://support.microsoft.com/en-us/kb/897284

SQL Server 诊断查询-(2)的更多相关文章

  1. SQL Server 诊断查询-(1)

    Query #1 is Version Info. SQL and OS Version information for current instance SELECT @@SERVERNAME AS ...

  2. SQL Server 诊断查询-(5)

    Query #57 Buffer Usage -- Breaks down buffers used by current database by object (table, index) in t ...

  3. SQL Server 诊断查询-(4)

    Query #41 Memory Clerk Usage -- Memory Clerk Usage for instance -- Look for high value for CACHESTOR ...

  4. SQL Server 诊断查询-(3)

    Query #27 Database Properties    -- Recovery model, log reuse wait description, log file size, log u ...

  5. Expert for SQL Server 诊断系列

    Expert for SQL Server 诊断系列 Expert 诊断优化系列------------------锁是个大角色   前面几篇已经陆续从服务器的几个大块讲述了SQL SERVER数据库 ...

  6. Sql Server中查询今天、昨天、本周、上周、本月、上月数据

    Sql Server中查询今天.昨天.本周.上周.本月.上月数据 在做Sql Server开发的时候有时需要获取表中今天.昨天.本周.上周.本月.上月等数据,这时候就需要使用DATEDIFF()函数及 ...

  7. Sql Server参数化查询之where in和like实现详解

    where in 的参数化查询实现 首先说一下我们常用的办法,直接拼SQL实现,一般情况下都能满足需要 string userIds = "1,2,3,4"; using (Sql ...

  8. 【转】Sql Server参数化查询之where in和like实现之xml和DataTable传参

    转载至: http://www.cnblogs.com/lzrabbit/archive/2012/04/29/2475427.html 在上一篇Sql Server参数化查询之where in和li ...

  9. 【转】Sql Server参数化查询之where in和like实现详解

    转载至:http://www.cnblogs.com/lzrabbit/archive/2012/04/22/2465313.html 文章导读 拼SQL实现where in查询 使用CHARINDE ...

随机推荐

  1. ACM-南京理工大学第八届程序设计竞赛-网络赛(2016.04.17)

    A.偷吃糖果Time Limit: 1000Ms Memory Limit: 65536KB Description小鱼喜欢吃糖果.他有两盒糖果,两盒糖果分别仅由小写字母组成的字符串s和字符串t构成. ...

  2. css学习--css基础

    学习慕课网笔记,课程:http://www.imooc.com/code/2024 1.css选择器 子选择器:parent>child 子选择器是指选择parent的范围内的第一个子元素.这里 ...

  3. UWP开发入门(二十二)——Storyboard和Animation

    微博上有同学问我MyerSplash是如何实现那个很炫的图片点亮,然后移动到屏幕中央的效果.惭愧啊,我又不是作者哪里会知道.硬着头皮去GitHub拜读了高手的代码,自愧弗如,比我不知道高到哪里去了…… ...

  4. iOS通过ARC管理内存(内容根据iOS编程编写)

    栈 当程序执行某个方法(或函数)时,会从内存中一个叫栈的区域分配一块内存空间,这块内存空间我们叫帧.帧负责保护程序在方法内声明的变量的值.在方法内声明的变量我们称之为局部变量. 当我们的程序开始启动, ...

  5. 转: IntelliJ IDEA 2016.2.2注册码

    43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiI ...

  6. DDL/DML是什么?

    DDL:(Data Definition Language)数据库定义语言 它是定义数据库的语言, 里面包含: CREATE ALTER DROP TRUNCATE COMMENT RENAME DM ...

  7. 强大的自适应jQuery焦点图特效

    jQuery焦点图切换自适应效果 自适应jQuery焦点图特效是一款支持移动端的响应式jQuery焦点图插件,支持flexible布局,支持移动触摸事件等. 今天我们要来分享一款很灵活的jQuery焦 ...

  8. javascript图片展示墙特效

    查看效果:http://hovertree.com/code/javascript/pwl4bhoi.htm 代码如下: <!DOCTYPE html> <html> < ...

  9. ListView灵活的用法

    以下是示例的效果图: WinForm的ListView控件是可以分组显示的,还可排序. 可以把ListView的View属性设置为Details 完整项目请到下面网址查找下载 http://hover ...

  10. 关于xamarin.forms在MVVM情况下如何DisplayActionSheet

    最近一直在研究Xmarin.forms,碰到了一个棘手的问题,就是在MVVM的情况下如何在ViewModel中去使用DisplayActionSheet,然而我使用的是XAML模式,也就是说,只有在后 ...