sqlserver内存、会话、连接查询
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
sqlserver内存、会话、连接查询的更多相关文章
- SQLServer数据库之连接查询
SQLServer数据库之连接查询 表的连接查询的几种方法介绍: inner join on内连接,left join on 左连接 , rigth join on 右连接, full join on ...
- SQLServer多表连接查询
双表内部连接查询 select wName,dName from DepartMent,Worker where DepartMent.dID=Worker.did select wName,dNam ...
- SQL多表连接查询以及mysql数据库、sqlserver数据库常见不同点
mysql数据库表及数据准备语句: USE test; DROP TABLE IF EXISTS `teacher_table`; DROP TABLE IF EXISTS `student_tabl ...
- 图解SQLSERVER联合查询和连接查询的区别
相信很多人都会用SQLSERVER联合查询和连接查询,但是用起来不一定都得心应手,对于其中的原理可能就模糊不清了,要想很牢固地掌握和运用SQL联合查询和连接查询机制,必须对其根本原理有很清晰认识, ...
- SQLServer SQL连接查询深度探险(摘录
SQL连接查询深度探险[摘录] 测试环境: Windows XP Profession MySQL 5.0.45 Oracle 9i DB2 UDB 9.1 测试的SQL脚本如下:此脚本适合MySQL ...
- 11-04 SQLserver基础--连接查询、联合查询、索引
一.子查询补充: Exists的用法: select*from haha where exists(select*from bumen where bumen.code=haha.bumen,and ...
- SQLServer连接查询之Cross Apply和Outer Apply的区别及用法
https://blog.csdn.net/wikey_zhang/article/details/77480118 先简单了解下cross apply的语法以及会产生什么样的结果集吧! 示例表: S ...
- SQLserver基础--连接查询、联合查询、索引
一.子查询补充: Exists的用法:select*from haha where exists(select*from bumen where bumen.code=haha.bumen,and b ...
- 010.简单查询、分组统计查询、多表连接查询(sql实例)
-------------------------------------day3------------ --添加多行数据:------INSERT [INTO] 表名 [(列的列表)] --SEL ...
随机推荐
- python爬虫-豆瓣电影的尝试
一.背景介绍 1. 使用工具 Pycharm 2. 安装的第三方库 requests.BeautifulSoup 2.1 如何安装第三方库 File => Settings => Proj ...
- SDK的使用步骤
SDK包括三种类型文件: (1).头文件(.h) (2).库文件(.lib) (3).动态库(.dll) 第一步:在项目目录中新建一个Libs文件夹,再在该文件夹中分别新建inc文件夹和lib文件夹, ...
- Redis--hash类型操作命令
哈希类型hash redis hash 是一个 string 类型的 field 和 value 的映射表,hash 特别适合用于存储对象 哈希类型hash——基本命令 hset /hget /hms ...
- Django model反向关联名称的方法(转)
原文:https://www.jb51.net/article/152825.htm
- MySQL绿色版mysql-5.7.17-winx64简洁安装教程
1.解压MySQL绿色版,复制my-default.ini,修改名称为my.ini 2. 以下为my.ini文件 # For advice on how to change settings plea ...
- C#-Parallel
using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Li ...
- WCF header 域
[OperationContract] [WebInvoke(UriTemplate = "poststr1")] public string poststr1(csinfo cs ...
- 使用swap扩展内存
当系统在内存不够用的时,新建一个swap文件,这个文件可以把内存中暂时不用的传输到对应的swap文件上,相当于扩展了内存的大小,具体使用方法如下: swap文件可以自己选择放在哪里,自己新建一个对应的 ...
- 【转】HTTP响应状态码参考簿
HTTP响应状态码参考簿 http状态返回代码 1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码. http状态返回代码 代码 说明100 (继续) 请求者应当继续提出请求. ...
- lumen中安装及使用redis作为cache
1.安装redis模块在compose.json的require中添加 "predis/predis": "*","illuminate/redi ...