Buffer cache statistics
Job details
Name: |
Buffer cache statistics |
Platform: |
Postgres |
Category: |
Performance |
Description: |
Gets data cache statistics from pg_stat_database view. |
Long description: |
Task gets data cache statistic from pg_stat_database view (columns: blks_read and blks_hit). |
Version: |
1.3 |
Default schedule: |
4,14,24,34,44,54 * * * |
Requires engine install: |
Yes |
Compatibility tag: |
.[type=‘instance’ & databasetype=‘postgres’]/.[hasengine=‘YES’ & is_awsrds = ‘0′ & newer_than_ninefour = 1] |
Parameters
Name |
Default value |
Description |
keep data for |
7 |
Number of days to provide statistics for. |
Job Summary
- Purpose: The Buffer Cache Statistics job is primarily intended to gather and analyze statistics regarding buffer cache performance in a PostgreSQL database, focusing particularly on the blocks read from the disk versus those hits found directly in the buffer cache.
- Why: This monitoring task is critical to understanding the efficiency of the data caching mechanism of PostgreSQL. By analyzing buffer cache hits and disk reads, database administrators can make informed decisions on how to optimize performance, manage resources effectively, and potentially decrease query response times, which is crucial for performance-intensive environments.
- Manual checking: You can manually check these statistics in PostgreSQL by querying the “pg_stat_database” view in the pg_catalog schema. The relevant columns for this task would be “blks_read” for disk reads and “blks_hit” for buffer cache hits:
SELECT sum(blks_read), sum(blks_hit) FROM pg_catalog.pg_stat_database;
Implementation Details
- This job uses several custom functions and tables for storing and processing cache statistics data. For instance, “dbw_buffer_cache_stat_fn”, a PL/pgSQL function, performs the main data collection and analysis.
- The job also involves data manipulation operations, such as inserting data into custom history and aggregation tables, thereby enabling the tracking over specified periods and computation of averages, maximums, and minimums.
- The SQL logic used in this job involves complex queries for managing historical data, which is structured to retain granularity while also providing aggregated views to analyze trends and patterns.
Dependencies and Structures
- Dependency Objects:
- PostgreSQL view: “pg_catalog.pg_stat_database”
- PostgreSQL functions: “dbw_buffer_cache_stat_fn(integer)”, “dbw_data_hit_ratio_histr”, “dbw_data_hit_ratio_aggr”, and “dbw_data_cache_last”.
- Tables Created:
- “dbw_data_cache_last” for storing the latest counter values,
- “dbw_data_hit_ratio_histr” for historical individual hit ratios,
- “dbw_data_hit_ratio_aggr” for aggregated ratio data over different periods.
- Cleanup Policies:
- The job includes mechanisms to clean up data entries beyond a defined retention period (configured by the “keep data for” parameter).
Scheduled Reporting and Visualization
- The job is automatically scheduled to run at defined intervals, capturing data cache performance metrics at these times.
- A rich set of reporting templates and visual presentations is included to help with data interpretation. Charts and graphs are used to represent data cache hit ratios and logical reads, both historically and in aggregated forms such as averages, maximums, and minimums over differing times of the day and overall.
- The reports cover various aspects, including:
- Comparison of data cache hit ratio (showing blocks served from cache versus those read from disk),
- Logical reads (indicative of querying activity and disk load),
- Special focus segments such as “working hours” for enhanced business relevance.
Importance
- By providing detailed insights into buffer cache utilization, the job helps in proactive database health monitoring and can guide capacity planning and performance optimization efforts. This is particularly beneficial in environments where database performance is critical to the business operations.
In conclusion, the Buffer Cache Statistics job within the dbWatch Control Center is a comprehensive monitoring and analytical tool tailored for PostgreSQL databases, designed to enhance understanding and management of data caching efficiency.