diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index 370c2b9a4f..5086775646 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -1885,11 +1885,13 @@ HandleNotifyInterrupt(void) /* * ProcessNotifyInterrupt * - * This is called just after waiting for a frontend command. If a - * interrupt arrives (via HandleNotifyInterrupt()) while reading, the - * read will be interrupted via the process's latch, and this routine - * will get called. If we are truly idle (ie, *not* inside a transaction - * block), process the incoming notifies. + * This is called if we see notifyInterruptPending set, just before + * transmitting ReadyForQuery at the end of a frontend command, and + * also if a notify signal occurs while reading from the frontend. + * HandleNotifyInterrupt() will cause the read to be interrupted + * via the process's latch, and this routine will get called. + * If we are truly idle (ie, *not* inside a transaction block), + * process the incoming notifies. */ void ProcessNotifyInterrupt(void) diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index d7a72c0766..3b85e48333 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -4194,7 +4194,18 @@ PostgresMain(int argc, char *argv[], } else { + /* Send out notify signals and transmit self-notifies */ ProcessCompletedNotifies(); + + /* + * Also process incoming notifies, if any. This is mostly to + * ensure stable behavior in tests: if any notifies were + * received during the just-finished transaction, they'll be + * seen by the client before ReadyForQuery is. + */ + if (notifyInterruptPending) + ProcessNotifyInterrupt(); + pgstat_report_stat(false); set_ps_display("idle", false);