Re: [Patch] add new parameter to pg_replication_origin_session_setup
Doruk Yilmaz <doruk@mixrank.com>
From: Doruk Yilmaz <doruk@mixrank.com>
To: Amit Kapila <amit.kapila16@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2025-08-11T17:11:34Z
Lists: pgsql-hackers
On Mon, Aug 11, 2025 at 9:44 AM Amit Kapila <amit.kapila16@gmail.com> wrote: > How do you advance the origin? Did you use > pg_replication_origin_advance()? If so, you should be aware that it > can be used for initial setup; see comment in that API code... No, we don't use pg_replication_origin_advance(). We use pg_replication_origin_xact_setup() instead as I mentioned before. Each worker does the following: 1. Sets up its own replication-origin session with pg_replication_origin_session_setup() (using the master process PID). 2. Applies changes inside transactions. 3. Right before commit, calls pg_replication_origin_xact_setup(lsn, commit_timestamp). 4. Commits only if everything succeeded, so the origin only advances on a real commit. That way, the origin LSN moves forward only when the transaction is actually committed. If something fails or the process crashes, the origin stays at the last successful commit, and on restart we replay from the correct spot. It's safer than advancing the origin without knowing the transaction made it to disk. So the issue you described is not relevant for our implementation.
Commits
-
Refactor replorigin_session_setup() for better readability.
- 735e8fe68535 19 (unreleased) landed
-
Prevent unintended dropping of active replication origins.
- e385a4e2fd8e 19 (unreleased) landed
-
Add optional pid parameter to pg_replication_origin_session_setup().
- 5b148706c5c8 19 (unreleased) landed