Book Image

PostgreSQL 13 Cookbook

By : Vallarapu Naga Avinash Kumar
Book Image

PostgreSQL 13 Cookbook

By: Vallarapu Naga Avinash Kumar

Overview of this book

PostgreSQL has become the most advanced open source database on the market. This book follows a step-by-step approach, guiding you effectively in deploying PostgreSQL in production environments. The book starts with an introduction to PostgreSQL and its architecture. You’ll cover common and not-so-common challenges faced while designing and managing the database. Next, the book focuses on backup and recovery strategies to ensure your database is steady and achieves optimal performance. Throughout the book, you’ll address key challenges such as maintaining reliability, data integrity, a fault-tolerant environment, a robust feature set, extensibility, consistency, and authentication. Moving ahead, you’ll learn how to manage a PostgreSQL cluster and explore replication features for high availability. Later chapters will assist you in building a secure PostgreSQL server, along with covering recipes for encrypting data in motion and data at rest. Finally, you’ll not only discover how to tune your database for optimal performance but also understand ways to monitor and manage maintenance activities, before learning how to perform PostgreSQL upgrades during downtime. By the end of this book, you’ll be well-versed with the essential PostgreSQL 13 features to build enterprise relational databases.
Table of Contents (14 chapters)
12
About Packt

Warming up the cache using pg_prewarm

Upon the restart of a database cluster, it may take some time to load the whole of the cache into the PostgreSQL buffer cache or the OS buffer cache. Sometimes, we may wish to load certain tables into the cache on-demand before performing some special reporting tasks. To help cache a table or a specific set of pages to either the OS cache or the database buffer cache (shared buffers), there exists an extension called pg_prewarm.

pg_prewarm is a function that can take five arguments:

pg_prewarm(regclass, mode text default 'buffer', fork text default 'main',
first_block int8 default null, last_block int8 default null) RETURNS int8

Let's discuss each of these arguments in detail:

  • regclass: Fully qualified table name (schemaname.tablename).
  • mode: You can choose any of the three prewarming methods:
    • prefetch: Asynchronous prefetch requests to the OS. Cached in the OS.
    • read: Synchronous prefetch. Cached in the OS.
    • buffer: Reads...