From bfefa25b210993450d89381ad26b5b77a37091bc Mon Sep 17 00:00:00 2001 From: Martijn van Oosterhout Date: Mon, 3 Jun 2019 17:10:38 +0200 Subject: [PATCH 2/2] Don't notify other backends about notifications without cause. It could be that there are other databases with active listens but unless they need to know because it may be useful to advance the queue tail, there's no point waking them up. --- src/backend/commands/async.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index c1b0705234..bb4f58d0b9 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -1519,11 +1519,13 @@ SignalBackends(void) int count; int i; int32 pid; + int notify_all = false; /* * Identify all backends that are listening and not already up-to-date. We * don't want to send signals while holding the AsyncQueueLock, so we just - * build a list of target PIDs. + * build a list of target PIDs. If we haven't moved to a new page there is + * no point notifying backends of other databases. * * XXX in principle these pallocs could fail, which would be bad. Maybe * preallocate the arrays? But in practice this is only run in trivial @@ -1532,6 +1534,7 @@ SignalBackends(void) pids = (int32 *) palloc(MaxBackends * sizeof(int32)); ids = (BackendId *) palloc(MaxBackends * sizeof(BackendId)); count = 0; + notify_all = QUEUE_POS_PAGE(QUEUE_HEAD) != QUEUE_POS_PAGE(QUEUE_TAIL); LWLockAcquire(AsyncQueueLock, LW_EXCLUSIVE); for (i = 1; i <= MaxBackends; i++) @@ -1539,6 +1542,9 @@ SignalBackends(void) pid = QUEUE_BACKEND_PID(i); if (pid != InvalidPid && pid != MyProcPid) { + if (!notify_all && QUEUE_BACKEND_DBOID(i) != MyDatabaseId) + continue; + QueuePosition pos = QUEUE_BACKEND_POS(i); if (!QUEUE_POS_EQUAL(pos, QUEUE_HEAD)) -- 2.11.0