-
SQL语句大全之监视SQL Server
监视SQL Server
1、监视工具
sp_who、sp_who2、sp_lock2、性能监视器
三个方面:(1)处理器使用率;
(2)磁盘活动;
(3)内存使用率;
3、查看锁定信息
SELECT l.resource_type, l.resource_associated_entity_id,OBJECT_NAME(sp.OBJECT_ID) AS ObjectName
,l.request_status, l.request_mode,request_session_id
,l.resource_description
FROM sys.dm_tran_locks l
LEFT JOIN sys.partitions sp
ON sp.hobt_id = l.resource_associated_entity_id
WHERE l.resource_database_id = DB_ID()
4、数据库中的索引使用情况
--------------------------------------------------------------------------------IF OBJECT_ID('dbo.IndexUsageStats') IS NULL
CREATE TABLE dbo.IndexUsageStats
(
IndexName sysname NULL
,ObjectName sysname NOT NULL
,user_seeks bigint NOT NULL
,user_scans bigint NOT NULL
,user_lookups bigint NOT NULL
,user_updates bigint NOT NULL
,last_user_seek datetime NULL
,last_user_scan datetime NULL
,last_user_lookup datetime NULL
,last_user_update datetime NULL
,StatusDate datetime NOT NULL
,DatabaseName sysname NOT NULL
)
GO
----Below query will give you index USED per table in a database.----
INSERT INTO dbo.IndexUsageStats
(
IndexName
,ObjectName
,user_seeks
,user_scans
,user_lookups
,user_updates
,last_user_seek
,last_user_scan
,last_user_lookup
,last_user_update
,StatusDate
,DatabaseName
)
SELECT
si.name AS IndexName
,so.name AS ObjectName
,diu.user_seeks
,diu.user_scans
,diu.user_lookups
,diu.user_updates
,diu.last_user_seek
,diu.last_user_scan
,diu.last_user_lookup
,diu.last_user_update
,GETDATE() AS StatusDate
,sd.name AS DatabaseName
FROM sys.dm_db_index_usage_stats diu
JOIN sys.indexes si
ON diu.object_id = si.object_id
AND diu.index_id = si.index_id
JOIN sys.all_objects so
ON so.object_id = si.object_id
JOIN sys.databases sd
ON sd.database_id = diu.database_id
WHERE is_ms_shipped <> 1
AND diu.database_id = DB_ID()
IF OBJECT_ID('dbo.NotUsedIndexes') IS NULL
CREATE TABLE dbo.NotUsedIndexes
(
IndexName sysname NULL
,ObjectName sysname NOT NULL
,StatusDate datetime NOT NULL
,DatabaseName sysname NOT NULL
)
----Below query will give you index which are NOT used per table in a database.----
INSERT dbo.NotUsedIndexes
(
IndexName
,ObjectName
,StatusDate
,DatabaseName
)
SELECT
si.name AS IndexName
,so.name AS ObjectName
,GETDATE() AS StatusDate
,DB_NAME()
FROM sys.indexes si
JOIN sys.all_objects so
ON so.object_id = si.object_id
WHERE si.index_id NOT IN (
SELECT index_id
FROM sys.dm_db_index_usage_stats diu
WHERE si.object_id = diu.object_id
AND si.index_id = diu.index_id
)
AND so.is_ms_shipped <> 1
5、查看阻塞情况
SELECTt1.resource_type
,t1.resource_database_id
,t1.resource_associated_entity_id
,OBJECT_NAME(sp.OBJECT_ID) AS ObjectName
,t1.request_mode
,t1.request_session_id
,t2.blocking_session_id
FROM sys.dm_tran_locks as t1
JOIN sys.dm_os_waiting_tasks as t2
ON t1.lock_owner_address = t2.resource_address
LEFT JOIN sys.partitions sp
ON sp.hobt_id = t1.resource_associated_entity_id
6、已连接用户的信息
SELECT login_name, count(session_id) as session_countFROM sys.dm_exec_sessions
GROUP BY login_name
7、内存使用情况
SELECTname
,type
,SUM(single_pages_kb + multi_pages_kb) AS MemoryUsedInKB
FROM sys.dm_os_memory_clerks
GROUP BY name, type
ORDER BY SUM(single_pages_kb + multi_pages_kb) DESC
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式