Leanpub Header

Skip to main content

PostgreSQL Internals Mastery: A Comprehensive Guide

Volume I: Foundations & Core Concepts

"It’s 3 AM, your database just hit 500 connections, and everything has ground to a halt. Do you know why?"

Most database outages aren't mysterious—they are architectural. Stop treating PostgreSQL as a black box and start understanding the mechanical "why" behind the engine. PostgreSQL Internals Mastery: Volume I is a modular deep dive designed for senior engineers who need to bridge the gap between writing SQL and architecting high-performance systems. From the process-per-connection model to the groundbreaking Asynchronous I/O (AIO) features of PostgreSQL 18, learn the internals that separate database architects from administrators. Don't just tune knobs; understand the machine.

Minimum price

$19.00

$29.00

You pay

$29.00

Author earns

$23.20
$

...Or Buy With Credits!

You can get credits with a paid monthly or annual Reader Membership, or you can buy them here.

Buying multiple copies for your team? See below for a discount!

PDF
EPUB
WEB
About

About

About the Book

PostgreSQL Internals Mastery

Volume I: Foundations & Core Concepts

Stop treating PostgreSQL as a black box. Whether you are troubleshooting a production outage at 3 AM or designing a system to handle 10,000 transactions per second, you cannot optimize what you do not understand.

PostgreSQL Internals Mastery is a modular curriculum designed for senior engineers who need to understand the mechanical "why" behind database behavior. This first volume establishes the critical mental model required for all advanced performance tuning and architectural decision-making.

Why a Modular 5-Volume Series?

Traditional database books are often too shallow for experts or too academic for practitioners. By breaking this knowledge into five focused volumes, we allow you to:

  • Master one layer at a time: Focus deeply on foundations before moving to query optimization or high availability.
  • Just-in-time expertise: Buy only the volume you need for your current project or production bottleneck.
  • Stay current: Receive free updates as PostgreSQL 18 and future versions evolve.

What You Will Learn in Volume I

  • The Process Model: Why PostgreSQL uses processes instead of threads and how this impacts connection scaling.
  • Memory Architecture: Mastering the crucial split between shared_buffers and per-process memory like work_mem.
  • Physical Storage: How data lives in 8kB pages and how the system manages Free Space Maps (FSM) and Visibility Maps (VM).
  • MVCC Foundations: The engine behind multi-version concurrency and how snapshots provide isolation without locking readers.
  • PostgreSQL 18 Highlights: Get a first look at the new Asynchronous I/O (AIO) subsystem and how it overlaps disk I/O with computation.

Who This Book Is For

This series is written for database professionals who require an architectural understanding of the engine:

  • Database Administrators responsible for reliability and optimization.
  • Platform Engineers designing infrastructure at scale.
  • Senior Backend Developers needing to understand how code interacts with internals.
  • SREs troubleshooting complex performance stalls.

The Series Roadmap

  • Volume I: Foundations & Core Concepts (Available Now)
  • Volume II: Concurrency & Maintenance (Coming Soon)
  • Volume III: Query Execution & Optimization
  • Volume IV: Indexes & Advanced Topics
  • Volume V: Case Studies & Real Scenarios

Share this book

Installments completed

6 / 6

Team Discounts

Team Discounts

Get a team discount on this book!

  • Up to 3 members

    Minimum price
    $47.00
    Suggested price
    $72.00
  • Up to 5 members

    Minimum price
    $76.00
    Suggested price
    $116.00
  • Up to 10 members

    Minimum price
    $133.00
    Suggested price
    $203.00
  • Up to 15 members

    Minimum price
    $190.00
    Suggested price
    $290.00
  • Up to 25 members

    Minimum price
    $285.00
    Suggested price
    $435.00

Author

About the Author

Giovanni Martinez

Giovanni Martinez is a database professional with over a decade of experience navigating the complexities of high-concurrency environments. His journey began in the trenches as a Database Administrator (DBA), where he developed a deep respect for the mechanical realities of data storage and the "3 AM" outages that occur when those realities are ignored.


Over the last 10+ years, Giovanni has evolved his practice to specialize in DevOps and database management, focusing on how automated pipelines and intelligent tooling can prevent architectural failures before they reach production. He is the creator and lead maintainer of IQtoolkit.ai, an open-source project dedicated to bringing intelligent troubleshooting and management tools to the database ecosystem.


In PostgreSQL Internals Mastery, Giovanni distills his 10+ years of experience into a practical guide for engineers who want to move beyond "tuning blindly". By focusing on the engine at the process and memory level , he empowers readers to build systems that aren't just theoretically sound, but mechanically resilient.


