Skip to content

Commit 0d4c75f

Browse files
committed
Initialize tsId and dbId fields in WAL record of COMMIT PREPARED.
Commit dd428c7 added dbId and tsId to the xl_xact_commit struct but missed that prepared transaction commits reuse that struct. Fix that. Because those fields were left unitialized, replaying a commit prepared WAL record in a hot standby node would fail to remove the relcache init file. That can lead to "could not open file" errors on the standby. Relcache init file only needs to be removed when a system table/index is rewritten in the transaction using two phase commit, so that should be rare in practice. In HEAD, the incorrect dbId/tsId values are also used for filtering in logical replication code, causing the transaction to always be filtered out. Analysis and fix by Andres Freund. Backpatch to 9.0 where hot standby was introduced.
1 parent 9601cb7 commit 0d4c75f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/backend/access/transam/twophase.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,9 +2092,13 @@ RecordTransactionCommitPrepared(TransactionId xid,
20922092

20932093
/* Emit the XLOG commit record */
20942094
xlrec.xid = xid;
2095-
xlrec.crec.xact_time = GetCurrentTimestamp();
2095+
20962096
xlrec.crec.xinfo = initfileinval ? XACT_COMPLETION_UPDATE_RELCACHE_FILE : 0;
2097-
xlrec.crec.nmsgs = 0;
2097+
2098+
xlrec.crec.dbId = MyDatabaseId;
2099+
xlrec.crec.tsId = MyDatabaseTableSpace;
2100+
2101+
xlrec.crec.xact_time = GetCurrentTimestamp();
20982102
xlrec.crec.nrels = nrels;
20992103
xlrec.crec.nsubxacts = nchildren;
21002104
xlrec.crec.nmsgs = ninvalmsgs;

0 commit comments

Comments
 (0)