常用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
相關文章
- mysql dba常用的查詢語句MySql
- sqlserver dba常用的sql語句SQLServer
- postgresql dba常用sql查詢語句SQL
- Oracle常用的系統查詢語句整理Oracle
- MySQL 查詢常用操作(0) —— 查詢語句的執行順序MySql
- MySQL資料庫:7、SQL常用查詢語句MySql資料庫
- ElasticSearch 7.X版本19個常用的查詢語句Elasticsearch
- mysql查詢語句MySql
- Sqlserver自動查詢缺失索引及拼出建立索引的語句的指令碼SQLServer索引指令碼
- MySql常用30種SQL查詢語句優化方法MySql優化
- Mysql之查詢語句MySql
- sql查詢語句流程SQL
- SQL mother查詢語句SQL
- SQL查詢語句 (Oracle)SQLOracle
- mysql查詢語句集MySql
- mysql查詢語句5:連線查詢MySql
- MySQL的簡單查詢語句MySql
- Mysql常用sql語句(20)- 子查詢重點知識MySql
- 使用sql語句查詢平均值,使用sql語句查詢資料總條數, not in 篩選語句的使用SQL
- 資料庫查詢語句資料庫
- mysql高階查詢語句MySql
- 多表查詢建表語句
- Laravel 子查詢語句用法Laravel
- ORACLE 資料庫 查詢語句與DML語句Oracle資料庫
- mysql查詢效率慢的SQL語句MySql
- MongoDB 常用查詢語法MongoDB
- 史上最全:PostgreSQL DBA常用SQL查詢語句(建議收藏學習)SQL
- MySQL內連線查詢語句MySql
- ORACLE結構化查詢語句Oracle
- hisql ORM 查詢語句使用教程SQLORM
- SqlServer中迴圈和條件語句SQLServer
- 在mysql查詢效率慢的SQL語句MySql
- 一條查詢語句的執行流程
- MySQL語句第二高的薪水查詢MySql
- Laravel 框架查詢執行的 SQL 語句Laravel框架SQL
- SQL基礎的查詢語句烈鉍SQL
- oracle查詢語句查詢增加一列內容Oracle
- 找到Oracle資料庫中效能最差的查詢語句BSOracle資料庫
- mysql常見的查詢語句的應用MySql