Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uuth3-0023wg-16 for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Sep 2025 14:15:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uuth1-00EE2r-B1 for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Sep 2025 14:15:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uuth0-00EE2j-QV for pgsql-hackers@lists.postgresql.org; Sat, 06 Sep 2025 14:15:03 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uutgz-000qzh-1Q for pgsql-hackers@postgresql.org; Sat, 06 Sep 2025 14:15:02 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-25221fa3c9bso2076285ad.0 for ; Sat, 06 Sep 2025 07:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757168100; x=1757772900; darn=postgresql.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=eBe2X/jvl4jNb5aNHwTsG0R9KJtQ8djMMhVSUmPKOXw=; b=Xxs3t0Uu397p/YzKzY2MB6e2EMaMAC9haqcHsIp+UaRUyDZef9ERCQrFhnINRnOuJH 84iSv+JbL6YsHWj+Dg7JUK6lN4DKbhCEXWUfsWYw9q7gOAUkjFdtX/KbvIpqabs0Gnn6 KooheC+oaJruJxlveKhIycieZDGxhXgOPMoMMYAIk2jruLyKlPZ2cOHFdqDCglbfBsd0 xsyLaNEsOxjzC1aKfLhFTdjZdvJhw+5NBSaPl58do8luwJ9KAHl7K4D8uV1CtGAjh2ys Y+R/HhUhBuiPeoe+WirW4UUWKMoMoXUtXHH8WN1WknbnPvh7T609wg8IuzsJqxiL7CIJ JGKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757168100; x=1757772900; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=eBe2X/jvl4jNb5aNHwTsG0R9KJtQ8djMMhVSUmPKOXw=; b=hGSsPRZGEH83s79wSLiMgcbHMhw3iTc2wxe+GjAKKBUqbHCzxGnp81tfbtKw2qtG/H qzrirEla6bI5HAS02EZyk+yUP93AlckQ8/HUnEtcMWf2dl1ATRoCL5lgrxj28CmNm4uu FZ4j+n9YL5S4qYR6Ou2evUjRtK2YvTcN6/U1/vjTw59x/GGxnD/cWW1/7iiRSWeunm9L i/+cpwvuvqygl3mr/S+H1wI0gHyUfnKlyP00AYZ6R8LRUAxIQ6f3ehORLBCfyq4oWnnZ za0t4NBBHYRusH8TkYb83aT1eIrBKDsuGRIdEv8NwFMZb2lBlRFC1bin6K7LgVXdRdob Xncg== X-Forwarded-Encrypted: i=1; AJvYcCVyRlRCNRhFdnA/8k5qe/S58GbB/pEquNSj4yNerkAVdEqOIZ3PSDAJ/UMY9G76KJ8oXmFL4Yb8jdI19wZj@postgresql.org X-Gm-Message-State: AOJu0YwUgreTgVuZGowYQIkNmar2EPCo6fpSxbR63zQwP3vsHIpzdgmZ LywrABTJab1bGAL1DZlUt0U+fyU1FjM1W+xYgM+1vb7VtFNhG/5how6W X-Gm-Gg: ASbGncv8hffR+TMhoPG91Y0OM+cFX9rhZqle9P+r8gcUKiUDyOidD3+wWOauPWKRO4T j6AX0H/SSVb8MqZyjigILGQ8USstlKDeN/R+TXo9khxPtvPscyIpgcejrMPnkdfiqgjdlMq/XRa 3jNuI8zPZ85yGwrpLT/AUrctOiH1/eC6gzqytu6vSm90MoPgPFioYn6xBFJHTcr7YrJfUIUBiml u3MM+dZJ9FKwHfjUYM+3cBjY+li0H29t0S0iKpqwz49VwruC+8IC3/frT2XFsgHPoRKba7aBI+k E+diTcdQ7NuWwh2xNFZX2AZfTtP03gbcFHvzztmk3rA4dy5IjyFCVuNrtr34m8TlPK7mASKKdRl pSUvNAqpUdL/1m4mcVZQHf3G3yyiDY8u1v7ywRFgOe/r9a0s7 X-Google-Smtp-Source: AGHT+IFL+Ngv6btc4QIcTAOBO5qAsGGSekzlj2vVH0rjKpbXD3hfz41lH5a0EPrQZG/Pqcnzle/CvA== X-Received: by 2002:a17:902:ef08:b0:235:f091:11e5 with SMTP id d9443c01a7336-251759a9f43mr30639335ad.10.1757168099618; Sat, 06 Sep 2025 07:14:59 -0700 (PDT) Received: from localhost ([163.116.233.146]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-24cc91987f4sm68572055ad.33.2025.09.06.07.14.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Sep 2025 07:14:59 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sat, 06 Sep 2025 11:14:54 -0300 Message-Id: Cc: "Rishu Bagga" , "Yura Sokolov" , "Masahiko Sawada" , "Daniil Davydov" <3danissimo@gmail.com>, =?utf-8?q?=C3=81lvaro_Herrera?= , "Alexandra Wang" , "PostgreSQL Hackers" , "Tom Lane" , "Joel Jacobson" Subject: Re: LISTEN/NOTIFY bug: VACUUM sets frozenxid past a xid in async queue From: "Matheus Alcantara" To: "Arseniy Mukhin" X-Mailer: aerc 0.20.1 References: <202508061044.ptcyt7aqsaaa@alvherre.pgsql> In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri Sep 5, 2025 at 9:56 AM -03, Arseniy Mukhin wrote: >> Ok, I agree that that this may happen but I don't see this as a common >> case to fix the issue based on this behaviour. I think that we check the >> transaction status also to skip notifications that were added on the >> queue by transactions that are not fully committed yet, and I see this >> scenario as a more common case but I could be wrong. >> > > IIUC we don't need clog to check if the notification transaction is > still in progress, we use a snapshot for that (XidInMVCCSnapshot()). > If we see that the notification transaction is still in progress, we > postpone processing of that notification. If we see that notification > transaction is not in progress, then we check its status with > TransactionIdDidCommit() (using clog) and only then fail if clog > doesn't have notification transcation data (as a quick check, we can > see in the stack trace that the failure occurs during the call to > TransactionIdDidCommit, not XidInMVCCSnapshot). > > So we need to check notification transaction status only to understand > if a transaction was committed and we can send notification or it was > aborted (somewhere in between PreCommit_Notify and AtCommit_Notify) > and we should skip notification. And the solution that Yura Sokolov > suggested is to introduce a 'commited' flag, so we can check it > instead of calling TransactionIdDidCommit. Another option is to make > aborted transactions to clean up after themselves in AtAbort_Notify(), > so if listener see notification in the queue and transaction that > wrote it is not in progress, then such notification was always created > by committed transaction and we also don't need to call > TransactionIdDidCommit. One way for aborted transactions to clean up > is to set its notifications dbOid to 0, so listeners skip them. > Another option I think is to set queue HEAD back to the position where > it was when the aborted transaction started to write to the queue. It > also makes such aborted transaction notifications 'invisible' for > listeners. We have a global lock and there is always only one writer, > so it sounds possible. And there is another option which is the patch > that Rishu Bagga is working on. In the patch all transactions write to > the listen/notify queue only after they wrote a commit record to the > WAL, so all notifications in the queue are always by committed > transactions and we don't need to call TransactionIdDidCommit. > You are right, I missed the XidInMVCCSnapshot() call, sorry about that and thanks very much for all the explanation! I'll keep on hold the development of new patch versions for this thread and focus on review and test the patch from Rishu at [1] to see if we can make progress using the WAL approach. [1] https://www.postgresql.org/message-id/CAK80%3DjipUfGC%2BUQSzeA4oCP9daRt= HZGm2SQZWLxC9NWmVTDtRQ%40mail.gmail.com -- Matheus Alcantara