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 1utuob-00G9rj-Q1 for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Sep 2025 21:14:50 +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 1utuoa-00BkWj-UE for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Sep 2025 21:14:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1utuoa-00BkVL-KU for pgsql-hackers@lists.postgresql.org; Wed, 03 Sep 2025 21:14:49 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1utuoX-000PsT-26 for pgsql-hackers@postgresql.org; Wed, 03 Sep 2025 21:14:48 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-24a9cc916b3so4410685ad.0 for ; Wed, 03 Sep 2025 14:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756934085; x=1757538885; 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=4KFsZVxwhK4oQnG4lvBu79BRmz88r7glJ6MImBfR63k=; b=U516gKGZyUHYgNsGPMvwBj+4Mz+0pAb9bNNz3Xk4j0cmZ9bbNuY+fe5fJdfFPh2cO5 a/ic40zhbIfJ2z6V+R1U8RSmeNr0nF1QWjYobVdViTQmjwZCfyiF0/B8AumRccxDgB+S bUQnKhTbRdOEQmqPit7fkC3xr+Vgly8iOP7xreMkFli26UnA/wobX5zhYIbqiAvpfUZm qfpuNmWN3dEUNkRSotfJyuqx6EDP4LpGQlEZlXhTeqV1sPfdmplkQbUauqzTCOXKycaB ilxhqX1FSYegCCtgGwF6sA1Wloar0zjW40BerXPP2F6gZRW/VKt5GTKKrKwrdDvXwtl5 KiLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756934085; x=1757538885; 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=4KFsZVxwhK4oQnG4lvBu79BRmz88r7glJ6MImBfR63k=; b=sGjLNs4Zja3b81fWOrwQr4IRdQ9HUZgYZbQZTQfTr5HQUYgKIHxKzdKkjLVSgb6ovb MTAKHoAGcFGpov2FN+627dL3F4ms05XbBnZdDTnotF1fHD68H87YSQS0d/DwgIA4gRxh T9HPRWg2/gYPCJr8PW1FedWu/XDX8RPEg8Qv6kUBEWgcW99HkAn1tIGNk0w3ef7X+P1d ypdEC1oJ6WfXJFNghVFlJztHP4dmIXeS+sa3zPiSTR29xrR5hq+h1lb9rhFLhujt03CM pdl2WJsqC0Yf8r9si17MDDZphZt6PBNzIXHrqBgT7SwpE47goglcyWqHXHIMGRrhhNsV 6+5w== X-Forwarded-Encrypted: i=1; AJvYcCWAfuPECqpdRKmj9qx/50hY9Qm9BSQ+4NfPZWyGWVOAPiJi1TE05IOjyCyJwS0y27/6TOfy9zxBL2CKQlqE@postgresql.org X-Gm-Message-State: AOJu0Yx3h1MzyT6MNhhYCBjXaP3JijFM+1lRKMtcyF5i4w6jHH0etrkD fN+aTK94q1O0wl1pHDjsWDQa2RM/N0nSfhizsfvQzpllao10mLN15Bgr X-Gm-Gg: ASbGncvuxu0owdrxVz8G10MU4ALvdBPpz5j4UHozTg/wLBaDaYuoI8IXK6tvZEjEgbw 4Vr8oB5UhGV3hKqGhODOeczhkpY/Yo/zsgdjVu3+0xXYXIHwHfNhequT21Iv51bEhoYJjUWYFCf 3sWg/flIrbm8FerieF3VQVXaiUgy1MSoAERWZiakPsu0vr3YTP1WqmlmwRUC0RJ3CsPJTpzqpcq flvntJwlXK+P00VCLOtMNxRra/0ca6VCaoUogsgspngKxdJqVHK4RRZGhXNhbhQzOOvqSjKajv/ agy8DXM7T3eQ5dT2f4G7svoteov5IB3GmY4JOH+mvYNzuS8iEnV55sDzo2mhMjVMMmeP+th12aE r8LJ6WmD9fIuIM6TLskc0oYNP2fYsGAzUOeeM8R6wSqy6b3BKh0rECiqdGjyrDpHh X-Google-Smtp-Source: AGHT+IFVJVhTi9DETznA0YHBhPiagtpiJDlUzP9A5QIBkFdc2bfhlgcvPy5kjKWnVzVCBSJeHzovhw== X-Received: by 2002:a17:903:1c6:b0:24b:4a9a:7038 with SMTP id d9443c01a7336-24b4a9a71e6mr73673085ad.61.1756934084674; Wed, 03 Sep 2025 14:14:44 -0700 (PDT) Received: from localhost ([163.116.228.146]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-24c9669a0e1sm25808235ad.56.2025.09.03.14.14.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Sep 2025 14:14:44 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 03 Sep 2025 18:14:40 -0300 Message-Id: Cc: "Masahiko Sawada" , "Daniil Davydov" <3danissimo@gmail.com>, =?utf-8?q?=C3=81lvaro_Herrera?= , "Alexandra Wang" , "PostgreSQL Hackers" Subject: Re: LISTEN/NOTIFY bug: VACUUM sets frozenxid past a xid in async queue From: "Matheus Alcantara" To: "Arseniy Mukhin" , "Yura Sokolov" 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 Wed Sep 3, 2025 at 4:28 PM -03, Arseniy Mukhin wrote: >> Since we still need to scan those pages, couldn't we mark finished >> transactions as committed/aborted? >> This way we may to not hold datfrozenxid for a long time and will allow >> both safe clog truncation and safe async queue notification. >> More over, most notifications could be marked as completed in >> AtCommit_Notify already. So there is a need to recheck a few notificatio= ns >> that were written but not marked in AtCommit_Notify. >> >> Since AsyncQueueEntry field is used only to check visibility, looks like= it >> is safe to set it to FrozenTransactionId. > > I like the idea to make queue records more self-sufficient, so we > don't need to check a transaction's status to determine if a > notification should be sent. What if we somehow mark every record of > an aborted transaction, so listeners can skip it without checking > transaction status? Also if the record is not marked as "aborted" we > also can send it without checking transaction status. IIUC > AtAbort_Notify is called before any listener can read records of the > aborted transaction (is it correct?), so we can do such "marking" in > AtAbort_Notify. And the listen/notify subsystem already has a similar > "marking" mechanism. At the end of every queue page we have a "dummy" > record which is skipped by every listener. Listeners skip it because > record's 'dboid' equals InvalidOid (listeners ignore any record where > the 'dboid' is different from their own). In the same way aborted > transactions can set 'dboid' to InvalidOid for their records in > AtAbort_Notify. > > Some benefits of this approach: > 1) Only aborted transactions would need to perform extra work. > 2) Listeners don't need to check notify transaction status, but ofc > they still need to wait if the notify transaction is 'in progress'. > 3) Vacuum don't need to be listen/notify aware. > 4) We don't need to do an extra scan of the whole queue. > > What do you think? > IIUC we don't store notifications of aborted transactions on the queue. On PreCommit_Notify we add the notifications on the queue and on Commit_Notify() we signal the backends. Or I'm missing something here? -- Matheus Alcantara