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 1vEk4P-00H4RV-Po for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Oct 2025 08:01:13 +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 1vEk4O-00Cnsa-FA for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Oct 2025 08:01:11 +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 1vEk4O-00CnsS-2I for pgsql-hackers@lists.postgresql.org; Fri, 31 Oct 2025 08:01:11 +0000 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vEk4K-005D7O-1I for pgsql-hackers@lists.postgresql.org; Fri, 31 Oct 2025 08:01:10 +0000 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-637e9f9f9fbso3583795a12.0 for ; Fri, 31 Oct 2025 01:01:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761897667; x=1762502467; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pSn88ijMn5F/khs86R9xPKWjkJWVXm9lT+bS7TjBptU=; b=l589glVP/0e8r9nZhAq90IAtljL5KdTHhfLBSvVO+gWDtAlhlY90eLaHiKxqWr2mAY OshBVP+e8JvmEmgKzSTdIAGicceFvayqMKixR0JHhQad1YLtRVjj49rVqguOCvoJ14QD Uxgq9uK2NwxmCb7V8NAQbPpUKUYT75/Ug6s0gCeKEEk7s5mPtjw1JGMz/1FDnDV3122W gHkkaVxouTMddOsyODMPyUedsxcc9MEhB/YSf/GAkbR2t4IOFm/bJHLdKUc70gXwGFLW H0pMUWxy4Yyu0ZmS6h6FgxDnHLSqYFLVHD8f9hsIArJTfHkAf5StOeZpXHGUjAkAvgef R4QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761897667; x=1762502467; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pSn88ijMn5F/khs86R9xPKWjkJWVXm9lT+bS7TjBptU=; b=e0F3t6E1XCPOFMjozMqF+CyuxbMjnGsf6lZbzrfMWwZn9v2pWHlATquYoIzhIz6b/F 1RmNdwmH1hci2LTAahIZTQoEOeb1D0PmWqYlz22XRghjBti2He6qn3kaFjolwum77doN VCd601GSrWZRZHnmoIWMka4pdwygN9Gi2Be+H8VVi99MNcE3bwn0t7Int7Ve6DGIeBwa 7Hgbs/28zRFJQOGohOgRxlYu2eMEaqoCMSEwEfSRXl1SlJtKKtK7GVmEstoVhf8YaQHL 3S1mFqTnQyw94EOFe4UehetSnPaYWh86TiUoOVVfKwcuI6zOYSaoZVQMrMYBmvopY3dl jKuw== X-Gm-Message-State: AOJu0YyqD7l0Iz6QEcRD6ZxgeAGkqXPN46K4UJgtyDoKj324CXcn3xoD iPPCmYWBw9KdqBNeKdAHPGmjlOpMBJ176by20OHr3q/fDo7pgwi8VH78eBv8o67TYod03+2VE2Z ewC7eXcN7v8QKSV5cI0tfA263WKoEcww= X-Gm-Gg: ASbGncufWgFTjSmQ3gu9K3I3WUVyVQPAm0Shq3WX/4fowMCzThvyafvPqdKzoodtVtr 6CO/A+FSSExdbaLx6Z3lpPlVqobgZEbJxPrCf6V1uAx1M3uXT8pc0imP04dprVXeRIS1+WOvvid njjoIgUIlZDtzSEhfaZvpKjnER91KkLKeB/KdIR/E9PtrbDHfOrIIv6j5JQI3AM2ZVpx9g1AP2J gBVlVL+emPrjH6kboaYjPw0eip6D9akX1JpJCHVZMlVnEh+Xhs999Y1GNo= X-Google-Smtp-Source: AGHT+IEkQgcOhRa3+UymDQ1cge6K4+UiwWxMzcFb7tQzBStuG48zjVa+xIpcg35WERMc8X0O+Ra/oT9cTTxSOuNMAEA= X-Received: by 2002:a05:6402:27cd:b0:639:dbe7:37b6 with SMTP id 4fb4d7f45d1cf-64076f71193mr2033144a12.3.1761897666856; Fri, 31 Oct 2025 01:01:06 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: wenhui qiu Date: Fri, 31 Oct 2025 16:00:54 +0800 X-Gm-Features: AWmQ_bksFf92I4zn_oNb1m8lf8IUFzTtYh_LZxIlrpg5WqD8c0u8z4Q8PEyUKD8 Message-ID: Subject: Re: Report oldest xmin source when autovacuum cannot remove tuples To: Shinya Kato Cc: PostgreSQL Hackers Content-Type: multipart/alternative; boundary="00000000000090496806426fc496" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000090496806426fc496 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable HI Thank you for your path ,This path is extremely helpful. > +/* > + * Identifies what determined a relation's OldestXmin horizon. > + * Used by autovacuum to report why dead tuples were not removable. > + */ > +typedef enum OldestXminSource > +{ > + OLDESTXMIN_SOURCE_ACTIVE_TRANSACTION, > + OLDESTXMIN_SOURCE_HOT_STANDBY_FEEDBACK, > + OLDESTXMIN_SOURCE_PREPARED_TRANSACTION, > + OLDESTXMIN_SOURCE_REPLICATION_SLOT, > + OLDESTXMIN_SOURCE_OTHER > +} OldestXminSource; > + > +typedef struct OldestXminInfo > +{ > + OldestXminSource source; > + int backend_pid; > +} OldestXminInfo; I have a question for like this one session begin; select * from table_a not commit or not closed session It is in OLDESTXMIN_SOURCE_ACTIVE_TRANSACTION type ? Thank On Fri, Oct 31, 2025 at 2:32=E2=80=AFPM Shinya Kato wrote: > Hi hackers, > > I am proposing to add the reason for the oldest xmin to VACUUM logs. > This feature would be useful for identifying why dead tuples cannot be > removed, thereby helping to diagnose and prevent table bloat. > > The current logs only indicate that dead tuples could not be reclaimed > due to the oldest xmin, but they do not reveal the underlying reason. > To identify the cause, it is necessary to query multiple views: > pg_stat_activity (for active transactions), pg_prepared_xacts (for > prepared statements), pg_replication_slots (for replication slots), > and pg_stat_replication (for hot standby feedback). However, because > the data in these views is volatile, it is difficult to retroactively > determine what was holding the oldest xmin at the specific time the > log message was generated. > > This PoC patch addresses this problem. The implementation now outputs > the reason for the oldest xmin and, where applicable, the backend PID. > This information was originally discarded when calculating the oldest > xmin horizon, and the computation required to retrieve these reasons > is considered reasonable. > > The patch is attached. What do you think? > > -- > Best regards, > Shinya Kato > NTT OSS Center > --00000000000090496806426fc496 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
HI=C2=A0
=C2=A0 Thank you for your path ,This path is = extremely helpful.
> +/*
> + * Identifies what determine= d a relation's OldestXmin horizon.
>=C2=A0+ * Used by autovacuum to report why dead tuple= s were not removable.
>= =C2=A0+ */
>=C2=A0= +typedef enum OldestXminSource
>=C2=A0+{
>=C2=A0+ OLDESTXMIN_SOURCE_ACTIVE_TRANSACTION,
>=C2=A0+ OLDESTXMIN_SOURCE_HOT_STA= NDBY_FEEDBACK,
>=C2=A0+ OLDESTXMIN_SOURCE_PREPARED_TRANSACTION,
>=C2=A0+ OLDESTXMIN_SOURCE_REPLICATION_SLOT,>=C2=A0+ OLDESTXMIN_= SOURCE_OTHER
>=C2=A0+} OldestXminSource;
>= =C2=A0+
>=C2=A0+typedef struct OldestXminInfo
>=C2=A0+{
>=C2=A0+ OldestXminSource source;
>=C2=A0+ int backend_pid;
>=C2=A0+} OldestXminInfo;
= I have a question for like this=C2=A0
one session=C2=A0
begin;
select * from table_a
not commit or not closed = session=C2=A0
It is in OLDESTXMIN_SOURCE_ACTIVE_TRANSACTION type = ?



Thank=C2=A0
<= /div>
On Fri, Oct 31, 2025 at 2:32=E2=80=AFPM Shinya Kato &l= t;shinya11.kato@gmail.com>= ; wrote:
Hi hackers,

I am proposing to add the reason for the oldest xmin to VACUUM logs.
This feature would be useful for identifying why dead tuples cannot be
removed, thereby helping to diagnose and prevent table bloat.

The current logs only indicate that dead tuples could not be reclaimed
due to the oldest xmin, but they do not reveal the underlying reason.
To identify the cause, it is necessary to query multiple views:
pg_stat_activity (for active transactions), pg_prepared_xacts (for
prepared statements), pg_replication_slots (for replication slots),
and pg_stat_replication (for hot standby feedback). However, because
the data in these views is volatile, it is difficult to retroactively
determine what was holding the oldest xmin at the specific time the
log message was generated.

This PoC patch addresses this problem. The implementation now outputs
the reason for the oldest xmin and, where applicable, the backend PID.
This information was originally discarded when calculating the oldest
xmin horizon, and the computation required to retrieve these reasons
is considered reasonable.

The patch is attached. What do you think?

--
Best regards,
Shinya Kato
NTT OSS Center
--00000000000090496806426fc496--