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.
Syllabus
Why PostgreSQL, and getting it running
The architecture, processes and WAL, running it in Docker, psql survival skills, and the configuration that actually matters.
02Schema design and data types
Choosing types that prevent bugs, constraints, enums, JSONB, arrays,
generated columns and migration safety.
Querying in depth
Joins, CTEs, window functions, filtered aggregates, upserts, RETURNING,
and full-text search.
Indexes
B-tree, GIN, GiST, BRIN; partial, covering and expression indexes; column order; and when an index makes things worse.
05EXPLAIN and the planner
Reading a plan, scan and join types, estimate versus actual, statistics, and the six patterns behind most slow queries.
06MVCC, vacuum and operations
Row versions, isolation levels, locks, bloat, connection pooling, backups, replication and a production checklist.
The architecture you should carry around
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.
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);
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
| Component | Version | Note |
|---|---|---|
| PostgreSQL | 16 | Everything applies to 14+; newer features are flagged |
| Client | psql | DBeaver or pgAdmin work too, but learn psql |
| Local install | Docker | One command, disposable, matches production |
| Migrations | Flyway | Same tool used in the Spring Boot course |
| Extensions | pg_stat_statements, pg_trgm, citext | Enabled in chapter 1 |