Query #1 is Version Info.

SQL and OS Version information for current instance

SELECT @@SERVERNAME AS [Server Name], @@VERSIONAS [SQL Server and OS Version Info];

Query #2 is Core Counts.

Get socket, physical core and logical core count from the SQL Server Error log.

EXEC sys.xp_readerrorlog 0, 1, N'detected', N'socket';

Query #3 is Server Properties.

Get selected server properties.

SELECT  SERVERPROPERTY('MachineName') AS [MachineName],

SERVERPROPERTY('ServerName') AS [ServerName],

SERVERPROPERTY('InstanceName') AS [Instance],

SERVERPROPERTY('IsClustered') AS [IsClustered],

SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS [ComputerNamePhysicalNetBIOS],

SERVERPROPERTY('Edition') AS [Edition],

SERVERPROPERTY('ProductLevel') AS [ProductLevel],                -- What servicing branch (RTM/SP/CU)

SERVERPROPERTY('ProductUpdateLevel') AS [ProductUpdateLevel],    -- Within a servicing branch, what CU# is applied

SERVERPROPERTY('ProductVersion') AS [ProductVersion],

SERVERPROPERTY('ProductMajorVersion') AS [ProductMajorVersion],

SERVERPROPERTY('ProductMinorVersion') AS [ProductMinorVersion],

SERVERPROPERTY('ProductBuild') AS [ProductBuild],

SERVERPROPERTY('ProductBuildType') AS [ProductBuildType],              -- Is this a GDR or OD hotfix (NULL if on a CU build)

SERVERPROPERTY('ProductUpdateReference') AS [ProductUpdateReference], -- KB article number that is applicable for this build

SERVERPROPERTY('ProcessID') AS [ProcessID],

SERVERPROPERTY('Collation') AS [Collation],

SERVERPROPERTY('IsFullTextInstalled') AS [IsFullTextInstalled],

SERVERPROPERTY('IsIntegratedSecurityOnly') AS [IsIntegratedSecurityOnly],

SERVERPROPERTY('FilestreamConfiguredLevel') AS [FilestreamConfiguredLevel],

SERVERPROPERTY('IsHadrEnabled') AS [IsHadrEnabled],

SERVERPROPERTY('HadrManagerStatus') AS [HadrManagerStatus],

SERVERPROPERTY('IsXTPSupported') AS [IsXTPSupported],

SERVERPROPERTY('IsPolybaseInstalled') AS [IsPolybaseInstalled],    -- New for SQL Server 2016

SERVERPROPERTY('InstanceDefaultDataPath') AS [InstanceDefaultDataPath],

SERVERPROPERTY('InstanceDefaultLogPath') AS [InstanceDefaultLogPath],

SERVERPROPERTY('BuildClrVersion') AS [Build CLR Version];

-- This gives you a lot of useful information about your instance of SQL Server,

-- such as the ProcessID for SQL Server and your collation

-- Some columns will be NULL on older SQL Server builds

Query #4 is Configuration Values.

-- Get instance-level configuration values for instance

SELECT name, value, value_in_use, minimum, maximum, [description], is_dynamic, is_advanced

FROM sys.configurations WITH (NOLOCK)

ORDERBY name OPTION (RECOMPILE);

-- Focus on these settings:

-- automatic soft-NUMA disabled (should be 0 in most cases)

-- backup checksum default (should be 1)

-- backup compression default (should be 1 in most cases)

-- clr enabled (only enable if it is needed)

-- cost threshold for parallelism (depends on your workload)

-- lightweight pooling (should be zero)

-- max degree of parallelism (depends on your workload and hardware)

-- max server memory (MB) (set to an appropriate value, not the default)

-- optimize for ad hoc workloads (should be 1)

-- priority boost (should be zero)

-- remote admin connections (should be 1)

-- New options for SQL Server 2016

-- hadoop connectivity

-- polybase network encryption

-- remote data archive (to enable Stretch Databases)

Query #5 Global Trace Flags

-- Returns a list of all global trace flags that are enabled (Query 5) (Global Trace Flags)

DBCC TRACESTATUS (-1);

-- If no global trace flags are enabled, no results will be returned.

-- It is very useful to know what global trace flags are currently enabled as part of the diagnostic process.

-- Common trace flags that should be enabled in most cases

-- TF 3226 - Supresses logging of successful database backup messages to the SQL Server Error Log

-- The behavior of TF 1118 and 2371 are enabled in SQL Server 2016 by default

Query #6 Process Memory

-- SQL Server Process Address space info (Query 6) (Process Memory)

-- (shows whether locked pages is enabled, among other things)

SELECT physical_memory_in_use_kb/1024 AS [SQL Server Memory Usage (MB)],

