Learn Labs
Foundations

Architecture

Client/server model, processes, clusters, databases, schemas

With Postgres running from Docker & Setup, it's worth being precise about what's actually listening on the other end of that connection before writing any SQL.

Client / server model

Postgres is a client/server database: a single long-running server process (the postmaster) listens on port 5432 and accepts connections. Critically, the postmaster doesn't handle queries itself — for every new connection, it forks a dedicated backend process to serve that one client for the lifetime of the connection.

Clientpsql, a driver, a pooler
Postmasterlistens on :5432, never runs queries
Backend Processforked per connection, runs this client's queries

This is different from thread-per-connection designs. One process per connection is simple and gives strong isolation (one backend crashing doesn't take down the server), but process creation is comparatively expensive — which is why a high connection count becomes a real cost, not just a number. That tradeoff is exactly why connection poolers like PgBouncer exist; see Scaling & Pooling.

Database cluster, databases, schemas, tables

The term database cluster in Postgres does not mean a group of machines — it means the entire collection of databases managed by one running Postgres server instance, all living under one data directory on disk (/var/lib/postgresql/data in this repo's container).

Inside a cluster:

  • A database is an isolated namespace — connections attach to exactly one database at a time, and by default databases can't query across each other.
  • A schema is a namespace inside a database — a way to group tables without needing separate databases. Every database starts with a public schema, and objects created without specifying a schema go there by default.
  • A table lives inside a schema, addressed as schema_name.table_name (or just table_name if it's in your search_path, which defaults to including public).
Database Clusterone data directory, one postmaster
Database"learning" — isolated, no cross-database queries
Schema"public" by default
Tablesales.orders
CREATE SCHEMA sales;
CREATE TABLE sales.orders (id serial PRIMARY KEY);

-- fully qualified
SELECT * FROM sales.orders;

OLTP, again

This process-per-connection, cluster/database/schema/table structure exists to serve the OLTP workload Postgres is built for: many concurrent clients, each doing small, isolated units of work against a shared, structured dataset.

Next: SQL Basics — creating that structure and putting rows into it.

On this page