All Products
Search
Document Center

AnalyticDB:pg_buffercache

Last Updated:Mar 28, 2026

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.

Note

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

Note

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
 ...
ColumnTypeDescription
relnametextName of the table or index occupying space in the shared buffer
percentage_in_shared_bufferfloat4Percentage of the shared buffer occupied by this relation
pages_in_shared_bufferint8Number 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
...
ColumnTypeDescription
relnametextName of the table or index
percentage_in_shared_bufferfloat4Average 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
ColumnTypeDescription
pages_in_useint8Number of pages currently occupied in the shared buffer
pages_marked_dirtyint8Pages modified in the buffer but not yet written back to disk — indicates write activity and pending I/O workload
pages_totalint8Maximum 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)
ColumnTypeDescription
relnametextName of the table or index
total_pagesint8Total number of pages in the database for this relation
pages_in_shared_bufferint8Number 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.