diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 79fe26a9325..ae4580ea7e1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -46,6 +46,7 @@ #include "pgstat.h" #include "postmaster/autovacuum.h" #include "postmaster/bgworker_internals.h" +#include "postmaster/bgwriter.h" #include "postmaster/interrupt.h" #include "storage/bufmgr.h" #include "storage/lmgr.h" @@ -685,6 +686,12 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy, StartTransactionCommand(); } + /* + * REPRO: Request chckpointer to wakeup to ensure xl_running_xacts exists + * before the PRUNE_ON_ACCESS + */ + RequestCheckpoint(CHECKPOINT_FORCE | CHECKPOINT_WAIT); + if ((params->options & VACOPT_VACUUM) && !(params->options & VACOPT_SKIP_DATABASE_STATS)) { diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index a1d4768623f..7ad4e61ed8c 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1570,6 +1570,12 @@ InvalidatePossiblyObsoleteSlot(ReplicationSlotInvalidationCause cause, break; } + /* + * REPRO: wait sometime to avoid slot invalidation before the logical + * walsender decodes xl_running_xacts and catalog_xmin is advanced. + */ + sleep(2); + /* * Check if the slot needs to be invalidated. If it needs to be * invalidated, and is not currently acquired, acquire it and mark it diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl index 4eca17885d6..71a18891d44 100644 --- a/src/test/recovery/t/035_standby_logical_decoding.pl +++ b/src/test/recovery/t/035_standby_logical_decoding.pl @@ -267,6 +267,11 @@ sub wait_until_vacuum_can_remove "SELECT (select pg_snapshot_xmin(pg_current_snapshot())::text::int - $xid_horizon) > 0" ) or die "new snapshot does not have a newer horizon"; + # REPRO: do CHECKPOINT and wait sometime to generate xl_running_xacts + # records + $node_primary->safe_psql('testdb', qq[CHECKPOINT]); + sleep(20); + # Launch the vacuum command and insert into flush_wal (see CREATE # TABLE flush_wal for the reason). $node_primary->safe_psql(