The pg_buffercache extension adds monitoring views that show which tables and indexes are cached in the shared buffer and how much buffer space they consume. Use these views to identify hot data, tune buffer allocation, and prevent performance bottlenecks before they affect query latency.
How it works
AnalyticDB for PostgreSQL replaces the standard pg_buffercache views with a set of lock-free views. Each view aggregates raw buffer metadata into readable per-relation statistics, covering both the coordinator node and compute nodes.
All views use the _lockfree suffix. These lock-free tables and indexes are used to prevent impacts on the running of instances and business. If many queries run concurrently, the statistics may include an acceptable margin of error.
Temporary database objects that cannot be identified by name are grouped under others in the results.
Prerequisites
Before you begin, ensure that you have:
An AnalyticDB for PostgreSQL instance running V6.6.2.5 or later (V6.0) or V7.1.0.0 or later (V7.0)
Installed the extension on the Extensions page of the instance
Serverless mode instances do not support pg_buffercache. To check your instance's minor version, see View the minor version of an instance. To upgrade, see UpgradeDBVersion.
Install and uninstall the extension
Install and uninstall pg_buffercache from the Extensions page of your instance. For instructions, see Install, update, and uninstall extensions.
Monitoring views reference
Six lock-free views are available. Four provide cluster-wide statistics; two let you query a specific table or index.
shared_buffer_stat_master_lockfree
Returns cache usage of each table and index on the coordinator node, sorted by buffer occupancy.
SELECT * FROM shared_buffer_stat_master_lockfree;Sample output:
relname | percentage_in_shared_buffer | pages_in_shared_buffer
---------------------------+-----------------------------+------------------------
others | 0.53125 | 85
pg_depend_reference_index | 0.09375 | 15
pg_depend | 0.05625 | 9
...| Column | Type | Description |
|---|---|---|
relname | text | Name of the table or index occupying space in the shared buffer |
percentage_in_shared_buffer | float4 | Percentage of the shared buffer occupied by this relation |
pages_in_shared_buffer | int8 | Number of pages cached in the shared buffer for this relation |
Use this view to identify which tables and indexes dominate the coordinator's buffer pool and whether to adjust the cache allocation policy or data access patterns.
shared_buffer_stat_segments_lockfree
Returns cache usage of each table and index across compute nodes. The percentage_in_shared_buffer value is the average across all compute nodes.
SELECT * FROM shared_buffer_stat_segments_lockfree;Sample output:
relname | percentage_in_shared_buffer
------------------------+-----------------------------
gp_distribution_policy | 0.00625
pg_namespace_oid_index | 0.0125
pg_rewrite | 0.00625
...| Column | Type | Description |
|---|---|---|
relname | text | Name of the table or index |
percentage_in_shared_buffer | float4 | Average percentage of shared buffer occupied across all compute nodes |
shared_buffer_summary_master_lockfree
Returns overall buffer utilization on the coordinator node as a single summary row.
SELECT * FROM shared_buffer_summary_master_lockfree;Sample output:
pages_in_use | pages_marked_dirty | pages_total
--------------+--------------------+-------------
594 | 594 | 16000| Column | Type | Description |
|---|---|---|
pages_in_use | int8 | Number of pages currently occupied in the shared buffer |
pages_marked_dirty | int8 | Pages modified in the buffer but not yet written back to disk — indicates write activity and pending I/O workload |
pages_total | int8 | Maximum number of pages the shared buffer can hold |
shared_buffer_summary_segments_lockfree
Returns overall buffer utilization aggregated across all compute nodes.
SELECT * FROM shared_buffer_summary_segments_lockfree;Sample output:
pages_in_use | pages_marked_dirty | pages_total
--------------+--------------------+-------------
11328 | 11328 | 98304
...The columns are the same as shared_buffer_summary_master_lockfree, but the values represent overall statistics of all compute nodes.
relation_shared_buffer_stat_lockfree
Returns cache hit statistics for a specific table or index.
SELECT * FROM relation_shared_buffer_stat_lockfree('<table or index name>'::regclass);Example:
SELECT * FROM relation_shared_buffer_stat_lockfree('adbpg_autoanalyze_test_table'::regclass);Sample output:
relname | total_pages | pages_in_shared_buffer
------------------------------+-------------+------------------------
adbpg_autoanalyze_test_table | 20055 | 3327
(1 row)| Column | Type | Description |
|---|---|---|
relname | text | Name of the table or index |
total_pages | int8 | Total number of pages in the database for this relation |
pages_in_shared_buffer | int8 | Number of pages currently cached in the shared buffer |
Compare pages_in_shared_buffer against total_pages to estimate the actual cache hit ratio. A low ratio may indicate that the cache allocation policy or data access pattern needs adjustment.
relation_detail_shared_buffer_stat_lockfree
Returns cache statistics for a table and its related indexes and TOAST table in one query.
If you specify a table name, the result includes the table, its indexes, and the associated TOAST table.
If you specify an index name, only the index statistics are returned.
SELECT * FROM relation_detail_shared_buffer_stat_lockfree('<table or index name>'::regclass);Example:
SELECT * FROM relation_detail_shared_buffer_stat_lockfree('adbpg_autoanalyze_test_table'::regclass);Sample output:
relname | total_pages | pages_in_shared_buffer
------------------------------+-------------+------------------------
adbpg_autoanalyze_test_table | 20055 | 3327
(1 row)In this example, 3,327 of 20,055 pages of adbpg_autoanalyze_test_table are cached. If no pages of the related adbpg_autoanalyze_test_table_i_idx index are cached, index-based queries will not benefit from the buffer and may perform poorly.
Use this view when you need a complete picture of how a table's entire object graph (table, indexes, TOAST) is cached — especially before deciding whether to preload data with pg_prewarm.
What's next
To preload frequently accessed tables and indexes into the shared buffer before they are queried, install and use the pg_prewarm extension. This reduces first-access latency caused by cache misses and keeps performance stable after instance restarts or expected traffic pattern changes.
To manage other extensions on your instance, see Install, update, and uninstall extensions.