Confio sql server writelog wait

9
Tuning for SQL Server WRITELOG Wait Types Confio Software 08/24/2022 1

description

When a SQL Server session waits on the WRITELOG wait type, it is waiting to write the contents of the log cache to disk where the transaction log is stored. When sessions are found waiting on the WRITELOG wait type, it's critical to understand the root cause of the issue to ensure that you solve the correct problem.

Transcript of Confio sql server writelog wait

Page 1: Confio sql server writelog wait

04/10/2023 1

Tuning for SQL Server WRITELOG Wait Types

Confio Software

Page 2: Confio sql server writelog wait

04/10/2023 2

What causes WRITELOG waits?

• SQL Server session waits to write contents of log cache to disk where the transaction log is stored– A session starts a transaction that will perform several INSERT

statements. While the data is being inserted, two actions occur:• Data page in buffer cache is updated with new data• Data written to log cache (segment of memory used to record data

that will be used for rolling back the transaction or be written to the log file)

– Process continues until transaction completes (commits) – Data in log cache is immediately written to physical log file– When SQL Server is in act of flushing log cache to disk, session

will wait on WRITELOG

Page 3: Confio sql server writelog wait

04/10/2023 3

How to find root cause of WRITELOG waits

• Review Perfmon data for signs of disk bottlenecks where the transaction log is stored:– Check PhysicalDisk Object

• Avg. Disk Queue Length: the average number of IO requests that were queued. If this is consistently greater than 1, this could indicate a disk bottleneck

• Avg. Disk sec/Read and Avg. Disk sec/Write: if either of these is higher than 15-20 ms, this could indicate the transaction log is stored on a slow device

– Check SQLServer: Buffer Manager• Checkpoint pages/sec: number of pages flushed by checkpoint operations that

require all dirty buffers to be written to disk

– Optionally, use a tool such as Confio Ignite for SQL Server to determine the top SQL statements waiting on the WRITELOG event• If many statements are waiting, it may indicate that one of the above issues is

causing the wait• If only a few SQL statements are waiting, it may indicate inefficient use of

transactions

Page 4: Confio sql server writelog wait

04/10/2023 4

Tuning for WRITELOG Waits

• Is it really disk subsystem performance?– Some documentation suggests that WRITELOG waits are solely a

disk subsystem issue—investigate thoroughly as this might not be the real cause!

– Important to be certain this is the issue before tuning for WRITELOG waits

• If disks are the problem:– Counters from the PhysicalDisk Object in Perfmon will be high – Common fixes for this include:

• Adding additional IO bandwidth to the disk subsystem where the transaction log is stored

• Moving non-transaction log IO from the disk• Moving the transaction log to a less busy disk• Reducing the size of the transaction log has also helped in some cases

Page 5: Confio sql server writelog wait

04/10/2023 5

Another possible cause: committing data too often

• Excessive WRITELOG waits can also be caused by an overzealous use of transactions (committing data too often)

• Two examples to consider…

Page 6: Confio sql server writelog wait

04/10/2023 6

Another possible cause: committing data too often (cont)

• Code Example 1: – Inserts 100,000 rows – Executed in 418 seconds and waited 410 seconds on WRITELOG– Note COMMIT statement is inside the loop and executed 100,000

times

Page 7: Confio sql server writelog wait

04/10/2023 7

Another possible cause: committing data too often (cont)

• Code Example 2: – Inserts 100,000 rows as in Example 1– Executed in 3 seconds and waited less than a second on WRITELOG – Note COMMIT statement is outside the loop and only executed once

Page 8: Confio sql server writelog wait

04/10/2023 8

Wrapping up

• If sessions are waiting on WRITELOG waits:– Perform a full analysis of the situation– Review disk performance data– Review query statements found waiting on

WRITELOG– Be sure you’re solving the correct problem, not

just adding expensive hardware that will not fix the root cause!

Page 9: Confio sql server writelog wait

04/10/2023 9

With Confio Ignite, You Find Root Cause of Waits Quickly

• Improve database performance by 65% with Confio Ignite– Installs in minutes– Puts no load on monitored servers– Identify bottlenecks and root causes of blocks like

these in minutes

Download Ignite trial for freewww.confio.com/freetrial