large_page_allocations_kb, locked_page_allocations_kb, page_fault_count,

memory_utilization_percentage, available_commit_limit_kb,

process_physical_memory_low, process_virtual_memory_low

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

-- You want to see 0 for process_physical_memory_low

-- You want to see 0 for process_virtual_memory_low

-- This indicates that you arenotunder internal memory pressure

Query #7 SQL Server Services Info

-- SQL Server Services information (Query 7) (SQL Server Services Info)

SELECT servicename, process_id, startup_type_desc, status_desc,

last_startup_time, service_account, is_clustered, cluster_nodename, [filename]

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

-- Tells you the account being used for the SQL Server Service and the SQL Agent Service

-- Shows the process_id, when they were last started, and their current status

-- Shows whether you are running on a failover cluster instance

Query #8 SQL Server Agent Jobs

-- Get SQL Server Agent jobs and Category information (Query 8) (SQL Server Agent Jobs)

SELECT sj.name AS [JobName], sj.[description] AS [JobDescription], SUSER_SNAME(sj.owner_sid) AS [JobOwner],

sj.date_created, sj.[enabled], sj.notify_email_operator_id, sj.notify_level_email, sc.name AS [CategoryName],

js.next_run_date, js.next_run_time

FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK)

INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)

ON sj.category_id = sc.category_id

LEFT OUTER JOIN msdb.dbo.sysjobschedules AS js WITH (NOLOCK)

ON sj.job_id = js.job_id

ORDER BY sj.name OPTION (RECOMPILE);

-- Gives you some basic information about your SQL Server Agent jobs, who owns them and how they are configured

-- Look for Agent jobs that are not owned by sa

-- Look for jobs that have a notify_email_operator_id set to 0 (meaning no operator)

-- Look for jobs that have a notify_level_email set to 0 (meaning no e-mail is ever sent)

-- MSDN sysjobs documentation

-- //msdn.microsoft.com/en-us/library/ms189817.aspx

Query #9 SQL Server Agent Alerts

-- Get SQL Server Agent Alert Information (Query 9) (SQL Server Agent Alerts)

SELECT name, event_source, message_id, severity, [enabled], has_notification,

delay_between_responses, occurrence_count, last_occurrence_date, last_occurrence_time

FROM msdb.dbo.sysalerts WITH (NOLOCK)

ORDERBY name OPTION (RECOMPILE);

-- Gives you some basic information about your SQL Server Agent Alerts (which are different from SQL Server Agent jobs)

-- Read more about Agent Alerts here: http://www.sqlskills.com/blogs/glenn/creating-sql-server-agent-alerts-for-critical-errors/

Query #10 Windows Info

-- Windows information (Query 10) (Windows Info)

SELECT windows_release, windows_service_pack_level,

windows_sku, os_language_version

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

-- Gives you major OS version, Service Pack, Edition, and language info for the operating system

-- 10.0 is either Windows 10 or Windows Server 2016

-- 6.3 is either Windows 8.1 or Windows Server 2012 R2

-- 6.2 is either Windows 8 or Windows Server 2012

-- 6.1 is either Windows 7 or Windows Server 2008 R2

-- 6.0 is either Windows Vista or Windows Server 2008

-- Windows SKU codes

-- 4 is Enterprise Edition

-- 7 is Standard Server Edition

-- 8 is Datacenter Server Edition

-- 10 is Enterprise Server Edition

-- 48 is Professional Edition

-- 1033 for os_language_version is US-English

-- SQL Server 2014 requires Windows Server 2012 or newer

-- Quick-Start Installation of SQL Server 2016

-- https://msdn.microsoft.com/en-us/library/bb500433(v=sql.130).aspx

-- Hardware and Software Requirements for Installing SQL Server 2016

-- https://msdn.microsoft.com/en-us/library/ms143506(v=sql.130).aspx

-- Using SQL Server in Windows 8, Windows 8.1, Windows Server 2012 and Windows Server 2012 R2 environments

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

Query #11 SQL Server NUMA Info

-- SQL Server NUMA Node information

SELECT node_id, node_state_desc, memory_node_id, processor_group, online_scheduler_count,

active_worker_count, avg_load_balance, resource_monitor_state

FROM sys.dm_os_nodes WITH (NOLOCK)

WHERE node_state_desc <> N'ONLINE DAC'OPTION (RECOMPILE);

--

avg_load_balance :Average number of tasks per scheduler on this node.

-- Gives you some useful information about the composition and relative load on your NUMA nodes

-- You want to see an equal number of schedulers on each NUMA node

-- Watch out if SQL Server 2016 Standard Edition has been installed on a machine with more than 16 physical cores

