zlacker

[parent] [thread] 8 comments
1. gunnar+(OP)[view] [source] 2021-06-12 08:52:03
The other issue with LISTEN/NOTIFY is that a client will miss any notifications sent while it is not running (e.g. due to crash, update, etc.). An alternative would be logical replication and change data capture (CDC), as provided for Postgres by Debezium for instance. That way, any consumers won't miss events during downtimes, as they'll continue to read from the replication slot from the last offset they had processed.

Disclaimer: I work on Debezium

replies(5): >>superm+s1 >>hardwa+v2 >>jbvers+G4 >>BiteCo+l8 >>Michae+mM
2. superm+s1[view] [source] 2021-06-12 09:10:40
>>gunnar+(OP)
isnt this also the case for redis pubsub?
replies(2): >>philjo+K2 >>Nick-C+Nl
3. hardwa+v2[view] [source] 2021-06-12 09:24:02
>>gunnar+(OP)
Could you explain a little more about this (Debezium is awesome btw)? So after creating the proper replication slots, you set up change data capture via Debezium, then you listen to the CDC stream from the original DB you are connected to, correct?

This sounds like it might be vulnerable to dead consumers causing WAL to pile up without the right settings/periodic checks.

replies(1): >>gunnar+HN
◧◩
4. philjo+K2[view] [source] [discussion] 2021-06-12 09:26:25
>>superm+s1
I'd need to check, but I think so.

Which is probably why if you don't want loss if consumers go down a proper queue system (RabbitMQ, ActiveMQ, Amazon SQS, Kafka if you don't care about ordering between partitions) is the way I'd go.

5. jbvers+G4[view] [source] 2021-06-12 09:52:25
>>gunnar+(OP)
This is by design and very common with pub/sub.
6. BiteCo+l8[view] [source] 2021-06-12 10:29:28
>>gunnar+(OP)
Then use streams.
◧◩
7. Nick-C+Nl[view] [source] [discussion] 2021-06-12 13:08:40
>>superm+s1
For pub/sub yes that's correct. For full info though: Redis later added streams (in 5.x) for the don't-wan't-to-miss case: https://redis.io/topics/streams-intro
8. Michae+mM[view] [source] 2021-06-12 17:13:14
>>gunnar+(OP)
then what's the point of this feature as part of the db, if it doesn't do persistance?
◧◩
9. gunnar+HN[view] [source] [discussion] 2021-06-12 17:24:31
>>hardwa+v2
> then you listen to the CDC stream from the original DB you are connected to, correct?

Yes, exactly.

> This sounds like it might be vulnerable to dead consumers causing WAL to pile up without the right settings/periodic checks.

There are some subtleties around this indeed. You should monitor backlog of replication slots, so to identify inactive consumers as you say. Also, there are some corner cases you need to take care of: when listening to changes from a low-traffic database on the same PG host that also has a high-traffic database, the replication slot may not be acknowledged often enough. Debezium mitigates this by optionally writing changes to a dummy heartbeat table in the low-traffic database, so to advance the replication slot.

In Postgres 13 there's also a new option "max_slot_wal_keep_size" which limits WAL size retained by a replication slot. This prevents unbounded WAL growth, at the risk of consumers to miss events if they are down for too long.

All in all, proper monitoring and alerting is key.

[go to top]