diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2015-04-23 21:25:44 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2015-04-23 21:39:35 +0300 |
commit | 2c47fe16a709e01dea403643a1ff4d00c8c8c1ad (patch) | |
tree | c1f4503b5893d911411665ad8f0e1ff8a2dd7a3b /src | |
parent | 2aa0fb032ecdc5624a3706a2db0a7ca42bbaf211 (diff) | |
download | postgresql-2c47fe16a709e01dea403643a1ff4d00c8c8c1ad.tar.gz postgresql-2c47fe16a709e01dea403643a1ff4d00c8c8c1ad.zip |
Fix deadlock at startup, if max_prepared_transactions is too small.
When the startup process recovers transactions by scanning pg_twophase
directory, it should clear MyLockedGxact after it's done processing each
transaction. Like we do during normal operation, at PREPARE TRANSACTION.
Otherwise, if the startup process exits due to an error, it will try to
clear the locking_backend field of the last recovered transaction. That's
usually harmless, but if the error happens in MarkAsPreparing, while
holding TwoPhaseStateLock, the shmem-exit hook will try to acquire
TwoPhaseStateLock again, and deadlock with itself.
This fixes bug #13128 reported by Grant McAlister. The bug was introduced
by commit bb38fb0d, so backpatch to all supported versions like that
commit.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/access/transam/twophase.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index b85a666ca1c..3ac339bebfc 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -2054,6 +2054,12 @@ RecoverPreparedTransactions(void) if (InHotStandby) StandbyReleaseLockTree(xid, hdr->nsubxacts, subxids); + /* + * We're done with recovering this transaction. Clear MyLockedGxact, + * like we do in PrepareTransaction() during normal operation. + */ + PostPrepare_Twophase(); + pfree(buf); } } |