| From: | Scott Ray <scott(at)scottray(dot)io> |
|---|---|
| To: | Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com> |
| Cc: | surya poondla <suryapoondla4(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 03:56:43 |
| Message-ID: | ZxZvnnBXzEobQUkk217i5npkSHUTm0BX1j6M9yP_D5SbYr9MAj9b1UkhKnZ2po64cNuQ0WaC03lo5eG1zBIybcqjdXZ6LU7QMSs6Ec6Tncw=@scottray.io |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Bharath,
Thanks for posting v11. I noticed it names me as its only author. If
you intended to give me credit, thank you, but please do not post code
you wrote under my name.
On Monday, November 16th, 2026 at 1:41 PM, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com> wrote:
> However, I
> think the patch is unnecessarily big at ~1480 LoC (for example, the
> tests don't have to be that long, the docs seem to be overly
> explaining things, and some code is unnecessarily complicated).
Relative to v10, v11 removes 1034 lines, 627 of them tests.
> I could bring it down to ~450 LoC with simplified docs, code
> and tests (for the same coverage).
The coverage is not the same. v11's tests never read any xmin, never
produce a slot_xmin row, and never check that access requires
pg_read_all_stats. I changed v11 to return 42 for every xmin and emit
no slot_xmin rows, and no test failed.
v11 reduces length further by deleting additions requested by reviewers.
v2 added datname at Solai's suggestion [1]. v5 added xid and a test
for a slot whose effective_xmin is set while data.xmin is still
invalid, and v6 made the SRF read fresh transaction start times, all
at Surya's request [2][3]. v11 drops these, and your mail gives no
reason other than the patch's size. Size alone would justify removing
anything. If you think these are not worth having, please say why
for each, so the reviewers who asked for them can respond.
The simplified docs omit material I added after you asked in [4]: the
notes on parallel workers and the SQL decoding functions (items 27 and
28) and the ANALYZE exception (item 29). They also lack information I
added unprompted because users need it: rows can tie, and a standby
shows the primary's transactions as of the standby's replay position.
v11 also returns gid from pg_get_xmin_horizon(). In item 7 of [4],
you wrote:
> The join also means gid reads null if the prepared transaction
> ends in between, for a row the view still reports.
In [5], I asked which locks the function would hold while it reads the
gid. v11 releases ProcArrayLock, then calls TwoPhaseGetGid(), which
takes only TwoPhaseStateLock. If the prepared transaction ends between
the proc array scan and that call, v11 still emits the row with a null
gid. Moving the lookup into C adds code without closing that window.
v11 also uses a row-building helper of the kind I declined in my reply
to item 25 of [4]. Calls to xmin_horizon_put_row() pass eight
arguments by position and are hard to read. v10 zeroes each row and
assigns fields by name. Like pg_stat_get_activity(),
pg_stat_get_wal_senders(), pg_prepared_xact(), and
pg_get_replication_slots(), it emits rows in one place. v11 emits
through its helper from six places. With v10's columns, such a helper
would save about 30 lines, but each call would pass ten arguments by
position. Five adjacent ones would be uint32, so the compiler could
not catch two of them swapped.
> And,
> the columns it emits seem to be too confusing, there are just too many
> xmins (shared, catalog and data horizon).
I can read this two ways. One is that three xmin columns are too many
to look at. Users can solve that by selecting the ones they want.
The other is that it's too confusing that there is more than one
horizon and that a row can hold back different horizons at different
values. v11 does not remove that confusion. It shifts most of that
complexity into the documentation, making horizon scoping easier to
overlook and requiring the user to apply more rules by hand.
Take the last query in your email. Writing it required choosing a
horizon and identifying which rows hold the horizon back. A user who
thinks there is only one horizon will not know that the query may
exclude logical slots that bloat the catalogs or that removing the
oldest row in the view might do nothing for a user table.
v11 splits a slot with both an xmin and a catalog_xmin into two rows.
Why is one slot row with a column per horizon more confusing than two
rows?
On a standby, v11 emits one primary_xact row for every transaction ID
in KnownAssignedXids, subtransactions included. A transaction with
two savepoints can yield three rows, and the view does not indicate
such rows are related. The documentation says to query the view on
the primary to find the transaction, but a subtransaction's ID does
not appear there.
I will reply to Surya, attach v12 there, and address logic duplication
and the xid column.
[1] https://postgr.es/m/CAF0whuesEDciXVLLPpSs72OMgzXzbbO9xTd-vDVcfhi0ZrDNNg@mail.gmail.com
[2] https://postgr.es/m/CAOVWO5p8boS_gcjVTJs8A=VkC_uz1OL0KjeZh6SBeUqsfbHzzg@mail.gmail.com
[3] https://postgr.es/m/CAOVWO5pTmggE5Z5cx12N_am4=4r76CwpgR9X591HcM5Q6FLNFw@mail.gmail.com
[4] https://postgr.es/m/CALj2ACXg+UQhtwZ5oiuvrx+1XKk49N6cu=wP5Cmv627_=zjsOg@mail.gmail.com
[5] https://postgr.es/m/qhODUcdKmqtOtwF4bW03SxPfKHda4EC7CEO2Ddj2jThrGRa8F1pDMA7LtG0R5JRo-2GK5RStXVP7tPP7WAUvfb_GCSN_I_YG7khDW859Fxg=@scottray.io
--
Scott Ray
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Scott Ray | 2026-11-21 04:01:21 | Re: pg_xmin_horizon: a system view of everything pinning the xmin horizon |
| Previous Message | Ana Bobillo | 2026-11-21 03:41:21 | Re: libpq: Don't read past the end of a message when tracing it |