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: Matheus Alcantara <matheusssilv97@gmail.com>,
Masahiko Sawada <sawada.mshk@gmail.com>
Cc: Daniil Davydov <3danissimo@gmail.com>, Álvaro Herrera <alvherre@kurilemu.de>, Alexandra Wang <alexandra.wang.oss@gmail.com>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2025-08-28T22:31:35Z
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
- v1-0001-Consider-LISTEN-NOTIFY-min-xid-during-VACUUM-FREE.patch (application/octet-stream) patch v1-0001
On Thu Aug 21, 2025 at 8:14 PM -03, Matheus Alcantara wrote: > I'll work on this considering the initial Daniil comments at [1] > > [1] https://www.postgresql.org/message-id/CAJDiXgg1ArRB1-6wLtXfVVnQ38P9Y%2BCDfEc9M2TXiOf_4kfBMg%40mail.gmail.com > I've been working on this on the last few days, please see the attached patch version. In this new version I tried to follow the suggestion from Daniil of scanning all pages from tail to head of the async queue. I tried to use other data structures like a list or a hashmap to store the xids but it shows to me more complicated due to duplicated information being stored and also considering that this data structure should be stored on shared memory, so I just tried to get the oldest xid with the information that we already have on the async queue. To find the oldest xid on the async queue I basically read all AsyncQueueEntry's on async queue pages on SLRU cache from tail to head, skipping only uncommitted transactions and notifications for different databases. The code that reads the pages and the entries within the page is a bit coupled with the send notification logic. The important functions that execute this is asyncQueueReadAllNotifications() which read the pages from SLRU cache and then call the asyncQueueProcessPageEntries() which read the entries within the page and send the notification to the client if needed. Since I need a very similar code to read the notification entries on the queue to check the min xid I think that it would be good to have an API that just works like an iterator and returns the next queue entry to work on so that it can be used for both cases. In this patch I created an AsyncQueueIterator that iterates over pages and AsyncQueueEntry's within the pages. The code is based on the asyncQueueReadAllNotifications() and asyncQueueProcessPageEntries() functions. For now I'm just implementing the iterator logic and use at AsyncQueueMinXid() to get the min xid on the queue to make the review more easier but I think that we can have another patch that refactor asyncQueueReadAllNotifications() and asyncQueueProcessPageEntries() functions to use this iterator approach and avoid duplicated code. I'm also adding a TAP test that reproduces the issue, but I'm not sure if it's declared on the best path. I think that it would be good to perform some benchmark tests to see if we have performance issues when reading very long async queues. Thoughts? -- Matheus Alcantara