pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Artur Zakirov <artur.zakirov@adjust.com>
Cc: Sergey Fedchenko <seregayoga@bk.ru>
Cc: Daniel Danzberger <daniel@dd-wrt.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Sergei Kornilov <sk@zsrv.org>
Cc: pgsql-hackers@postgresql.org, Peter Eisentraut <peter_e@gmx.net>
Cc: Marc Dean <marc.dean.jr@gmail.com>
Cc: Petr Jelinek <petr@2ndquadrant.com>
Cc: michael.paul.powers@gmail.com <michael.paul.powers@gmail.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Robert Welin <robert@vaion.com>
Subject: Re: BUG #15293: Stored Procedure Triggered by Logical Replication is Unable to use Notification Events
Date: Tue, 14 Sep 2021 17:56:58 -0400
Message-ID: <905668.1631656618@sss.pgh.pa.us> (raw)
In-Reply-To: <284756.1631467798@sss.pgh.pa.us>
References: <20190628212224.GA11418@alvherre.pgsql>
	<923262c473b494c4aec825a360d6f0499c144552.camel@dd-wrt.com>
	<1623669444.237579337@f317.i.mail.ru>
	<CAFt03JNo9=77=W6ggSjFRQ_h85BhrjNPArWd761k_KQye0HjCQ@mail.gmail.com>
	<3113945.1630956452@sss.pgh.pa.us>
	<CAFt03JMY=769Vst0nipzSTpiXG3HBf5m42cGxZqafwiO0uWDYA@mail.gmail.com>
	<284756.1631467798@sss.pgh.pa.us>

I wrote:
> Hence, I present the attached, which also tweaks things to avoid an
> extra pq_flush in the end-of-command code path, and improves the
> comments to discuss the issue of NOTIFYs sent by procedures.

Hearing no comments, I pushed that.

> I'm inclined to think we should flat-out reject LISTEN in any process
> that is not attached to a frontend, at least until somebody takes the
> trouble to add infrastructure that would let it be useful.  I've not
> done that here though; I'm not quite sure what we should test for.

After a bit of looking around, it seems that MyBackendType addresses
that problem nicely, so I propose the attached.

			regards, tom lane

Attachments:

forbid-LISTEN-in-background.patch (text/x-diff, 1.1K) download diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 27fbf1f3aa..bf085aa93b 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -803,6 +803,23 @@ standard_ProcessUtility(PlannedStmt *pstmt, ListenStmt *stmt = (ListenStmt *) parsetree; CheckRestrictedOperation("LISTEN"); + + /* + * We don't allow LISTEN in background processes, as there is + * no mechanism for them to collect NOTIFY messages, so they'd + * just block cleanout of the async SLRU indefinitely. + * (Authors of custom background workers could bypass this + * restriction by calling Async_Listen directly, but then it's + * on them to provide some mechanism to process the message + * queue.) Note there seems no reason to forbid UNLISTEN. + */ + if (MyBackendType != B_BACKEND) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + /* translator: %s is name of a SQL command, eg LISTEN */ + errmsg("cannot execute %s within a background process", + "LISTEN"))); + Async_Listen(stmt->conditionname); } break;

view thread (25+ messages)  latest in thread

Message-ID: <905668.1631656618@sss.pgh.pa.us>
Permalink:  ../905668.1631656618@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/905668.1631656618@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, artur.zakirov@adjust.com, seregayoga@bk.ru, daniel@dd-wrt.com, andres@anarazel.de, sk@zsrv.org, peter_e@gmx.net, marc.dean.jr@gmail.com, petr@2ndquadrant.com, michael.paul.powers@gmail.com, alvherre@2ndquadrant.com, robert@vaion.com
  Subject: Re: BUG #15293: Stored Procedure Triggered by Logical Replication is Unable to use Notification Events
  In-Reply-To: <905668.1631656618@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox