Analyzing buffer cache contents

In this recipe, we will be discussing how to analyze the content that resides in PostgreSQL shared buffers.

Getting ready

To analyze the shared buffer contents, PostgreSQL provides an extension called pg_buffercache, and we also use the CREATE EXTENSION command. This extension reports the buffer details such as which relation holds the number of buffers in the memory, what buffers are dirty at this moment, and what is a specific buffer's usage count.

In PostgreSQL, shared buffers are not specific to any database as they are managed at cluster level. Hence, while querying the pg_buffercache we may get relation details that are from other databases too. Also, it is not recommended to query the pg_buffercache too frequently ...

Get PostgreSQL High Performance Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.