Author: Noah Misch Commit: Noah Misch [not for commit] Demonstrate 035_standby_logical_decoding.pl hang. There are three way XLOG_RUNNING_XACTS can show up: - SELECT pg_log_standby_snapshot() - CHECKPOINT - bgwriter LOG_SNAPSHOT_INTERVAL_MS An idle primary won't do the second two. If you're unlucky enough for all three to happen before CREATE_REPLICATION_SLOT's DecodingContextFindStartpoint() call starts watching, then CREATE_REPLICATION_SLOT will hang indefinitely. diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c index f11ce27..07f987c 100644 --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -70,7 +70,7 @@ int BgWriterDelay = 200; * Interval in which standby snapshots are logged into the WAL stream, in * milliseconds. */ -#define LOG_SNAPSHOT_INTERVAL_MS 15000 +#define LOG_SNAPSHOT_INTERVAL_MS 1 /* * LSN and timestamp at which we last issued a LogStandbySnapshot(), to avoid diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c index 9270d7b..0f170a4 100644 --- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c +++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c @@ -1085,6 +1085,7 @@ libpqrcv_create_slot(WalReceiverConn *conn, const char *slotname, appendStringInfoString(&cmd, " PHYSICAL RESERVE_WAL"); } + pg_usleep(1000 * 1000); res = libpqrcv_PQexec(conn->streamConn, cmd.data); pfree(cmd.data); diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl index cebfa52..c371369 100644 --- a/src/test/recovery/t/035_standby_logical_decoding.pl +++ b/src/test/recovery/t/035_standby_logical_decoding.pl @@ -467,6 +467,7 @@ $psql_subscriber{run}->pump_nb(); # Speed up the subscription creation $node_primary->safe_psql('postgres', "SELECT pg_log_standby_snapshot()"); +$node_primary->safe_psql('postgres', "CHECKPOINT"); # Explicitly shut down psql instance gracefully - to avoid hangs # or worse on windows