-- Balancing Your Available SQL Server Core Licenses Evenly Across NUMA Nodes

-- http://www.sqlskills.com/blogs/glenn/balancing-your-available-sql-server-core-licenses-evenly-across-numa-nodes/

Query #12 System Memory

-- Good basic information about OS memory amounts and state

SELECT total_physical_memory_kb/1024 AS [Physical Memory (MB)],

available_physical_memory_kb/1024 AS [Available Memory (MB)],

total_page_file_kb/1024 AS [Total Page File (MB)],

available_page_file_kb/1024 AS [Available Page File (MB)],

system_cache_kb/1024 AS [System Cache (MB)],

system_memory_state_desc AS [System Memory State]

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

-- You want to see "Available physical memory is high" for System Memory State

-- This indicates that you are not under external memory pressure

---------------------------------------------------------------------------------------------------

  1. 本文内容来自Glenn Berry ,原文中对查询做了简单的解析和说明。此查询是针对SQL Server 2016的,但在不涉及新特性的时,2008~2016皆可用。
  2. 从事DBA工作一些年后,每个人都会有自己的Toolkit。我在整理脚本时,发现这个系列的脚本很实用和具有启发性,就收集整理出来了。
  3. 关于系统DMV的使用,需要知道:

    (a)这些数据都是上次实例启动以来的积累数据

    (b)利用它们来诊断时,很多情况下需要运行多次收集数据,再分析。

    (c)对于性能指标,不要迷信所谓的推荐值。你的系统运行正常,满足你的用户,满足企业要求,就是正常值。所以说平时收集基线数据,是一件很重要的事情。

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

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

    Query #13 SQL Server Error Log(FC) -- Shows you where the SQL Server failover cluster diagnostic log ...

  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. 用node-webkit 开发 PC 客户端

      7月 3 2013 导言 node-webkit 是一个很神奇的桌面客户端项目,正如这个项目的名字,这个项目是由node 和 webkit 构成,简单来说,就是你可以用HTML 5和 node 进 ...

  2. python排序算法的实现-快速排序

    1. 算法描述: 1.先从数列中取出一个数作为基准数. 2.分区过程,将比这个数大的数全放到它的右边,小于或等于它的数全放到它的左边. 3.再对左右区间重复第二步,直到各区间只有一个数. 2.pyth ...

  3. Django 源码小剖: Django ORM 查询管理器

    ORM 查询管理器 对于 ORM 定义: 对象关系映射, Object Relational Mapping, ORM, 是一种程序设计技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换.从 ...

  4. Navi.Soft30.产品.Net对象查看器.操作手册

    1系统简介 1.1功能简述 在软件开发过程中,我们会编写各种类以及创建类的属性,方法,事件等.特别是第三方控件或组件,刚拿到手时,若没有完善的开发文档,很难下手.这时,若是可以查看这些DLL的成员对象 ...

  5. 【css】ie6 和 ie7 下 position 与 overflow 的问题

    前几天做的项目中碰到这样一个问题,在 ie6 和 ie7 下,给父元素设置 overflow:hidden 不起作用无法隐藏,后来发现是子元素中有设置 position:relative,如果子元素删 ...

  6. 第 3 章 MySQL 存储引擎简介

    第 3 章 MySQL 存储引擎简介 前言 3.1 MySQL 存储引擎概述 MyISAM 存储引擎是 MySQL 默认的存储引擎,也是目前 MySQL 使用最为广泛的存储引擎之一.他的前身就是我们在 ...

  7. Oracle-ARCGIS-SDE 数据整合遇到的问题

    一. 近日在做全文检索,基础采用oracle text,版本是10g,做好管理页面后,有功能是删除索引,就是生成drop index的语句.没有想到这个全文检索的index这么直接弄还不行,经过这样删 ...

  8. ubuntu-16.04+-xxx-i386.iso :安装 Oracle 11gR2 数据库

    前言:说实在的,ubuntu 16.04以上很难安装oracle!其间走过了艰难的一段路! 重要附件:ubuntu16.04+-xxx-i386.iso_安装oracle所需的软件包.zip 特点: ...

  9. Android程序的签名保护及绕过方法

    随着Android 市场的扩大,各类盗版.破解.打包党纷纷涌现,其使用的手法无非是apk _> smali ->修改代码 ->重打包签名,为对抗此类技术,广大程序员挖掘了Androi ...

  10. [原创]HierarchyView的实现原理和Android设备无法使用HierarchyView的解决方法

    最近在看一个老外写的东西,发现里面有个类,使用这个类可以让任何设备使用HierarchyView. 众所周知,市面上卖的Android设备,一般都不能使用HierarchyView,所以借此机会,了解 ...