HeadlinesBriefing favicon HeadlinesBriefing.com

Understanding PostgreSQL Internals: Database Clusters and OID Architecture

Hacker News •
×

Developer Burak Sen documents his exploration of PostgreSQL internals, sharing technical insights about how database clusters organize tables and system catalogs. The deep dive examines both logical and physical storage structures, providing hands-on examples with PostgreSQL 18.

Sen clarifies that a PostgreSQL database cluster refers to multiple databases managed by a single instance, not distributed server nodes. Each database uses OID (unsigned integer identifiers) for object tracking, with built-in objects like template1 holding hardcoded values while user objects start at OID 16384. System catalogs store metadata as regular tables, enabling direct query access.

The physical structure centers on the PGDATA directory containing base subdirectories for each database, WAL logs, and cluster-wide catalogs. Files within base/{OID} represent tables and indexes using relfilenode identifiers. Sen demonstrates this by creating a shop database and examining how PostgreSQL creates directories named after their OIDs.

OID generation evolved significantly: PostgreSQL versions through 8.0 assigned OIDs automatically to all rows, 8.1 through 11 made it opt-in, and PostgreSQL 12+ removed the feature entirely. This architectural evolution reflects the system's ongoing optimization for modern workloads while maintaining backward compatibility.