Where is My Memory? (Postgres Edition)
summary
A deliberately buggy external storage extension shows blob reads polluting shared buffers (shared_buffers ~128 MB, total shared memory ~143 MB) and a backend RSS jumping from ~151 MB to ~223 MB when large files are read. Diagnosis uses pg_buffercache views plus real‑time tracing with memleak (eBPF) and visualized with flame graphs to find arena_mmap/arena_malloc allocations done outside palloc and a missing memory-context free; changing to palloc and fixing context deletion resolves the leaks.
AI-written summary · about
chapters (17)
- 0:00Introduction to memory tracking
- 0:27Postgres memory components primer
- 3:42Demo setup with buggy extension
- 5:10Shared buffers cache demonstration
- 8:45Shared buffers pollution issue
- 9:49Monitoring backend memory usage
- 10:52Memory context hierarchy overview
- 11:40External file storage operations
- 13:03Undetected memory allocation leak
- 14:31Debugging with memleak tool
- 16:16Visualizing leak data with flame graphs
- 18:30Root cause analysis of leak
- 19:32Fixing memory allocation calls
- 20:13Post-fix memory context check
- 20:54Memory context leak detection
- 21:37Debugging unscoped memory context
- 22:20Summary and key takeaways
related talks
45mEnhancing PostgreSQL Plasticity: New Frontiers in Memory Management
50mInside PostgreSQL Shared Memory
48mPractical Memory Tuning for PostgreSQL
39mPostgreSQL: Page Buffer Overview
33mFinding and fixing a data-corruption bug...
32mDesigning and implementing a monitoring feature in PostgreSQL
56mPostgreSQL at low Level: stay curious!
31mAll in a context!
