SQL Server Performance Issues 1742566449
SQL Server Performance Issues 1742566449
01
SQL SERVER -
PERFORMANCE
TROUBLESHOOTING
MOHAN SAHU
02
INTRODUCTION
Being a SQL server DBA, you will encounter
database performance issues. It's essential
to have a structured process and specific
U
tasks to address these problems. This post
H
SA
outlines steps to help you create a standard
N
A
U
website becomes unresponsive, with error logs
H
SA
showing "Database Timeout" messages. Your phone
starts ringing, and you're surrounded by your
N
A
THE APPROACH
As the only person available on shift with no
access to senior resources, the first and most
important thing is to avoid panic. Staying calm is
crucial in such situations. We can't provide a
U
solution until we follow a systematic approach that
H
SA
will lead us to solution.
A
N
Check the below details on your database-
H
O
Check Blocking/deadlock?
M
CHECK BLOCKING
Using sp_who2 System Stored Procedure-
This procedure provides information about current
SQL Server processes, including blocked processes.
EXEC sp_who2;
Using Dynamic Management Views (DMVs)-
U
H
sys.dm_exec_requests: This DMV shows details of all
SA
running processes, including blocked ones.
N
SELECT session_id, blocking_session_id, wait_type, wait_time,
A
wait_resource FROM sys.dm_exec_requests WHERE blocking_session_id <> 0;
H
CHECK DEADLOCK
Using SQL Server Profiler
Set up a trace to capture deadlock events. Look for
the Deadlock graph event to analyze deadlocks.
U
Using Extended Events
H
SA
Create an Extended Events session to capture
N
deadlock information.
A
H
sqlserver.lock_deadlock
M
RECENT CHANGES
07
U
H
written by the programmer. Additionally, a web developer
SA
could add ad-hoc queries within the code, making you
unaware of any changes to the SQL code.
N
A
Changes to the application's configuration file could
H
U
H
space, the database auto-growth might be disabled
SA
or set to a percentage of the file size instead of a
N
A
fixed amount in megabytes. For instance, if your
H
MULTI APPLICATION
U
H
applications running on it would likely
SA
experience problems. If this isn't the
N
A
NEXT ACTION
If the above approaches are not working or
have already been checked, we can proceed
to investigate further issues:
U
Check the SQL Server error log.
H
SA
Verify when the statistics were last
N
updated.
A
H
O
U
To read a specific error log file, you can specify the log number:
H
SA
EXEC sp_readerrorlog 0, 1, 'Error';
Using SQL Server Configuration Manager-Open SQL Server
N
Configuration Manager->Navigate to the SQL Server Services-
A
H
Error Log Path: Under the "Startup Parameters" tab, you can
M
CHECK STATISTICS
Using T-SQL- View Statistics for a Specific Table
Use the DBCC SHOW_STATISTICS command to view statistics for
a specific table and index.
DBCC SHOW_STATISTICS ('table_name', 'IndexName');
List All Statistics for a Table- Query the sys.stats and
sys.stats_columns system views to list all statistics for a table
U
H
SELECT s.name AS statistics_name, c.name AS column_name, s.auto_created,
SA
s.user_created,s.no_recompute,s.has_filter, s.filter_definition FROM sys.stats AS s
JOIN sys.stats_columns AS sc ON s.stats_id = sc.stats_id JOIN sys.columns AS c ON
sc.column_id = c.column_id AND sc.object_id = c.object_id WHERE s.object_id =
N
OBJECT_ID('TableName');
A
updated.
SELECT object_name(s.object_id) AS table_name,s.name AS
statistics_name,sp.last_updated,sp.rows,sp.rows_sampled,sp.steps,sp.unfiltered_ro
ws FROM sys.stats AS s CROSS APPLY sys.dm_db_stats_properties(s.object_id,
s.stats_id) AS sp WHERE s.object_id = OBJECT_ID('YourTableName');
Using SQL Server Management Studio (SSMS): Connect to your SQL
Server instance->Navigate to the database containing the table you
want to check->Find and expand the table.->Right-click on "Statistics"
and select "Properties" to view details about each statistic.
MOHAN SAHU
13
CHECK REMAINING DETAILS
Check linked severs: Always consider this when
troubleshooting an application's database: you might be
searching for issues on the wrong server. The simplest way
to check for problems with a linked server is to look for
excessive OLEDB wait tasks in the Performance Dashboard
U
report.
H
SA
Check slow disk: For SQL Server to operate properly,
disk access time should be below 30 milliseconds. The
N
quickest way to check this is by opening the SSMS
A
H
FINAL THOUGHTS 14
U
H
Identify Issues: Look for slow queries,
SA
blocking, and hardware limitations.
N
Optimize: Regularly update statistics,
A
H
fragmentation.
Collaborate: Work with other teams to
resolve issues.
By following these steps, you can effectively
manage and improve SQL Server
performance.
MOHAN SAHU
15