常用Sqlserver中的查詢語句
/* 連線數 */
select connectnum=count(distinct net_address)-1 from master..sysprocesses
/* 返回一組有關計算機和有關 SQL Server 可用資源及其已佔用資源的有用雜項資訊 */
select * from sys.dm_os_sys_info
/* 從作業系統返回記憶體資訊 */
select * from sys.dm_os_sys_memory
/* 返回有關呼叫程式的虛擬地址空間中的頁範圍的資訊 */
select * from sys.dm_os_virtual_address_dump
/* 命令提供了SQL Server的當前記憶體狀態的快照,也可以作為我們分析記憶體瓶頸的重要依據 */
DBCC MemoryStatus
/* 計數器檢視,主要對緩衝區管理器和記憶體管理器的一些計數器進行監控,比如頁面的生存週期、檢查點、惰性寫入器和緩衝命中率等指標 */
select * from sys.dm_os_performance_counters
/* 緩衝池內資料庫緩衝池中各個資料庫的分佈情況 */
select case database_id when 32767 then 'resourceDb' else db_name(database_id) end as database_name,count(*) as cached_pages_count from sys.dm_os_buffer_descriptors group by db_name(database_id),database_id order by cached_pages_count desc;
/* 返回資料和日誌檔案的 I/O 統計資訊 */
select * from sys.dm_io_virtual_file_stats(null,null)
/* 當前快取的哪些批處理或過程佔用了大部分 CPU 資源 */
SELECT TOP 50 SUM(qs.total_worker_time) AS total_cpu_time, SUM(qs.execution_count) AS total_execution_count, COUNT(*) AS number_of_statements, qs.sql_handle FROM sys.dm_exec_query_stats AS qs GROUP BY qs.sql_handle ORDER BY SUM(qs.total_worker_time) DESC
/* 快取計劃所佔用的 CPU 總使用率 */
SELECT total_cpu_time, total_execution_count, number_of_statements, s2.text --(SELECT SUBSTRING(s2.text, statement_start_offset / 2, ((CASE WHEN statement_end_offset = -1 THEN (LEN(CONVERT(NVARCHAR(MAX), s2.text)) * 2) ELSE statement_end_offset END) - statement_start_offset) / 2) ) AS query_text FROM (SELECT TOP 50 SUM(qs.total_worker_time) AS total_cpu_time, SUM(qs.execution_count) AS total_execution_count, COUNT(*) AS number_of_statements, qs.sql_handle --, --MIN(statement_start_offset) AS statement_start_offset, --MAX(statement_end_offset) AS statement_end_offset FROM sys.dm_exec_query_stats AS qs GROUP BY qs.sql_handle ORDER BY SUM(qs.total_worker_time) DESC) AS stats CROSS APPLY sys.dm_exec_sql_text(stats.sql_handle) AS s2
/* CPU 平均佔用率最高的前 50 個 SQL 語句 */
SELECT TOP 50 total_worker_time/execution_count AS [Avg CPU Time], (SELECT SUBSTRING(text,statement_start_offset/2,(CASE WHEN statement_end_offset = -1 then LEN(CONVERT(nvarchar(max), text)) * 2 ELSE statement_end_offset end -statement_start_offset)/2) FROM sys.dm_exec_sql_text(sql_handle)) AS query_text, * FROM sys.dm_exec_query_stats ORDER BY [Avg CPU Time] DESC
/* 檢視 CPU、計劃程式記憶體和緩衝池資訊 */
select cpu_count, hyperthread_ratio, scheduler_count, physical_memory_in_bytes / 1024 / 1024 as physical_memory_mb, virtual_memory_in_bytes / 1024 / 1024 as virtual_memory_mb, bpool_committed * 8 / 1024 as bpool_committed_mb, bpool_commit_target * 8 / 1024 as bpool_target_mb, bpool_visible * 8 / 1024 as bpool_visible_mb from sys.dm_os_sys_info
/* 查詢顯示 SQL 等待分析和前 10 個等待的資源 */
select top 10 * from sys.dm_os_wait_stats --where wait_type not in ('CLR_SEMAPHORE','LAZYWRITER_SLEEP','RESOURCE_QUEUE','SLEEP_TASK','SLEEP_SYSTEMTASK','WAITFOR') order by wait_time_ms desc
/* 計算可執行狀態下的工作程式數量,來觀察CPU壓力 */
SELECT COUNT( * ) as workers_waiting_for_cpu FROM sys.dm_os_workers WHERE o.state = 'RUNNABLE' GROUP BY s.scheduler_id
/* 檢查閂鎖等待統計資訊以確定 I/O 瓶頸 */
select wait_type, waiting_tasks_count, wait_time_ms, signal_wait_time_ms, wait_time_ms / waiting_tasks_count from sys.dm_os_wait_stats where wait_type like 'PAGEIOLATCH%' and waiting_tasks_count > 0 order by wait_type
/* 系統中的每個工作執行緒 */
select * from sys.dm_os_workers
/* 系統中的所有SQLOS工作執行緒 */
select COUNT(*) from sys.dm_os_threads
/* SQL Server 例項中的每個活動任務 */
select * from sys.dm_os_tasks
/* 連線的所有使用者名稱 */
select hostname from master..sysprocesses where hostname <> ' ' group by hostname /* 不同計算機連線的使用者數 */ select count(distinct(hostname)) from master..sysprocesses where hostname <> ' ' /* 所有連線的使用者數 */ select count(hostname) from master..sysprocesses where hostname <> ' '
sp_monitor
sp_who
Select * from master.dbo.spt_monitor
Select * from sys.dm_os_tasks
Select * from master..sysprocesses where hostname <> ' '
Select count(hostname) from master..sysprocesses where hostname <> ' '
Select * from sys.dm_os_tasks
Select connectnum=count(distinct net_address)-1 from master..sysprocesses
Select connectnum=count(distinct net_address)-1 from master..sysprocesses
select * from master.dbo.spt_monitor
相關文章
- Oracle常用的查詢語句Oracle
- mysql dba常用的查詢語句MySql
- postgresql dba常用sql查詢語句SQL
- sqlserver dba常用的sql語句SQLServer
- Oracle常用的系統查詢語句整理Oracle
- MySQL 查詢常用操作(0) —— 查詢語句的執行順序MySql
- (轉)Oracle常用資料字典查詢語句Oracle
- 淺談MySQL中優化sql語句查詢常用的30種方法MySql優化
- MySQL資料庫:7、SQL常用查詢語句MySql資料庫
- SQLServer資料庫管理的常用SQL語句SQLServer資料庫
- Hql查詢語句
- mysql查詢語句MySql
- ElasticSearch 7.X版本19個常用的查詢語句Elasticsearch
- 小覷資料庫(SqlServer)查詢語句執行過程資料庫SQLServer
- hibhibernate中hql中的語句where語句查詢List出現空
- [Mysql 查詢語句]——查詢欄位MySql
- 查詢資料庫中的topsql語句資料庫SQL
- Elasticsearch查詢語句語法Elasticsearch
- MySql常用30種SQL查詢語句優化方法MySql優化
- Sqlserver自動查詢缺失索引及拼出建立索引的語句的指令碼SQLServer索引指令碼
- mysql查詢語句集MySql
- SQL查詢語句 (Oracle)SQLOracle
- MySQL查詢阻塞語句MySql
- SQL server 查詢語句SQLServer
- Hibernate 查詢語句
- oracle查詢語句大全Oracle
- sql查詢語句流程SQL
- SQL mother查詢語句SQL
- Mysql之查詢語句MySql
- mysql查詢語句5:連線查詢MySql
- [Mysql 查詢語句]——分組查詢group byMySql
- [Mysql 查詢語句]——查詢指定記錄MySql
- SQL中查詢語句內的相關應用SQL
- MySQL的簡單查詢語句MySql
- 複雜查詢語句的使用
- SGA區查詢的基本語句
- Mysql常用sql語句(20)- 子查詢重點知識MySql
- ORACLE EBS常用表及查詢語句(最終整理版)Oracle