sqlserver内存、会话、连接查询
2024-10-10 21:03:07
1、连接查询
select * from sysprocesses where dbid in (select dbid from sysdatabases where name='dbname')
--或者
SELECT * FROM
[Master].[dbo].[SYSPROCESSES] WHERE [DBID] IN ( SELECT
[DBID]
FROM
[Master].[dbo].[SYSDATABASES]
WHERE
NAME='dbname'
)
2、当前正在执行的sql查询
SELECT [Spid] = session_id ,
ecid ,
[Database] = DB_NAME(sp.dbid) ,
[User] = nt_username ,
[Status] = er.status ,
[Wait] = wait_type ,
[Individual Query] = SUBSTRING(qt.text,
er.statement_start_offset / 2,
( CASE WHEN er.statement_end_offset = -1
THEN LEN(CONVERT(NVARCHAR(MAX), qt.text))
* 2
ELSE er.statement_end_offset
END - er.statement_start_offset )
/ 2) ,
[Parent Query] = qt.text ,
Program = program_name ,
hostname ,
nt_domain ,
start_time
FROM sys.dm_exec_requests er
INNER JOIN sys.sysprocesses sp ON er.session_id = sp.spid
CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) AS qt
WHERE session_id > 50 -- Ignore system spids.
AND session_id NOT IN ( @@SPID ) -- Ignore this current statement.
ORDER BY 1 ,
清理存储过程预编译等缓存、会话缓存、系统缓存、缓存区
DBCC FREEPROCCACHE
DBCC FREESESSIONCACHE
DBCC FREESYSTEMCACHE('All')
DBCC DROPCLEANBUFFERS
--内存使用情况
SELECT * FROM sys.dm_os_performance_counters
WHERE counter_name IN ('Target Server Memory (KB)','Total Server Memory (KB)') -- 内存状态
DBCC MemoryStatus --查看最小最大内存
SELECT
cfg.name AS [Name],
cfg.configuration_id AS [Number],
cfg.minimum AS [Minimum],
cfg.maximum AS [Maximum],
cfg.is_dynamic AS [Dynamic],
cfg.is_advanced AS [Advanced],
cfg.value AS [ConfigValue],
cfg.value_in_use AS [RunValue],
cfg.description AS [Description]
FROM
sys.configurations AS cfg --设置最小最大内存 sp_configure 'show advanced options', 1 go
sp_configure 'min server memory', 0
RECONFIGURE
GO sp_configure 'max server memory', 2147483647
RECONFIGURE
GO sp_configure 'max server memory', 256
RECONFIGURE
GO
sp_configure 'show advanced options', 0
CREATE proc [dbo].reclaimmemory --强制释放内存 as begin DBCC FREEPROCCACHE
DBCC FREESESSIONCACHE
DBCC FREESYSTEMCACHE('All')
DBCC DROPCLEANBUFFERS exec sp_configure 'max server memory', 256
EXEC ('RECONFIGURE' ) WAITFOR DELAY '00:00:05' EXEC sp_configure 'max server memory', 2147483647
EXEC ('RECONFIGURE' )
GO end
最新文章
- js如何求一组数中的极值
- 编译可供C#调用的C/C++动态链接库dll文件
- NOIP 考前 Tarjan复习
- MSSQL数据库中Text类型字段在PHP中被截断之解 (转)
- ios auto layout demystified (一)
- 基于MySQL协议的数据库中间层项目Atlas - 360团队
- Java基础知识强化之集合框架笔记50:Map集合之Map集合的概述和特点
- 查看Android系统当前运行的activity
- HttpWatch工具简介及使用技巧(转载)
- 深入探讨 ECMAScript 规范第五版
- 使用getCurrentPosition方法实时获取当前Geolocation信息(赋源码文件)--html5、JavaScript
- fiddler实现手机抓包
- 移动开发的捷径:3种方式轻松创建webapp
- Confluence 6 数据库字符集编码和问题
- 对象何时进入老年代、何时发生full gc
- DevExpress GridView 整理(转)
- Network-Emulator Network-Emulator-Toolkit网络模拟器使用详细介绍
- Poj2296
- Java关键字(二)——native
- emulator: ERROR: x86 emulation currently requires hardware acceleration!Please ensure Intel HAXM is properly installed and usable.CPU acceleration status: HAX kernel module is not installed!