Lazy writer and Checkpoint statistics
Job details
Name: |
Lazy writer and Checkpoint statistics |
Platform: |
Sqlserver |
Category: |
Performance |
Description: |
Monitors ‘Checkpoint pages/sec’, ‘Lazy writes/sec’ and ‘Page life expectancy’ by extracting counter values from the sys.dm_os_performance_counters performance table. |
Long description: |
Lazy writer purpose is to release the buffer pool memory. When more memory is needed, lazy writer responds to a memory pressure releasing the “coldest” pages from the buffer pool, and makes more memory available for new pages to come in. |
Version: |
1.3 |
Default schedule: |
4,14,24,34,44,54 * * * |
Requires engine install: |
Yes |
Compatibility tag: |
.[type=‘instance’ & databasetype=‘sqlserver’]/instance[maj_version > ‘2005′ & hasengine=‘YES’ & (engine_edition = ‘Microsoft SQL Server’ |
engine_edition = ‘Azure SQL Managed Instance’)] |
Parameters
Name |
Default value |
Description |
keep data for |
10 |
Number of days to provide statistics for. |
keep aggregated statistics for |
360 |
Removes aggregate statistics older than this threshold (in days) from the tables dbw_lazy_writer_aggr and dbw_page_life_exp_aggr. |
Job Summary
- Purpose: The purpose of this job is to monitor SQL Server performance with a focus on Lazy Writes, Checkpoints, and Page Life Expectancy using the sys.dm_os_performance_counters system view.
- Why: This job is crucial for ensuring SQL Server’s performance and efficiency. Monitoring these metrics:
- Checkpoints contribute to database availability by shortening data file recovery times, which aligns closely with the frequency of transactions logged.
- Lazy Writes manage memory allocation effectively by releasing memory pages that are least frequently accessed.
- Page Life Expectancy (PLE) indicates how long data pages can stay in the buffer pool without being accessed, which assists in identifying memory pressure and helps in performance tuning.
- Manual checking: To manually check these metrics, execute the following SQL command:
SELECT cntr_value, object_name FROM sys.dm_os_performance_counters WHERE counter_name IN ('Checkpoint pages/sec', 'Lazy writes/sec', 'Page life expectancy');
Database and Job Configuration
- Database type & versions: SQL Server instances or Azure SQL Managed Instances, specifically versions newer than SQL Server 2005.
- Frequency of execution: This job is scheduled to run automatically at ten-minute intervals throughout the day.
Key Counters Monitored
- “Checkpoint pages/sec” — Tracks the rate at which checkpoint pages are written.
- “Lazy writes/sec” — Monitors the rate at which buffers are written out by the lazy writer.
- “Page life expectancy” — Measures the time in seconds a data page is expected to stay in the buffer pool without referencing.
Data Tables and Procedure Implementation
- Tables:
- “dbw_lazy_writer_last” — Stores the most recent values of Lazy Writes, Checkpoints, and PLE.
- “dbw_lazy_writer_histr” — Historical data of the above metrics for trend analysis.
- “dbw_lazy_writer_aggr” and “dbw_page_life_exp_aggr” — Aggregate and track statistical minimum, maximum, and average values over configurable timeframes.
- Procedures:
- “dbw_lazy_writer_proc” — Main procedure incorporating several operational and conditional logic to retrieve, calculate, store, and manage life cycle of data involving Lazy Writes, Checkpoints, and PLE.
Upgrades and Maintenance
- Version handling: Capable of transitioning smoothly through various upgrade paths, ensuring data consistency and adding new functionalities without interrupting existing setups.
- Error handling: Incorporates comprehensive error management within stored procedures to capture and log issues effectively.
Reporting and Visualization
- Custom presentations and reports are generated to display historical trends and aggregated data, providing clear insights into performance over different periods (night, work, evening hours).
- Graphical representations:
- Checkpoint and Lazy Writes performance across various parts of the day.
- Page Life Expectancy segmentation to understand duration-specific occurrences and potential anomalies in memory handling.
Conclusion
This monitoring job is essential for database administrators to ensure SQL Server’s optimal performance and stability, particularly in environments where high availability and efficient memory management are crucial.