Troubleshooting·PostgreSQL
PostgreSQL Promotion and Timelines
pg_promote() turns a standby into a primary in seconds. It also increments the timeline, and that number is PostgreSQL recording that two histories have now diverged and cannot be recombined.
Replication Guide 30 of 47 Advanced
- OSUbuntu 26.04 LTS
- PostgreSQL18.6-0ubuntu0.26.04.1
- ReplicationPhysical streaming, async, with slots
- TimeAbout 16 min
pg_promote() is a SQL function and needs no shell access, unlike pg_ctl promote. Both do the same thing.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| db-a01 | 192.168.0.81 | Ubuntu 26.04 LTS | Primary / Source / Replica Set Member 1 | 2 Core | 4 GB | 50 GB |
| db-b01 | 192.168.0.82 | Ubuntu 26.04 LTS | Standby / Replica / Replica Set Member 2 | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when a standby has to become a primary. This matters because promotion itself takes seconds - and it starts a new timeline, which is what stops the old primary and the new one being interchangeable afterwards.
- promoting the standby, and watching
pg_is_in_recovery()change - reading the timelines on each server afterwards
- understanding what a new timeline means for everything downstream
Before you start
- A streaming standby you are willing to detach permanently.
-
Promote the standby
-
Read the timelines and understand what just happened