Re: LISTEN/NOTIFY bug: VACUUM sets frozenxid past a xid in async queue
Matheus Alcantara <matheusssilv97@gmail.com>
From: "Matheus Alcantara" <matheusssilv97@gmail.com>
To: "Daniil Davydov" <3danissimo@gmail.com>
Cc: Álvaro Herrera <alvherre@kurilemu.de>, "Alexandra Wang" <alexandra.wang.oss@gmail.com>, "PostgreSQL Hackers" <pgsql-hackers@postgresql.org>
Date: 2025-08-20T21:18:32Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Clear 'xid' in dummy async notify entries written to fill up pages
- 84f1bf4afa5e 14.21 landed
- 21a9014cf00a 15.16 landed
- 0e8eaa2181d4 16.12 landed
- d80d5f099502 17.8 landed
- 82fa6b78dba1 18.2 landed
- 0bdc777e8007 19 (unreleased) landed
-
Fix remaining race condition with CLOG truncation and LISTEN/NOTIFY
- c2e58c0711fe 14.21 landed
- 0c862646cf2a 15.16 landed
- 44e8c60be66c 16.12 landed
- c2682810ab7d 17.8 landed
- 7b069a1876e4 18.2 landed
- 797e9ea6e54b 19 (unreleased) landed
-
Fix bug where we truncated CLOG that was still needed by LISTEN/NOTIFY
- eba917d360e7 14.21 landed
- 1a469d7b5b7d 15.16 landed
- 053e1868b7ee 16.12 landed
- d02c03ddc5e3 17.8 landed
- 321ec54625fd 18.2 landed
- 8eeb4a0f7c06 19 (unreleased) landed
-
Escalate ERRORs during async notify processing to FATAL
- 7cb05dd2d198 14.21 landed
- b1da37de21d4 15.16 landed
- c1a5bde003b8 16.12 landed
- b821c92920f0 17.8 landed
- aab4a84bb070 18.2 landed
- 1b4699090eaf 19 (unreleased) landed
-
Limit the size of TID lists during parallel GIN build
- c98dffcb7c70 19 (unreleased) cited
On Tue Aug 19, 2025 at 2:37 PM -03, Daniil Davydov wrote: > Hi, > > On Tue, Aug 19, 2025 at 6:31 PM Matheus Alcantara > <matheusssilv97@gmail.com> wrote: >> >> On Tue Aug 19, 2025 at 12:57 AM -03, Daniil Davydov wrote: >> > You have started a very long transaction, which holds its xid and prevents >> > vacuum from freezing it. But what if the backend is stuck not inside a >> > transaction? Maybe we can just hardcode a huge delay (not inside the >> > transaction) or stop process execution via breakpoint in gdb. If we will use it >> > instead of a long query, I think that this error may be reproducible. >> > >> But how could this happen in real scenarios? I mean, how the backend >> could be stuck outside a transaction? >> > > For now, I cannot come up with a situation where it may be possible. > Perhaps, such a lagging may occur during network communication, > but I couldn't reproduce it. Maybe other people know how we can achieve > this? > Reading more the code I understand that once the a NOTIFY command is received by a backend (and the transaction is committed) it will emedialy signal all other listener backends and if the listener backend is in idle it will consume the notification and then send it back to the client as a PqMsg_NotificationResponse, so if there is a network delay to send the notification from the listener backend back to the client I don't think that it would be possible to get this error, because the message was already dispatched by the backend and it will eventually get to the client and once the notification is dispatched the backend doesn't need to track it anymore (the queue pointers of the backend are advanced after the dispatch). Assuming that every SQL command is wrapped into a transaction (if it's not already inside in) I think a busy listener backend will always prevent the vacuum from freezing clog files past from its current xid, so any notification that is sent while the backend is busy will not have their transaction status removed from clog files anyway. Is all these understandings and assumptions correct or am I missing something here? > I think that if such a situation may be possible, the suggestion to delete > messages will no longer be relevant. Therefore, first of all, I would like to > clarify this issue. > >From what I've understood until now it seems to me that this can happen only if we have a notification on the queue without any listener, so the notification may stay on the queue from a long time and a vacuum freeze can be executed during this time and then when we have a new listener (even for a different channel) it will fail to advance the pointers at listener setup(Exec_ListenPreCommit()) because it would not be able to get the transition status of this very old notification. (please note that I'm not trying to invalidate your concern, I'm also have this concern but unfortunately I'm unable to reproduce it and I'm just sharing my thoughts to see if this issue is really possible or not) -- Matheus Alcantara