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.96) (envelope-from ) id 1vZ0TM-001QVU-0W for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Dec 2025 05:34:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vZ0TJ-008WyP-0S for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Dec 2025 05:34:41 +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.96) (envelope-from ) id 1vZ0TI-008WyH-2U for pgsql-hackers@lists.postgresql.org; Fri, 26 Dec 2025 05:34:41 +0000 Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vZ0TH-002f7i-2K for pgsql-hackers@lists.postgresql.org; Fri, 26 Dec 2025 05:34:40 +0000 Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-8886fdf674bso88012216d6.2 for ; Thu, 25 Dec 2025 21:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766727277; x=1767332077; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=fayjqov1/w2I1PhRQKm1zbR1uGjkje0SfIcWpY1MpcM=; b=f0yrfMrqQyClqp9GuOKbxzoj6D8NZmf8QKSr6aaW8TSiY3D0YwkBMhIL08BdPiXAbp aOwmZQ28o1SBlPRbonJVY+YCffueyYogOs9nLMK0a6CF6NHXWSOk0dKZOoqYKsuxYNAS WxN0nA/vY2rSMheIr3qGNpZmkqYWt6AhYJuJjjum7L4mNORmX84MWZft42HQLS7EDJ08 /BbSstbJx7rSanzIZYYY9NCGyUMKuv7TADFpnMOqBC9Oh5f1AiRGLP4Z6j5p02E1vqK4 6XxcpK3J6UEcNFxfkZbmhtLCY8GFvFr0DrJ8PVJJt92HvlQH0YSdHABpwqqQcdzHdqkU DbJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766727277; x=1767332077; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=fayjqov1/w2I1PhRQKm1zbR1uGjkje0SfIcWpY1MpcM=; b=WXsgnNNL+iDZ4H0kpGzzFOs/8txkPc/ABH228UQJUaLrSM69sfdRpM4RL3qwvzWFH3 9dExNxtL1XYWUq4I/2LkegEbFJdNeaYPAIGwRT9BNUNA0Z+lLQ5Th0WRC7Ixbs2s2E7s QRbxTt75Jh2sucAFQWhxf24bSXiyjR13DRtW02+ty+iguvwIi3ndhdYXJ4JmUXK36dNK CIjU+s9qgWVCven4n6qQZQZIj7Z1b4DbuISzHBxWU3UuWAyxWdJ7X/qdXCr1mSwEP8TO GFW+Jg+cLcLHW835bqZ0UvQ4iqbZQGok+Gn5XC689hSk8E3/vcOxiyKVo33NF6TymdXG 3zRw== X-Forwarded-Encrypted: i=1; AJvYcCWQC7bS7Mn/eKmKx0b0cmJWkI7Nx8K51UiL/I3DWjbyN0HfUPb5DtLCi53efreh/6JfccmwbbJSCs0Ti+me@lists.postgresql.org X-Gm-Message-State: AOJu0YzSpS+OXyR9VqZ2RCXv6F9jGagFXqlhr1lzJdPhVTuofUMnaklP G80NQjMnihUeb42mmu6uqgBlr3+KT/pqWw1hoTNZ+pIbqc9SRoUQ0SslQE7Eou2M46M8yCxKN/T K4ai3+TRuzBeblBGQ1b8oW3TxmL5qhg== X-Gm-Gg: AY/fxX6io/ybTo8dNiz4oqCGmLIRVZMmCE78ULg66jT1r2so/y/pnujAKj+pWmTS4d+ 9YhkTD2Zs5a/fRcUfxW6VSX+eT4StAiffZi9wgL2NRMCjdgwOFb8em8wBxS9fOf9EcuQohFt4Ge AcZTqevuU0dQDx8eLwY4p4ZKmw5YPV5+NCA97CeJyRysD5/Yxn5jQ7jNoG/bt7llevkoLICtfDQ zExhTxzOaQawuFXtk8pl/NA3ZRz656cem/bGFmhsQ0g8pjjH+GzFQZkXenAkqiWiKnNKsk= X-Google-Smtp-Source: AGHT+IE1JIw24wYMRW4qcxy18Ot9J4OK3VuKQztEGmmC50wAVYDJWbtnWrWvroy5aQD6ZUX9e0Fr2TfXXhEZh0wHL1M= X-Received: by 2002:ad4:40c6:0:b0:880:877d:6c6e with SMTP id 6a1803df08f44-88d8369eadbmr293387246d6.37.1766727277393; Thu, 25 Dec 2025 21:34:37 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Shinya Kato Date: Fri, 26 Dec 2025 14:34:01 +0900 X-Gm-Features: AQt7F2pdbfMQylPmlM0Qk65djEHWG-GqKFdCa9d2-aZTvQ1Xh5YKyQc-yRrCpOI Message-ID: Subject: Re: Report oldest xmin source when autovacuum cannot remove tuples To: Sami Imseih Cc: wenhui qiu , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thank you all for the review comments, and sorry for the late reply. I will address the review comments in order. On Sat, Nov 15, 2025 at 9:25=E2=80=AFAM Sami Imseih w= rote: > More importantly: > > 3/ As mentioned earlier in the thread, the "idle-in-transaction" > transactions is not being reported correctly, particularly for write > tansactions. I think that is an important missing case. The reason > for this is the cutoff xmin is not being looked up against the current > list of xid's, so we are not blaming the correct pid. > > 4/ > Thinking about point 3 above, I began to wonder if this > whole thing can be simplified with inspiration. Looking at the > existing BackendXidGetPid(), I think it can. > > Based on BackendXidGetPid(), I tried a new routine called > BackendXidFindCutOffReason() which can take in the cutoff xmin, > passed in by vacuum and can walk though the proc array and > determine the reason. We don't need to touch ComputeXidHorizons() > to make this work, it seems to me. This comes with an additional > walk though the procarray holding a shared lock, but I don't think > this will be an issue. > > Attached is a rough sketch of BackendXidFindCutOffReason() > For now, I just added NOTICE messages which will log with > VACUUM (verbose) for testing. Thanks for the revised proposal! Your approach is clear and makes the code easier to read. However, I=E2=80=99m hesitant to proceed with this ide= a for the following reasons: - The original proposal extends ComputeXidHorizons(), which is always calculated, so there is almost no additional overhead. - Your proposal incurs additional cost. Furthermore, the time lag between the execution of ComputeXidHorizons() and BackendXidFindCutOffReason() could lead to inaccurate logging. - I don't believe it is necessary to distinguish between active transactions and "idle in transaction." These states can change rapidly, and as long as we have the PID, we can check the current status via pg_stat_activity. - Your comment made me realize that it might be appropriate to expose the oldest xmin in the pg_stat_{all,user,sys}_tables views, rather than just logging it. In that case, we would need to calculate the oldest xmin horizon every time. This might be a topic for a separate thread, but we could consider adding columns such as: - pg_stat_{all,user,sys}_tables.last_vacuum_oldest_xmin (xid) - pg_stat_{all,user,sys}_tables.last_vacuum_oldest_xmin_source (text) -- Best regards, Shinya Kato NTT OSS Center