Benutzer:MovGP0/SQL/Query Performance Metrics

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Query Performance Metrics

[Bearbeiten | Quelltext bearbeiten]

Extended Events

[Bearbeiten | Quelltext bearbeiten]

Predefined Templates

[Bearbeiten | Quelltext bearbeiten]
Predefined Templates
Query Batch Sampling queries and procedure calls for 20% of all active sessions
Query Batch Tracking all queries and procedures on the server
Query Detail Sampling set of events from queries and procedure calls for 20% of all active sessions
Query Detail Tracking set of events from all queries and procedures on the server
Query Wait Statistic wait statistics of queries and procedure calls for 20% of all active sessions

What to capture

[Bearbeiten | Quelltext bearbeiten]
  • CPU utilization
  • Memory usage
  • I/O activity
  • Execution time
  • Query frequency
  • Errors and warnings
Important Events
Category Event Description
Execution rpc_completed remote procedure call completion event (OLDBC)
Execution sp_statement_completed remote procedure call statement completion event
Execution sql_batch_completed batch of T-SQL statements completed
Execution sql_statement_completed single T-SQL statement completed
Session loginlogout user connects and disconnects
Session existing_connection current number of user connections
Errors attention termination of request (caused by query cancellation, connection loss, timeout, etc.)
Errors error_reported
Errors execution_warning warnings during execution of a query or stored procedure
Errors hash_warning error in an hashing operation
Warnings missing_column_statistics statistics required by the query optimizer is missing
Warnings missing_join_predicate query is executed without joining predicate between them
Warnings sort_warnings sort operation that does not fit into memory
lock lock_deadlock process becomes deadlock victim
lock lock_deadlock_chain chain of queries creating the deadlock
lock lock_timeout lock has exceeded the timeout parameter
execution sql_statement_recompile execution plan had to be recompiled because it did not exist
execution rpc_starting starting of a stored procedure
execution query_post_compilation_showplan execution plan after compilation
execution query_post_execution_showplan execution plan and query statistics (capturing is resource intensive)
transaction sql_transaction informations about transactions (including time of start, stop, and rollback)
Important Fields
  • client_app_name
  • database_id
  • plan_handle
  • query hash
  • query_plan_hash
  • session_id
  • transaction_id

Creating an Session

[Bearbeiten | Quelltext bearbeiten]

SQL Server Manager

[Bearbeiten | Quelltext bearbeiten]
  • Extended Events
  • right click on Sessions
  • New Session/New Session Wizard
Create Session
CREATE EVENT SESSION
Activate session
ALTER EVENT
Get active sessions
SELECT dxs.name, dxs.create_date
FROM sys.dm_xe_sessions AS dxs
Stop Session
ALTER EVENT SESSION [Query Performance Metric]
ON SERVER
STATE = STOP;
  • Set max file size properly (default is 1GB; increase as needed; typically 50 GB)
  • Avoid debug events (halting SQL Server on error for debugger)
  • avoid use of No_Event_Loss (performance drain)
SELECT TOP(100) *
FROM sys.dm_exec_query_stats AS res
OUTER APPLY sys.dm_exec_sql_text(res.sql_handle) -- resolve handle
OUTER APPLY sys.dm_exec_query_plan(res.plan_handle) -- resolve query plan