From a8b6fd65a9e2eeb11a92a61c6e75ae618ae8f55e Mon Sep 17 00:00:00 2001 From: sav-maya Date: Thu, 20 Aug 2026 13:26:53 -0700 Subject: [PATCH] Fix remaining PostgreSQL reference bugs Make temporal, upgrade, and replication examples runnable without omitted dependencies or misleading worker rows. --- .../references/logical-replication.md | 5 ++++- .../references/major-version-upgrades.md | 5 ++++- skills/postgres-best-practices/references/schema-design.md | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/skills/postgres-best-practices/references/logical-replication.md b/skills/postgres-best-practices/references/logical-replication.md index fbbc32b..d0cd7bf 100644 --- a/skills/postgres-best-practices/references/logical-replication.md +++ b/skills/postgres-best-practices/references/logical-replication.md @@ -382,7 +382,10 @@ SELECT now() - st.latest_end_time AS time_lag FROM pg_subscription s JOIN pg_stat_subscription st ON st.subid = s.oid -WHERE st.pid IS NOT NULL; +WHERE st.pid IS NOT NULL + AND st.relid IS NULL + -- PG17+ can also expose parallel apply workers; keep only the leader. + AND coalesce(to_jsonb(st)->>'worker_type', 'apply') = 'apply'; ``` ## Schema Changes During Replication diff --git a/skills/postgres-best-practices/references/major-version-upgrades.md b/skills/postgres-best-practices/references/major-version-upgrades.md index 2a678bc..523d135 100644 --- a/skills/postgres-best-practices/references/major-version-upgrades.md +++ b/skills/postgres-best-practices/references/major-version-upgrades.md @@ -226,8 +226,11 @@ Never upgrade production first. Test on a copy: # Create a test copy pg_basebackup -D /tmp/upgrade_test -Fp -Xs -P +# Initialize an empty target cluster with the new version's binaries +/usr/lib/postgresql/17/bin/initdb -D /tmp/new_cluster + # Run pg_upgrade --check against the copy -pg_upgrade --check \ +/usr/lib/postgresql/17/bin/pg_upgrade --check \ --old-datadir /tmp/upgrade_test \ --new-datadir /tmp/new_cluster \ --old-bindir /usr/lib/postgresql/16/bin \ diff --git a/skills/postgres-best-practices/references/schema-design.md b/skills/postgres-best-practices/references/schema-design.md index 001935e..e60af7a 100644 --- a/skills/postgres-best-practices/references/schema-design.md +++ b/skills/postgres-best-practices/references/schema-design.md @@ -173,6 +173,8 @@ This prevents overlapping bookings for the same room at the database level. PG18 adds built-in temporal constraint support, simplifying the exclusion constraint pattern above: ```sql +CREATE EXTENSION IF NOT EXISTS btree_gist; + CREATE TABLE room_bookings ( room_id int NOT NULL, during tstzrange NOT NULL,