summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2009-02-13 17:12:04 +0000
committerTom Lane2009-02-13 17:12:04 +0000
commit5d2a33cc53db4d1996c81ab09c879ab8e5f31acb (patch)
treeedafafe6fb25a6d54633be2de6859e0f4bcbcc59
parent9697aaab2fdebcaa1107bdf918c3fec8378b3b24 (diff)
Fix UNLISTEN to fall out quickly if the current backend has never executed
any LISTEN command. This is more important than it used to be because DISCARD ALL invokes UNLISTEN. Connection-pooled applications making heavy use of DISCARD ALL were seeing significant contention for pg_listener, as reported by Matteo Beccati. It seems unlikely that clients using LISTEN would use pooled connections, so this simple tweak seems sufficient, especially since the pg_listener implementation is slated to go away soon anyway. Back-patch to 8.3, where DISCARD ALL was introduced.
-rw-r--r--src/backend/commands/async.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c
index a6b93e5910..d410b2d47d 100644
--- a/src/backend/commands/async.c
+++ b/src/backend/commands/async.c
@@ -277,6 +277,10 @@ Async_Unlisten(const char *relname)
if (Trace_notify)
elog(DEBUG1, "Async_Unlisten(%s,%d)", relname, MyProcPid);
+ /* If we couldn't possibly be listening, no need to queue anything */
+ if (pendingActions == NIL && !unlistenExitRegistered)
+ return;
+
queue_listen(LISTEN_UNLISTEN, relname);
}
@@ -291,6 +295,10 @@ Async_UnlistenAll(void)
if (Trace_notify)
elog(DEBUG1, "Async_UnlistenAll(%d)", MyProcPid);
+ /* If we couldn't possibly be listening, no need to queue anything */
+ if (pendingActions == NIL && !unlistenExitRegistered)
+ return;
+
queue_listen(LISTEN_UNLISTEN_ALL, "");
}