How does PostgreSQL actually work
summary
PostgreSQL is about 880,000 lines of code (≈730k C) and processes a query by passing the SQL string from psql through libpq protocol messages (Q, T, D, Z), parsing with flex/bison into a parse tree, doing name/type resolution, expanding views/rules, and feeding the planner which chooses a concrete plan (e.g. hash join, hash aggregate, sort) based on statistics and cost parameters. The executor pulls tuples through access methods (heap/index), heap updates write new tuples and emit WAL/xlog records that get fsynced on commit; use tcpdump/wireshark, EXPLAIN/ANALYZE and pg_filedump to inspect behavior.
AI-written summary · about
chapters (16)
- 0:00Intro
- 1:55query
- 8:42frontend/backend protocol
- 12:01lexical analysis
- 13:40parsing
- 14:01parse tree
- 15:29parse analysis
- 16:41rewriting
- 18:03planning/optimizing
- 19:09plan tree
- 22:31execution
- 27:06access methods
- 29:17function/operator calls
- 35:14WAL logging
- 37:53the pieces of PostgreSQL
- 43:37storage management








