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

select db_id, db_name, blocks_fetched_total, blocks_hit_total, histr_date from dbw_buffer_cache_reads_last;

Job Components

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

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.