● Course · 6 chapters

The Complete PostgreSQL Tutorial

Written for application developers who already write SQL and now need to own the database: how it stores rows, why the planner chose that plan, which index to reach for, and what breaks at 3 a.m. if you get vacuum wrong.

PostgreSQL 16 psql & Docker JSONB · GIN · MVCC Free · no sign-up
A psql session running EXPLAIN ANALYZE beside a PostgreSQL database with index types

Who this course is for

You can write a JOIN and a GROUP BY. What you have not done is read an execution plan, chosen between a GIN and a B-tree index, or explained why a table grew to 40 GB when it only holds two million rows.

This is the database half of the stack. It pairs directly with the MyBatis course, where you write the SQL that this course teaches you to make fast.

Four-stage roadmap: foundations, querying, performance, operations
Chapters 1–3 suit any developer. Chapters 4–6 are what makes you the person the team asks.

Syllabus

The architecture you should carry around

PostgreSQL architecture: connection, query pipeline, shared memory and background processes over disk
Five layers. Almost every performance question is really a question about one of them.

The running schema

The same order-management schema used across the stack, so the SQL here is the SQL you will map in MyBatis and build a UI over in Angular.

schema.sql (excerpt)
CREATE TYPE order_status AS ENUM
    ('DRAFT','PLACED','PAID','FULFILLED','DELIVERED','CANCELLED','REFUNDED');

CREATE TABLE customer (
    customer_id  bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    email        citext        NOT NULL UNIQUE,
    full_name    text          NOT NULL,
    created_at   timestamptz   NOT NULL DEFAULT now()
);

CREATE TABLE customer_order (
    order_id     bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    customer_id  bigint        NOT NULL REFERENCES customer,
    reference    text          NOT NULL UNIQUE,
    status       order_status  NOT NULL DEFAULT 'DRAFT',
    total_amount numeric(12,2) NOT NULL CHECK (total_amount >= 0),
    metadata     jsonb         NOT NULL DEFAULT '{}',
    version      integer       NOT NULL DEFAULT 0,
    placed_at    timestamptz
);

CREATE INDEX idx_order_customer ON customer_order (customer_id, placed_at DESC);
CREATE INDEX idx_order_open     ON customer_order (placed_at)
                                 WHERE status IN ('PLACED','PAID');
CREATE INDEX idx_order_metadata ON customer_order USING gin (metadata);
Three habits worth adopting immediately

1. timestamptz, never timestamp.
2. numeric for money, never float.
3. text rather than varchar(n) unless the limit is a real business rule — in PostgreSQL they perform identically.

Versions and tools

ComponentVersionNote
PostgreSQL16Everything applies to 14+; newer features are flagged
ClientpsqlDBeaver or pgAdmin work too, but learn psql
Local installDockerOne command, disposable, matches production
MigrationsFlywaySame tool used in the Spring Boot course
Extensionspg_stat_statements, pg_trgm, citextEnabled in chapter 1