The practice environment for PostgreSQL: 1,000 Examples by Bi Learner.
You need Docker Desktop, which is free for personal use, and nothing else.
docker run -d --name pg1000-practice \
-p 8888:8888 -p 5432:5432 \
bilearner/postgres1000-practice:1.1Then open http://localhost:8888/lab.
PostgreSQL 16.15 is already running with the book's datasets loaded and all 53 chapter folders waiting. There is nothing to generate, nothing to load, and nothing to configure. First start is a few seconds.
The same image is on GitHub's registry too, if you prefer it or if Docker Hub's anonymous pull limit gets in your way on a shared network:
docker run -d --name pg1000-practice \
-p 8888:8888 -p 5432:5432 \
ghcr.io/bitoollearner/postgres1000-practice:1.1To connect your own client instead — pgAdmin, DBeaver, DataGrip, PyCharm:
| Setting | Value |
|---|---|
| Host | localhost |
| Port | 5432 |
| Database | pg1000 |
| Username | book |
| Password | book |
The book is 1000 worked PostgreSQL examples across 53 chapters. Every one was executed against PostgreSQL 16.15 and its output captured — the printed row counts, sums and execution plans are real, not illustrative.
This repository is the environment those examples run in, so you can work through them on your own machine and get the same answers the book prints.
- The practice image — PostgreSQL 16.15, configured exactly as the book was verified against, with the datasets preloaded and JupyterLab on top.
- 53 chapter notebooks — every example as a problem to solve, with an empty cell under it waiting for your SQL.
- The datasets — the seeded generators, so the figures are reproducible rather than approximate.
- The exact server configuration —
conf/postgresql.conf, copied from the book's own build. Plans depend on these settings; a differentwork_memordefault_statistics_targetproduces a different plan. - A chapter index — all 1000 example titles, so you can find the one you need.
The solutions, explanations, common mistakes, recommendations and pattern insights. Each example in the book carries all of them in a fixed seven-section format, plus a captured execution plan for the advanced tier.
That is the deal: the environment and the problems are free and open, and the answers are what you buy. The notebooks here give you the question and a blank cell — work it out, then check yourself against the book.
Three schemas, each from a seeded generator, so your numbers match the printed ones exactly.
| Schema | Scale | In the image? | Used by |
|---|---|---|---|
ecommerce |
5,000 orders, 14,998 lines | preloaded | most of the book |
hr |
1,200 employees | preloaded | Chapter 49 |
ecommerce_lg |
2,000,000 orders, 6M lines | load on demand | Part VIII |
ecommerce_lg is not baked in because it would add roughly 850 MB to the
image for the one part that needs it. Load it when you reach Part VIII:
docker exec -it pg1000-practice load-large-datasetIndex selection, partition pruning and BRIN cannot be demonstrated on five thousand rows — at that size the planner correctly prefers a sequential scan and every lesson inverts. See docs/DATASETS.md, including the defects the data contains on purpose.
conf/ the server configuration the book was verified against
datasets/ seeded generators and DDL for all three schemas
docs/ setup, datasets, troubleshooting, and the chapter index
notebooks/ 53 chapter notebooks -- problems, not answers
practice-image/ the Dockerfile and entrypoint for the image above
scripts/ environment verification and dataset loading
Part I — Getting Started
-
- PostgreSQL in Context · 5 examples
-
- Your Environment: Docker, psql, PyCharm · 8 examples
-
- The Architecture You Actually Need · 7 examples
Part II — Data Definition and Types
-
- Databases, Schemas and Tables · 14 examples
-
- The Type System: Numbers, Text, Booleans · 20 examples
-
- Dates, Times and Time Zones as Types · 12 examples
-
- Constraints and Data Integrity · 22 examples
-
- Writing Data: INSERT, UPDATE, DELETE, UPSERT · 24 examples
Part III — Querying
-
- SELECT Fundamentals · 22 examples
-
- Filtering and Conditional Logic · 26 examples
-
- String Functions · 28 examples
-
- Numeric and Mathematical Functions · 16 examples
-
- Date and Time Functions · 36 examples
-
- Aggregation and GROUP BY · 38 examples
-
- Advanced Grouping: ROLLUP, CUBE, GROUPING SETS · 12 examples
-
- Joins · 45 examples
Part IV — Composition and Analytics
-
- Subqueries · 18 examples
-
- Common Table Expressions · 20 examples
-
- Recursive CTEs · 12 examples
-
- Window Functions · 60 examples
-
- Analytical Patterns · 28 examples
Part V — Data Modeling
-
- Relational Modeling · 20 examples
-
- Normalization and Denormalization · 16 examples
-
- Dimensional Modeling · 26 examples
-
- Slowly Changing Dimensions · 20 examples
-
- Designing Production Schemas · 15 examples
Part VI — PostgreSQL's Distinctive Types
-
- Arrays · 25 examples
-
- JSON and JSONB · 19 examples
-
- UUID, ENUM, Ranges and Custom Types · 15 examples
Part VII — Objects, Transactions and Programming
-
- Views and Materialized Views · 20 examples
-
- Transactions and Savepoints · 13 examples
-
- MVCC, Isolation and Locking · 14 examples
-
- Functions and Procedures · 22 examples
-
- Triggers and Change Tracking · 13 examples
Part VIII — Performance
-
- Index Fundamentals · 17 examples
-
- Specialized Indexes · 16 examples
-
- Reading Execution Plans · 17 examples
-
- Query Optimization · 16 examples
-
- Partitioning, VACUUM and Maintenance · 20 examples
Part IX — Data Engineering
-
- Loading Data · 17 examples
-
- Incremental Processing and CDC · 18 examples
-
- Dimension and Fact Pipelines · 16 examples
-
- Data Quality and Reconciliation · 14 examples
-
- Orchestration with Python · 14 examples
Part X — Production Operations
-
- Roles, Security and RLS · 13 examples
-
- Backup, Recovery and PITR · 11 examples
-
- Monitoring and System Catalogs · 12 examples
-
- Beyond the Core · 4 examples
Part XI — Capstone Projects
-
- HR and Workforce Analytics · 10 examples
-
- Capstone I - E-Commerce Warehouse · 22 examples
-
- Capstone II - Enterprise ELT · 20 examples
-
- Capstone III - Banking and Fraud · 16 examples
-
- Capstone IV - Event Analytics · 16 examples
| Level | Examples | What it means |
|---|---|---|
| Beginner | 142 | establishes a mechanism; usually one reasonable way to write it |
| Intermediate | 729 | applying it correctly, which is where most real difficulty lives |
| Advanced | 129 | carries a captured EXPLAIN plan and a performance discussion |
You can use any PostgreSQL 13 or later, but the book assumes the container's
configuration and some output will differ. See
docs/SETUP.md. The settings that matter
are in conf/postgresql.conf, and the cluster locale must be C — text sort
order depends on it, and every example that orders mixed-case text will differ
otherwise.
Found a mistake in the book, or an example that does not reproduce? Open an issue. Errata reports are especially welcome and are credited in the next revision.
The code, notebooks, configuration and dataset generators in this repository are MIT licensed — see LICENSE.
The book's text, example solutions and explanations are © Bi Learner and are not covered by that licence.