Re: Listen/notify across clusters

Lists: pgsql-hackers
From: Greg Jaskiewicz <gryzman(at)mac(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Listen/notify across clusters
Date: 2013-07-10 08:03:20
Message-ID: CA5030E2-2079-4504-9884-E5DFA2867965@mac.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi masters of PostgreSQL,

I recently got asked about possibility of listening to notifications on warm standby.
So question, how hard would that be to implement ?
Is it even possible without major changes to the architecture ?


From: Christopher Browne <cbbrowne(at)gmail(dot)com>
To: Greg Jaskiewicz <gryzman(at)mac(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Listen/notify across clusters
Date: 2013-07-10 16:27:53
Message-ID: CAFNqd5X0UpzVbczX3S0+KVYUCe-58Mx-uL=wYX3mky7AL+T=pA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Shouldn't be possible.

The act of requesting to LISTEN requires doing a sort of update to the
database. In elder versions, it put tuple(s) into pg_catalog.pg_listener,
and that's Right Well Disallowed on a WAL-based replica.

I would think that if you're keen on building an "event detection
substrate," particularly one that's supposed to cross clusters, then you
should consider using something actually attuned to that, such as a message
queueing system, whether an AMQP implementation such as RabbitMQ, or a
message bus like Spread. If you do that, then you can do this in much
broader cross-cluster ways for unrelated Postgres clusters.


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Christopher Browne <cbbrowne(at)gmail(dot)com>
Cc: Greg Jaskiewicz <gryzman(at)mac(dot)com>, "pgsql-hackers(at)postgresql(dot)org Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Listen/notify across clusters
Date: 2013-07-10 18:26:48
Message-ID: 51DDA768.7080004@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 07/10/2013 09:27 AM, Christopher Browne wrote:
> The act of requesting to LISTEN requires doing a sort of update to the
> database. In elder versions, it put tuple(s) into pg_catalog.pg_listener,
> and that's Right Well Disallowed on a WAL-based replica.
>
> I would think that if you're keen on building an "event detection
> substrate," particularly one that's supposed to cross clusters, then you
> should consider using something actually attuned to that, such as a message
> queueing system, whether an AMQP implementation such as RabbitMQ, or a
> message bus like Spread. If you do that, then you can do this in much
> broader cross-cluster ways for unrelated Postgres clusters.

Huh? LISTEN/NOTIFY across replication has been a desired feature since
we introduced streaming replication. We want it, there's just no
obvious way to do it.

Your email kinda implies that it's not desirable.

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


From: Greg Jaskiewicz <gryzman(at)mac(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Christopher Browne <cbbrowne(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Listen/notify across clusters
Date: 2013-07-15 14:10:51
Message-ID: B2A4F6D8-31E2-4DF3-ABEE-C33D1276C461@mac.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 10 Jul 2013, at 19:26, Josh Berkus <josh(at)agliodbs(dot)com> wrote:
>
>
> Huh? LISTEN/NOTIFY across replication has been a desired feature since
> we introduced streaming replication. We want it, there's just no
> obvious way to do it.
>
> Your email kinda implies that it's not desirable.

Thanks Josh. I was under impression that it is desirable.
It certainly makes sense to be used with the existing database infrastructure.

In terms of features, apart from separating LISTEN so that it can be actually used on Standbys, wouldn't it be a matter of including the notifications in the WAL stream, as simple packets ?
This would guarantee same behaviour as on the master.

--
GJ


From: Andreas Karlsson <andreas(at)proxel(dot)se>
To: Greg Jaskiewicz <gryzman(at)mac(dot)com>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, Christopher Browne <cbbrowne(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Listen/notify across clusters
Date: 2013-07-17 02:16:00
Message-ID: 51E5FE60.7060300@proxel.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 07/15/2013 04:10 PM, Greg Jaskiewicz wrote:
> In terms of features, apart from separating LISTEN so that it can be actually used on Standbys, wouldn't it be a matter of including the notifications in the WAL stream, as simple packets ?
> This would guarantee same behaviour as on the master.

I guess one problem is to implement writing to the WAL with the smallest
possible performance hit. As far as I can see there are two possible
approaches: either write to WAL when NOTIFY is run or write to WAL on
commit. The former seems more in line with how commands in PostgreSQL
usually work.

There shouldn't be any major problems with implementing LISTEN on the
slaves since LISTEN is done in memory.

I feel like I as a beginner to the codebase am missing something bit
because while this is a fair bit of work it does not too hard to implement.

Andreas

--
Andreas Karlsson


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Andreas Karlsson <andreas(at)proxel(dot)se>
Cc: Greg Jaskiewicz <gryzman(at)mac(dot)com>, Christopher Browne <cbbrowne(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: Listen/notify across clusters
Date: 2013-07-17 18:08:59
Message-ID: 51E6DDBB.6020106@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 07/16/2013 07:16 PM, Andreas Karlsson wrote:
> I guess one problem is to implement writing to the WAL with the smallest
> possible performance hit. As far as I can see there are two possible
> approaches: either write to WAL when NOTIFY is run or write to WAL on
> commit. The former seems more in line with how commands in PostgreSQL
> usually work.

Yes.

There was some work being done by Heikki or Andreas Freund on "log-only
tables" which seems like it would be a perfect solution to this. Anyone
know what happened to that patch?

> There shouldn't be any major problems with implementing LISTEN on the
> slaves since LISTEN is done in memory.

Actually, that's not the hard part. Listeners need to be registered on
the standby, which requires a write to a system catalog, currently. So
you'd need some alternate way to register listeners on the standby.

Presumably all LISTEN events would need to be broadcast to all standbys,
whether or not they had LISTENERs registered. Otherwise we'd have to
push the listener registrations back to the master.

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Andreas Karlsson <andreas(at)proxel(dot)se>, Greg Jaskiewicz <gryzman(at)mac(dot)com>, Christopher Browne <cbbrowne(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: Listen/notify across clusters
Date: 2013-07-17 18:47:46
Message-ID: 51E6E6D2.8060602@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 07/17/2013 02:08 PM, Josh Berkus wrote:
>
>> There shouldn't be any major problems with implementing LISTEN on the
>> slaves since LISTEN is done in memory.
> Actually, that's not the hard part. Listeners need to be registered on
> the standby, which requires a write to a system catalog, currently.

Er, not since 9.0 I think - there is no pg_listener any more.

cheers

andrew