diff options
author | Daniel Gustafsson <dgustafsson@postgresql.org> | 2023-07-04 17:36:13 +0200 |
---|---|---|
committer | Daniel Gustafsson <dgustafsson@postgresql.org> | 2023-07-04 17:36:13 +0200 |
commit | 48efb2302bea3b2af8b4bb865edcc70132ee4250 (patch) | |
tree | a8a46c0ec38a78ce7fe0d4caf2a77116e373e1de /src | |
parent | 4b4798e1384ce12e19a558708e66c829276cf8d7 (diff) |
Fix assertion failure in snapshot building
Clear any potential stale next_phase_at value from the snapshot
builder which otherwise may trip an assertion check ensuring
that there is no next_phase_at value.
This can be reproduced by running 80 concurrent sessions like
the below where $c is a loop counter (assumes there has been
1..$c databases created) :
echo "
CREATE TABLE replication_example(id SERIAL PRIMARY KEY,
somedata int,
text varchar(120));
SELECT 'init' FROM
pg_create_logical_replication_slot('regression_slot_$c',
'test_decoding');
SELECT data FROM
pg_logical_slot_get_changes('regression_slot_$c', NULL,
NULL, 'include-xids', '0',
'skip-empty-xacts', '1');
" | psql -d regress_$c >>psql.log &
Backpatch down to v16.
Bug: #17695
Author: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Alexander Lakhin <exclusion@gmail.com>
Reported-by: bowenshi <zxwsbg@qq.com>
Discussion: https://postgr.es/m/17695-6be9277c9295985f@postgresql.org
Backpatch-through: v16
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/replication/logical/snapbuild.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index e403feeccda..843ceba840b 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -1955,8 +1955,12 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn) if (TransactionIdPrecedes(ondisk.builder.xmin, builder->initial_xmin_horizon)) goto snapshot_not_interesting; - /* consistent snapshots have no next phase */ + /* + * Consistent snapshots have no next phase. Reset next_phase_at as it is + * possible that an old value may remain. + */ Assert(ondisk.builder.next_phase_at == InvalidTransactionId); + builder->next_phase_at = InvalidTransactionId; /* ok, we think the snapshot is sensible, copy over everything important */ builder->xmin = ondisk.builder.xmin; |