Giovanni shares his knowledge through:

  • The PostgreSQL Internals Mastery book series
  • The IQtoolkit YouTube channel
  • Technical writing and open-source contributions

Learn more at iqtoolkit.ai

Contents

Table of Contents

Preface: Why This Book Exists

About the Author

Who This Book Is For

How to Use This Book

Volume I: FOUNDATIONS & CORE CONCEPTS

  1. What You’ll Learn
  2. Why This Matters
  3. How to Read Part I

Chapter 1: PostgreSQL Architecture at a Glance

  1. Overview
  2. The Cost of Wrong Assumptions
  3. 1.1 The PostgreSQL Process Model
  4. 1.2 Memory Architecture
  5. 1.3 Data Flow from Query to Disk
  6. 1.4 Why Understanding Architecture Changes Everything
  7. 1.5 Asynchronous I/O (AIO) Overview (PostgreSQL 18)
  8. Learning Objectives
  9. Exercises
  10. References & Diagnostics

Chapter 2: Transaction Model & ACID Fundamentals

  1. Overview
  2. 2.1 What ACID Really Means in PostgreSQL
  3. 2.2 Transaction Lifecycle
  4. 2.3 The Write-Ahead Log (Preview)
  5. 2.4 Atomicity in Practice
  6. 2.5 Consistency: Business Logic’s Job
  7. 2.6 Real-World Scenario: Race Condition at 3 AM
  8. 2.7 Choosing Your Isolation Level
  9. Learning Objectives
  10. Exercises
  11. References & Diagnostics
  12. Bridge to Chapter 3 – Isolation Levels

Chapter 3: Isolation Levels & Snapshot Isolation

  1. Overview
  2. 3.1 The Four Isolation Levels
  3. 3.2 Read Committed (The Default Isolation Level)
  4. 3.3 Repeatable Read (Snapshot Isolation)
  5. 3.4 Serializable (SSI)
  6. 3.5 Decision Framework
  7. 3.6 Case Study: Payment System Gone Wrong
  8. 3.7 Practical Patterns and Anti-Patterns
  9. Exercises
  10. References & Diagnostics
  11. Bridge to Chapter 4 – MVCC

Chapter 4: MVCC – The Core Concept

  1. Overview
  2. 4.1 Why PostgreSQL Never Locks Readers
  3. 4.2 Transaction Identifiers (XID)
  4. 4.3 Tuple Structure: xmin, xmax, and Hint Bits
  5. 4.4 The Visibility Algorithm
  6. 4.5 The Cost of MVCC
  7. 4.6 Vacuum, Pruning, and the Visibility Map
  8. 4.7 MVCC vs Other Concurrency Models
  9. 4.8 Practical Implications
  10. 4.9 Case Study: The Runaway Bloat Incident
  11. Learning Objectives
  12. Exercises
  13. References & Diagnostics
  14. Bridge to Chapter 5 – Storage & Pages

Chapter 5: Storage & Pages

  1. Overview
  2. 5.1 The Page: PostgreSQL’s Fundamental Unit
  3. 5.2 Page Internal Layout
  4. 5.3 Row Organization Within Pages: The ctid
  5. 5.4 Free Space Management: FSM and VM
  6. 5.5 TOAST: For Values That Don’t Fit
  7. 5.6 Files and Forks
  8. 5.7 Fillfactor and Page Packing Strategy
  9. 5.8 Asynchronous I/O in the Storage Stack (v18)
  10. 5.9 Case Study: The Page-Split Performance Cliff
  11. Exercises
  12. Bridge to Chapter 6
  13. References

Chapter 6: Buffer Cache – The Speed Layer

  1. 6.1 The Buffer Cache Concept
  2. 6.2 Shared Buffers and Double Buffering
  3. 6.3 Anatomy of a Buffer
  4. 6.4 Lifecycle: Hit, Miss, Read, Dirty
  5. 6.5 Eviction: Clock Sweep (LRU Approximation)
  6. 6.6 Dirty Pages, WAL, and Checkpoints
  7. 6.7 Measuring Cache Effectiveness
  8. 6.8 Sizing Strategy
  9. 6.9 Cache Warming
  10. 6.10 Operational Pitfalls
  11. 6.11 Case Study: The Oversized Cache
  12. 6.12 Diagnostics Checklist
  13. Exercises
  14. Conclusion
  15. Looking Ahead: Bridging to Volume 2

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub