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: Álvaro Herrera <alvherre@kurilemu.de>, "Alexandra Wang" <alexandra.wang.oss@gmail.com>
Cc: "Daniil Davydov" <3danissimo@gmail.com>, "PostgreSQL Hackers"
<pgsql-hackers@postgresql.org>
Date: 2025-08-11T13:41:08Z
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
Attachments
- v0-0001-Consider-async-queue-min-xid-on-VACUUM-FREEZE.patch (text/plain) patch v0-0001
On Wed Aug 6, 2025 at 7:44 AM -03, Álvaro Herrera wrote: >> My questions: >> >> 1. Is it acceptable to drop notifications from the async queue if >> there are no active listeners? There might still be notifications that >> haven’t been read by any previous listener. > > I'm somewhat wary of this idea -- could these inactive listeners become > active later and expect to be able to read their notifies? > I'm bit worry about this too. >> 2. If the answer to 1 is no, how can we teach VACUUM to respect the >> minimum xid stored in all AsyncQueueEntries? > > Maybe we can have AsyncQueueAdvanceTail return the oldest XID of > listeners, and back off the pg_clog truncation based on that. This > could be done by having a new boolean argument that says to look up the > XID from the PGPROC using BackendPidGetProc(QUEUE_BACKEND_PID) (which > would only be passed true by vac_update_datfrozenxid(), to avoid > overhead by other callers), then collect the oldest of those and return > it. > The problem with only considering the oldest XID of listeners is that IIUC we may have notifications without listeners, and in this case we may still get this error because when the LISTEN is executed we loop through the AsyncQueueEntry's on asyncQueueProcessPageEntries() and we call TransactionIdDidCommit() that raise the error before IsListeningOn(channel) is called. Another option would be to add a minXid field on AsyncQueueControl and then update this value on asyncQueueProcessPageEntries() and asyncQueueAddEntries() routines, and then we could check this value on vac_update_datfrozenxid(). > This does create the problem that an inactive listener could cause the > XID counter to stay far in the past. Maybe we could try to avoid this > by adding more signalling (e.g, AsyncQueueAdvanceTail() itself could > send PROCSIG_NOTIFY_INTERRUPT signal?), and terminating backends that > are way overdue on reading notifies. I'm not sure if this is really > needed or useful; consider a backend stuck on SIGSTOP (debugger or > whatever): it will just sit there forever. > With this idea that I've proposed we still could have this problem, if a listener take too long to consume a message we would block vacuum freeze to advance the xid. For this I think that we could have two GUC's; One to enable and disable the oldest xmin check on async queue and the second to control how far we want to prevent the vacuum from freezing the oldest async queue xid, and if the min xid raises this limit we ignore and truncate the xid. I've write a draft patch that plays with the idea, see attached. -- Matheus Alcantara