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. .NET 中Barcode Library的应用二

    .NET中Barcode Library的应用二 介绍 在上一篇中我已经简单介绍了这个函数库(条形码应用之一------------函数库的简介).在这一篇中我将使用这个库提供更多的操作,希望对大家有 ...

  2. 输入URL到展现页面的全过程

    最近在看一本关于网络协议的书<图解HTTP> 当我们在浏览器的地址栏输入 http://www.pwstrick.com ,然后回车,回车这一瞬间到看到页面到底发生了什么呢? 1.  域名 ...

  3. Android百度地图 关于visibility="gone"的奇葩问题

    最近在项目中遇到一个奇葩问题,花了很长时间,在这里记录下. 问题描述:我的主界面是ViewPager+Fragment,并且设置缓存了我的4个ViewPager页面.左侧是一个侧滑菜单,点击相应按钮打 ...

  4. Stackoverflow/dapper的Dapper-Extensions用法(二)

    之前翻译了Dapper-Extensions项目首页的readme.md,大家应该对这个类库的使用有一些了解了吧,接下来是wiki的文档翻译,主要提到了AutoClassMapper.KeyTypes ...

  5. 【JUC】JUC集合框架综述

    一.前言 完成了JUC的锁框架的分析后,现在分析JUC集合框架,之前分析过的集合框架,很大程度上都不是线程安全的,其在多线程环境下会出现很多问题,为了保证在多线程环境下仍然能够正确安全的访问集合,出现 ...

  6. java删除文件夹

    想删除本地一个项目目录,结果windows说路径太长,不能删除.于是试了试java删除.一切ok.以后一定要抓紧时间学python. /** * Created by rmiao on 4/21/20 ...

  7. Hibernate —— 检索策略

    一.Hibernate 的检索策略本质上是为了优化 Hibernate 性能. 二.Hibernate 检索策略包括类级别的检索策略.和关联级别的检索策略(<set> 元素) 三.类级别的 ...

  8. jQuery简洁大方的登录页面模板

    jQuery+CSS网站登录模板本模板带验证码 在线体验:http://hovertree.com/texiao/jquery/13.htm Demo 2:http://hovertree.com/h ...

  9. Redis修改数据多线程并发—Redis并发锁

    本文版权归博客园和作者本人吴双共同所有 .转载爬虫请注明地址,博客园蜗牛 http://www.cnblogs.com/tdws/p/5712835.html 蜗牛Redis系列文章目录http:// ...

  10. [.NET逆向] .net IL 指令速查(net破解必备)

    .net的破解比较特殊,很多人看见IL就头疼,最近在研究的时候发现了这个东东 相信对广大学习net破解的人一定有帮助 .对上指令表一查,跟读原代码没什么区别了, 名称 说明 Add 将两个值相加并将结 ...