Database Design & PostgreSQL

Database Design and PostgreSQL

Beyond basic SELECT: relational modeling, normalization, real PostgreSQL data types and schema implementation, advanced querying, transactions and concurrency, indexing, and operational safety.

advanced14 lessons6 modules9h total

Helpful before you begin (optional -- you can start this course now): Git, APIs & SQL

Who it's for

Developers who already know basic SQL (SELECT, JOIN, INSERT/UPDATE/DELETE, GROUP BY) and want to design real schemas, understand PostgreSQL-specific behavior, and operate a production database safely.

What you'll be able to do

  • Model a domain into entities, relationships, cardinality, and optionality before writing any SQL
  • Normalize a schema to Third Normal Form, and justify a deliberate denormalization tradeoff
  • Implement a normalized PostgreSQL schema with correct types, constraints, and dependency-ordered DDL
  • Write joins, subqueries, CTEs, and window functions, and explain PostgreSQL's transaction and isolation guarantees
  • Add useful indexes, read EXPLAIN output, and design least-privileged roles
  • Write ordered, safe schema migrations and describe a real backup/recovery plan

Not started — 14 lessons, no account required.

Start this course

Practice this course →Add to a study plan →Interview questions

Relational modeling

Entities, attributes, relationships, keys, and constraints.

  1. Relational Modeling: Entities, Attributes, and Relationships

    Turning a real-world domain into entities, attributes, and relationships — and the cardinality/optionality questions that decide how those relationships are actually implemented.

    19 min
  2. Primary Keys, Foreign Keys, and Constraints

    The identity guarantee a primary key provides, the referential-integrity guarantee a foreign key enforces, and the natural-vs-surrogate key decision every table forces you to make.

    20 min

Normalized schema design

Functional dependencies, First through Third Normal Form, and denormalization tradeoffs.

  1. Normalization: First and Second Normal Form

    Functional dependencies as the underlying idea behind normalization, and the first two normal forms — eliminating repeating groups, then eliminating partial dependency on a composite key.

    21 min
  2. Third Normal Form and Denormalization Tradeoffs

    Eliminating dependency on a non-key column, and the honest, deliberate cases where denormalizing a schema is the right engineering call, not a mistake.

    20 min

PostgreSQL schema implementation

Real PostgreSQL data types, DDL, and dependency-ordered table creation and seed data.

  1. PostgreSQL Data Types and DDL

    Choosing the right PostgreSQL column type for a value — including the types SQLite doesn't distinguish at all — and the DDL that defines a table.

    20 min
  2. Implementing a Normalized Schema in PostgreSQL

    Turning a relational model into real DDL with correctly-ordered CREATE TABLE statements, relationships, constraints, and seed data — and doing it for real, on your own machine.

    22 min

Advanced querying

Multi-table joins and aggregation, subqueries and CTEs, and window functions.

  1. Joins and Aggregation, Beyond the Basics

    Going past the SELECT/JOIN/GROUP BY fundamentals from the SQL module: multi-table joins, HAVING vs. WHERE, and aggregate functions that hold up in both SQLite and PostgreSQL.

    20 min
  2. Subqueries and Common Table Expressions

    Nesting a query inside another to answer a question a single flat query can't, and CTEs — the readable, nameable alternative for anything beyond a trivial subquery.

    20 min
  3. Window Functions: Calculations Across Rows Without Collapsing Them

    The one capability GROUP BY fundamentally can't offer — a per-row calculation that sees other rows in its group without collapsing the result down to one row per group.

    21 min

Transactions and performance

ACID guarantees, concurrent-update anomalies and isolation levels, and indexes and query plans.

  1. Transactions and ACID Guarantees

    Grouping several statements into one all-or-nothing unit, and the four ACID properties that make a transaction a genuine guarantee rather than a convention.

    20 min
  2. Concurrent-Update Problems and Isolation Levels

    The specific anomalies that happen when two transactions overlap in time, and how PostgreSQL's isolation levels trade off which of those anomalies each one still permits.

    22 min
  3. Indexes, Composite Indexes, and Reading EXPLAIN

    How an index turns an O(n) table scan into an O(log n) lookup, when adding one is actually the wrong call, and how to read EXPLAIN to find out instead of guessing.

    22 min

Security and evolution

Views, roles and least privilege, and safe, ordered schema migrations.

  1. Views, Roles, and the Principle of Least Privilege

    Naming a reusable query as a view, and the security discipline of granting every role exactly the access it needs — never more.

    20 min
  2. Migrations, Schema Evolution, and Operational Safety

    Changing a live schema safely with ordered, reversible migrations, testing database behavior deliberately, and the backup/recovery discipline that makes every other guarantee in this course matter.

    23 min