How nuo534202/pgcpp works
pgcpp is a C++20 reimplementation of PostgreSQL’s database server and client tools. The main workflow is a client sending SQL to the server, which parses and analyzes it, rewrites views and security policies, plans it, executes it against access methods and storage, then returns results. The tree and README document broader administration, replication, and backup capabilities. Sampled source supports several runtime details, but not every subsystem’s wiring; links for unsampled stages are limited to the architecture and module roles evident in the repository.
Main entry points: postgres.cpp Client protocol · rewrite_handler.cpp Rewrite and RLS · exec_main.cpp Plan executor · psql_client.cpp psql client
Components 21
Server lifecycle
- Server entry
src/server/main.cpp - Postmaster
src/server/postmaster.cpp - Cluster bootstrap
src/server/bootstrap.cpp - Client protocol
src/protocol/postgres.cpp
Query processing
- Parse and analyze
src/parser/analyze.cpp - Rewrite and RLS
src/rewrite/rewrite_handler.cpp - Query planner
src/optimizer/plan/planner.cpp - Plan executor
src/executor/exec_main.cpp - SQL commands
src/commands/tablecmds.cpp
Data and transactions
- System catalog
src/catalog/catalog.cpp - Heap and indexes
src/access/heap/heapam.cpp - Buffer manager
src/storage/buffer/bufmgr.cpp - Database files
src/storage/smgr/md.cpp - Transactions and WAL
src/transaction/xact.cpp
Operations and replication
- Replication
src/replication/logical.cpp - Apply worker
src/replication/worker.cpp
Client tools
- psql client
src/tools/psql_client.cpp - Admin utilities
tools/createdb/createdb.cpp - Dump and restore
tools/pg_dump/pg_dump.cpp - Base backup
tools/pg_basebackup/pg_basebackup.cpp
Other components
- SQL user
Connections 20
- SQL user → psql client: enters SQL
- psql client → Client protocol: sends query
- Server entry → Cluster bootstrap: dispatches bootstrap
- Server entry → Postmaster: starts server
- psql client → Client protocol: receives results
- Client protocol → Parse and analyze: dispatches SQL
- Parse and analyze → Rewrite and RLS: passes query
- Rewrite and RLS → Query planner: passes rewritten query
- Rewrite and RLS → System catalog: looks up views
- Query planner → Plan executor: creates plan
- Plan executor → Heap and indexes: runs scans
- Plan executor → SQL commands: dispatches utility
- Heap and indexes → Buffer manager: reads and writes pages
- Buffer manager → Database files: reads and writes blocks
- Transactions and WAL → System catalog: records transactional state
- Transactions and WAL → Replication: supplies WAL
- Replication → Apply worker: manages workers
- Admin utilities → Client protocol: issues commands
- Dump and restore → Client protocol: queries database
- Base backup → Client protocol: requests backup