liveBook · Manning

What you will learn in PostgreSQL Mistakes and How to Avoid Them

by Jimmy Angelakos
Foreword by Gianni Ciolli

Chapter by chapter

Chapter 1: Why PostgreSQL matters—and why talking about mistakes does too

1.1 Why learning about PostgreSQL matters · 1.2 Why talking about PostgreSQL mistakes matters · 1.3 What you will learn · 1.4 Typical kinds of PostgreSQL mistakes · 1.4.1 Coming with expectations from other databases · 1.4.2 Misunderstanding PostgreSQL · 1.4.3 Misunderstanding the documentation · 1.4.4 Using relics from the SQL Standard · 1.4.5 Not following best practices · 1.5 How this book works · 1.5.1 Mental models · 1.5.2 Example mistake · 1.6 Sample database: Frogge Emporium · 1.7 Summary

What you learn in chapter 1 →

Chapter 2: Bad SQL usage

2.1 Using NOT IN to exclude · 2.1.1 Performance implications · 2.1.2 Alternative · 2.2 Selecting ranges with BETWEEN · 2.3 Not using CTEs · 2.4 Using uppercase identifiers · 2.5 Dividing INTEGERs · 2.6 COUNTing NULL values · 2.7 Querying indexed columns with expressions · 2.8 Upserting NULLs in a composite unique key · 2.9 Selecting and fetching all the data · 2.10 Not taking advantage of checkers/linters or large language models · 2.10.1 Code checkers/linters · 2.10.2 Large language models · 2.11 Summary

What you learn in chapter 2 →

Chapter 3: Improper data type usage

3.1 TIMESTAMP (WITHOUT TIME ZONE) · 3.2 TIME WITH TIME ZONE · 3.3 CURRENT_TIME · 3.4 CHAR(n) · 3.5 VARCHAR(n) · 3.6 MONEY · 3.7 SERIAL data type · 3.8 XML · 3.9 Summary

What you learn in chapter 3 →

Chapter 4: Table and index mistakes

4.1 Table inheritance · 4.2 Neglecting table partitioning · 4.3 Partitioning by multiple keys · 4.4 Using the wrong index type · 4.5 Summary

What you learn in chapter 4 →

Chapter 5: Improper feature usage

5.1 Selecting SQL_ASCII as the encoding · 5.2 CREATE RULE · 5.3 Relational JSON · 5.4 Putting UUIDs everywhere · 5.5 Homemade multi-master replication · 5.6 Homemade distributed systems · 5.7 Summary

What you learn in chapter 5 →

Chapter 6: Performance bad practices

6.1 Default configuration in production · 6.2 Improper memory allocation · 6.3 Having too many connections · 6.4 Having idle connections · 6.4.1 What is MVCC? · 6.4.2 The problem with idle connections · 6.5 Allowing long-running transactions · 6.5.1 Idle in transaction · 6.5.2 Long-running queries in general · 6.6 High transaction rate · 6.6.1 XID wraparound · 6.6.2 Burning through lots of XIDs · 6.7 Turning off autovacuum/autoanalyze · 6.8 Not using EXPLAIN (ANALYZE) · 6.9 Locking explicitly · 6.10 Having no indexes · 6.11 Having unused indexes · 6.12 Removing indexes used elsewhere · 6.13 Summary

What you learn in chapter 6 →

Chapter 7: Administration bad practices

7.1 Not tracking disk usage · 7.1.1 Deleting the Write-Ahead Log · 7.1.2 What can eat up your disk space? · 7.1.3 What can you do? · 7.2 Logging to PGDATA · 7.3 Ignoring the logs · 7.3.1 Bad configuration · 7.3.2 Performance issues · 7.3.3 Locks · 7.3.4 Corruption · 7.3.5 Security · 7.4 Not monitoring the database · 7.5 No tracking of statistics over time · 7.6 Not upgrading Postgres · 7.7 Not upgrading your system · 7.8 Summary

What you learn in chapter 7 →

Chapter 8: Security bad practices

8.1 Specifying psql -W or - -password · 8.2 Setting listen_addresses = '*' · 8.3 trust-ing in pg_hba.conf · 8.4 Database owned by a superuser · 8.5 Setting SECURITY DEFINER carelessly · 8.6 Choosing an insecure search path · 8.7 Summary

What you learn in chapter 8 →

Chapter 9: High availability bad practices

9.1 Not taking backups · 9.2 No Point-in-Time Recovery · 9.3 Backing up manually · 9.4 Not testing backups · 9.5 Not having redundancy · 9.6 Using no HA tool · 9.7 Summary

What you learn in chapter 9 →

Chapter 10: Upgrade/migration bad practices

10.1 Not reading all release notes · 10.2 Performing inadequate testing · 10.3 Succumbing to encoding chaos · 10.4 Not using proper BOOLEANs · 10.5 Mishandling differences in data types · 10.6 Summary

What you learn in chapter 10 →

Chapter 11: PostgreSQL, best practices, and you: Final insights

11.1 What type of user are you? · 11.1.1 The dabbler · 11.1.2 The cautious steward · 11.1.3 The oblivious coder · 11.1.4 The freefaller · 11.2 Be proactive: Act early · 11.3 All right, so you inherited a bad database · 11.3.1 “Historical reasons” · 11.3.2 What now? · 11.3.3 First things first · 11.4 Treat Postgres well, and it will treat you well · 11.5 Summary

What you learn in chapter 11 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.