| From: | Scott Ray <scott(at)scottray(dot)io> |
|---|---|
| To: | surya poondla <suryapoondla4(at)gmail(dot)com> |
| Cc: | Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: pg_xmin_horizon: a system view of everything pinning the xmin horizon |
| Date: | 2026-11-21 04:01:21 |
| Message-ID: | OHp8aTleslESBdjLjP-sCXESJa_fF_lSckXAhSfE-VxsldUj_naLYQsa6Agd0OmbTyOidnGNX_67MhupQNGOgF0z_8uSCpNxM13iWEnYUSs=@scottray.io |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Surya,
On Tuesday, November 17th, 2026 at 1:32 PM, surya poondla <suryapoondla4(at)gmail(dot)com> wrote:
> Bharath's v11 removes the duplicated classifier by recording the
> inputs inside ComputeXidHorizonsInternal(), which addresses the
> concern Horiguchi, Sami and Bharath raised previously,
Sami described that design in [1] and set it aside:
> Initially, I thought about a ComputeXidHorizonsInternal() which takes a
> bool called with_horizon_data and returns the data needed by the SQL
> function. ComputeXidHorizons() would then become a wrapper for
> ComputeXidHorizonsInternal() with with_horizon_data = false. I did not
> have any performance concerns with this approach, but I also no longer
> like the idea of turning ComputeXidHorizons() into a multi-purpose
> function.
I agree.
Horiguchi raised his concern about GetXidHorizonBlockers() in the
other thread [2]. He asked for a helper that both functions could
use. Kato added ProcAffectsDataHorizon() and kept the two callers
separate [3]. In May, I asked whether the blocker could be found
inside ComputeXidHorizons(), and Kato preferred to keep the two
responsibilities separate [4]. When Bharath proposed it, Kato
declined again [5].
v10 keeps a separate function as well, but it contains a bug that v12
fixes: during recovery, a backend with no database holds back every
horizon, but v10 shows only shared_xmin. In my first mail [6], I said
I expect Kato's patch to be committed first. The SRF could
call ProcAffectsDataHorizon() and maybe other shared helpers. In my
reply to Sami [7], I said that ComputeXidHorizons() and
GetXidHorizonProcs() "already share what they can". That overstated
it, and the bug above is in a rule they do not share. Kato's patch
moves that rule into ProcAffectsDataHorizon(). I plan to build on his
helper rather than add competing helpers now.
v11 shares only two rules through ComputeXidHorizonsInternal(): which
processes are exempt, and taking the older of xid and xmin. v12
shares the first through a macro and restates the second in one line.
The rule v10 got wrong is not one of the two. v11 does not apply it
and describes it in the documentation instead.
For slots, v11 records nothing inside ComputeXidHorizonsInternal().
Like v12, it reads them again in its own loop. v12's loop restates
the rule that a slot's catalog_xmin holds back the shared and catalog
horizons but not the data horizon. v11's does not, because it does
not apply the rule. It leaves that to users.
> and an xid8 xmin makes the obvious ORDER BY work.
Yes, but no system view and no catalog uses an xid8 column. Using
xid8 with values from pg_stat_activity, pg_prepared_xacts,
pg_replication_slots, or pg_locks requires casting, and age() does not
accept xid8. I would rather the new view match the others.
> One thing I'd like to keep from v10 is the xid column.
v12 keeps it. Bharath replied that the view should report what goes
into computing the horizon and leave the rest to the existing views.
A backend's xid goes into that computation. As you say, without it a
backend that holds the horizon back with its own transaction looks
the same as one that holds it back with a snapshot. And v11 does not
leave the rest to the existing views. For example, it adds a C
function to return the gid, which is already in pg_prepared_xacts.
v12 is attached and applies to master commit 736ecc413b3. Besides the
recovery fix above, it corrects several statements in the
documentation and comments, fixes two races and an ineffective check
in the tests, and renumbers the TAP test.
[1] https://postgr.es/m/CAN12+YLOLcsePG8r9m9gTomXHbJ6ynd+-eLHmoN4eoBBQMSVKw@mail.gmail.com
[2] https://postgr.es/m/20260629.172207.542761264338459554.horikyota.ntt@gmail.com
[3] https://postgr.es/m/CAOzEurQSYUD64pGnbwgxHb_xUhHsO486Y1ZdV=dJugu922q+hA@mail.gmail.com
[4] https://postgr.es/m/CAOzEurTC+5xuH_X2EBWjW0Fs9iuTq3OMA=1FfT4xx1wYbCAR6g@mail.gmail.com
[5] https://postgr.es/m/CAOzEurTr-Z43BPSAz1cW=SiFsMk_AjC4qLAKfG2c09skL9Zn8w@mail.gmail.com
[6] https://postgr.es/m/AT-erSWn0vFw8TYLb84jqyfxgTV21gjwEo4YJDcses8qWtDkQK_pS6g2OIfVh4-L1PPn94w8-tE1mHZactVAgxPJ8vL96MXsyAnUg2Xz-Ks=@scottray.io
[7] https://postgr.es/m/i2q1k7cXS05oPhU_tBZfXKJ0tgqQ6unlVDrB8EhjjazAHmGhX3Qk9AAhybbf59b0yA_BH66GWzTc1hwvnnJb5WFApD1apw6DTrhAZSHqL3E=@scottray.io
--
Scott Ray
| Attachment | Content-Type | Size |
|---|---|---|
| v12-0001-Add-pg_xmin_horizon-view-showing-per-input-horiz.patch | application/octet-stream | 64.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Sho Ito | 2026-11-21 04:38:35 | Re: [PATCH v1] Preserve implicit composite casts in ROW deparsing |
| Previous Message | Scott Ray | 2026-11-21 03:56:43 | Re: pg_xmin_horizon: a system view of everything pinning the xmin horizon |