Commit ca5646fc authored by Tom Lane's avatar Tom Lane

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.
parent 30735adf
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.145 2009/01/01 17:23:37 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.146 2009/02/13 17:12:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -277,6 +277,10 @@ Async_Unlisten(const char *relname) ...@@ -277,6 +277,10 @@ Async_Unlisten(const char *relname)
if (Trace_notify) if (Trace_notify)
elog(DEBUG1, "Async_Unlisten(%s,%d)", relname, MyProcPid); 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); queue_listen(LISTEN_UNLISTEN, relname);
} }
...@@ -291,6 +295,10 @@ Async_UnlistenAll(void) ...@@ -291,6 +295,10 @@ Async_UnlistenAll(void)
if (Trace_notify) if (Trace_notify)
elog(DEBUG1, "Async_UnlistenAll(%d)", MyProcPid); 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, ""); queue_listen(LISTEN_UNLISTEN_ALL, "");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment