Skip to content

Commit a4e7571

Browse files
authored
fix: correct the LSN stuff for pg replication (#162)
1 parent 28ce6c3 commit a4e7571

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pgserver/logrepl/replication.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ func (r *LogicalReplicator) StartReplication(sqlCtx *sql.Context, slotName strin
255255
// The StatusUpdate message wants us to respond with the current position in the WAL + 1:
256256
// https://www.postgresql.org/docs/current/protocol-replication.html
257257
err := pglogrepl.SendStandbyStatusUpdate(context.Background(), primaryConn, pglogrepl.StandbyStatusUpdate{
258-
WALWritePosition: state.lastWrittenLSN + 1,
258+
WALWritePosition: state.lastReceivedLSN + 1,
259259
WALFlushPosition: state.lastWrittenLSN + 1,
260-
WALApplyPosition: state.lastReceivedLSN + 1,
260+
WALApplyPosition: state.lastWrittenLSN + 1,
261261
})
262262
if err != nil {
263263
return handleErrWithRetry(err, false)
@@ -862,8 +862,8 @@ func (r *LogicalReplicator) commitOngoingTxn(state *replicationState, flushReaso
862862
return err
863863
}
864864

865-
r.logger.Debugf("Writing LSN %s\n", state.currentTransactionLSN)
866-
if err = r.writeWALPosition(state.replicaCtx, state.slotName, state.currentTransactionLSN); err != nil {
865+
r.logger.Debugf("Writing LSN %s\n", state.lastCommitLSN)
866+
if err = r.writeWALPosition(state.replicaCtx, state.slotName, state.lastCommitLSN); err != nil {
867867
return err
868868
}
869869

0 commit comments

Comments
 (0)