Buffer cache reads per database
Job details
Name: |
Buffer cache reads per database |
Platform: |
Postgres |
Category: |
Performance |
Description: |
Collects the number of block fetch requests for table or index per database. |
Long description: |
Collects the number of block fetch requests and hits for table or index using the pg_stat_get_blocks_fetched and pg_stat_get_db_blocks_hit functions. The statistics are collected per database. |
Version: |
1.3 |
Default schedule: |
1,11,21,31,41,51 * * * |
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 |
The number of days to keep the data for. |
Job Summary
- Purpose: The purpose of this job is to monitor and collect statistics on the number of block fetch requests and hits for each table or index across all databases in a PostgreSQL instance. It helps in assessing the performance related to buffer cache usage.
- Why: This job is important to ensure efficient database operations by analyzing buffer cache read patterns, identifying potential caching issues, and providing insights for performance tuning.
- Manual checking: You can check this manually in the database by issuing these SQL commands:
select db_id, db_name, blocks_fetched_total, blocks_hit_total, histr_date from dbw_buffer_cache_reads_last;
Job Components
- Task Name: Buffer cache reads per database
- Object: dbw_buffer_cache_reads_fn
- Description: Collects the number of block fetch requests for table or index per database.
- Long Description: Collects the number of block fetch requests and hits for table or index using specific PostgreSQL statistics functions. Detailed information logged includes total and individual statistics archived per database.
- Version: 1.3
- Company: dbwatch.no
- Category: Performance
Job Dependencies
Dependency Object |
Type |
Description |
dbw_buffer_cache_reads_fn(integer) |
Function |
Primary function invoked for executing task. |
dbw_buffer_cache_reads_histr_tab |
Table |
Archives historical data of buffer cache reads. |
dbw_buffer_cache_reads_last |
Table |
Stores the most recent buffer cache read data. |
dbw_buffer_cache_reads_rank_1h_view |
View |
Supports ranking databases based on 1-hour read statistics. |
dbw_buffer_cache_reads_rank_24h_view |
View |
Supports ranking databases based on 24-hour read statistics. |
Implementation
-- SQL Statements for initializing schema objects --
create table dbw_buffer_cache_reads_last (
db_id bigint,
db_name varchar(256),
blocks_fetched_total bigint,
blocks_hit_total bigint,
histr_date timestamp
);
create table dbw_buffer_cache_reads_histr_tab (
db_id bigint,
db_name varchar(256),
blocks_fetched_total bigint,
blocks_fetched bigint,
blocks_hit_total bigint,
blocks_hit bigint,
period bigint,
histr_date timestamp
);
create view dbw_buffer_cache_reads_rank_1h_view as
select db_name, sum(blocks_fetched) as blocks_fetched
from dbw_buffer_cache_reads_histr_tab
where histr_date > (now() - cast('1 hour' as interval))
group by db_name
order by blocks_fetched desc;
create view dbw_buffer_cache_reads_rank_24h_view as
select db_name, sum(blocks_fetched) as blocks_fetched
from dbw_buffer_cache_reads_histr_tab
where histr_date > (now() - cast('24 hours' as interval))
group by db_name
order by blocks_fetched desc;
-- PostgreSQL Function for collecting and processing buffer cache reads --
CREATE OR REPLACE FUNCTION dbw_buffer_cache_reads_fn(taskId int) ...
Reporting
- Report Title: Disk block hitrate
- Description: This report assesses the efficiency of disk block requests, focusing on the hit rate, which is crucial for database performance.
Segment |
Detail |
Buffer Cache Reads |
Displays a graph showing buffer cache read statistics for the top 5 databases over the most recent hour. |
Buffer Cache Hit Ratio |
Visualizes the hit ratio for buffer caches correlating to databases with high activity levels. |
Total Buffer Cache Reads |
Provides aggregated data of buffer cache reads/sec across all databases. |
Each visualization and dataset derived are aimed at providing clear, actionable insights into the performance of the buffer cache system within a PostgreSQL environment.