Skip to content

Add infrastructure to identify what holds back the xid horizon - #7

Open
shinyaaa wants to merge 2 commits into
masterfrom
add-oldest-xmin-reason-to-autovacuum-log
Open

Add infrastructure to identify what holds back the xid horizon#7
shinyaaa wants to merge 2 commits into
masterfrom
add-oldest-xmin-reason-to-autovacuum-log

Conversation

@shinyaaa

@shinyaaa shinyaaa commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Introduce GetXidHorizonBlocker() and GetXidHorizonBlockers() in
procarray.c. Given an xid horizon, these search the proc array and the
replication slots for what is preventing it from advancing: active
transactions, idle-in-transaction sessions, prepared transactions, hot
standby feedback (held either in a walsender's PGPROC or, when a physical
slot is in use, in the slot itself), and logical replication slots.

A blocker is described by the new XidHorizonBlocker struct, and the
candidates are ranked by XidHorizonBlockerType so that the single
highest-priority (root-cause) blocker can be reported. A companion
GetPreparedTransactionGid() in twophase.c resolves the GID of a blocking
prepared transaction.

This is infrastructure with no in-tree caller yet. A following patch
uses it to report the blocker in VACUUM's log output, and the same API
can underpin a future SQL-callable view that lists every blocker.

Author: Shinya Kato shinya11.kato@gmail.com
Reviewed-by: wenhui qiu qiuwenhuifx@gmail.com
Reviewed-by: Fujii Masao masao.fujii@gmail.com
Reviewed-by: Sami Imseih samimseih@gmail.com
Reviewed-by: Dilip Kumar dilipbalaut@gmail.com
Reviewed-by: Japin Li japinli@hotmail.com
Discussion: https://postgr.es/m/CAOzEurSgy-gDtwFmEbj5+R9PL0_G3qYB6nnzJtNStyuf87VSVg@mail.gmail.com

shinyaaa added 2 commits July 8, 2026 01:22
Introduce GetXidHorizonBlocker() and GetXidHorizonBlockers() in
procarray.c.  Given an xid horizon, these search the proc array and the
replication slots for what is preventing it from advancing: active
transactions, idle-in-transaction sessions, prepared transactions, hot
standby feedback (held either in a walsender's PGPROC or, when a physical
slot is in use, in the slot itself), and logical replication slots.

A blocker is described by the new XidHorizonBlocker struct, and the
candidates are ranked by XidHorizonBlockerType so that the single
highest-priority (root-cause) blocker can be reported.  A companion
GetPreparedTransactionGid() in twophase.c resolves the GID of a blocking
prepared transaction.

This is infrastructure with no in-tree caller yet.  A following patch
uses it to report the blocker in VACUUM's log output, and the same API
can underpin a future SQL-callable view that lists every blocker.

Author: Shinya Kato <shinya11.kato@gmail.com>
Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: Japin Li <japinli@hotmail.com>
Discussion: https://postgr.es/m/CAOzEurSgy-gDtwFmEbj5+R9PL0_G3qYB6nnzJtNStyuf87VSVg@mail.gmail.com
When VACUUM encounters recently-dead tuples that cannot be removed, it
is often unclear what is preventing the xid horizon from advancing.
Using the infrastructure added in the previous patch, VACUUM (VERBOSE)
and log_autovacuum output now report the highest-priority blocker that
is holding back OldestXmin, with identifying details: the backend pid,
the prepared transaction GID, the standby application_name, or the
replication slot name.

Because the horizon was computed earlier, the result is best-effort: the
original blocker may have already committed by the time it is looked up,
in which case a different blocker or none at all may be reported.

Author: Shinya Kato <shinya11.kato@gmail.com>
Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: Japin Li <japinli@hotmail.com>
Discussion: https://postgr.es/m/CAOzEurSgy-gDtwFmEbj5+R9PL0_G3qYB6nnzJtNStyuf87VSVg@mail.gmail.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant