# PostgreSQL transaction horizons and index-only scans

Status: publication candidate with a third same-host replay and strengthened verification.
Classification: controlled software observation plus source synthesis.
This extends the existing PostgreSQL TOAST/index-only analysis, not a new bug report.

## Reproduce

Requires an unprivileged Linux account, PostgreSQL 16 server and client binaries,
and the pg_visibility extension. No Python dependencies beyond the standard library.

```sh
python3 -B probe.py --output replay.json
python3 -B verify_record.py results-1.json results-2.json results-3.json replay.json
python3 -B -m unittest -v test_probe.py
python3 -B -O -m unittest -v test_probe.py
python3 -B build_summary.py
```

Use --bindir for the server installation and --client-bin for the matching psql
installation. The default is /usr/lib/postgresql/16/bin for both. The recorded
run used the existing extracted Ubuntu server at
/srv/cgpt-workspace/artifacts/aio-pg-page-contract-20261018/pg/usr/lib/postgresql/16/bin
and the default client. Server version: 16.15. Both records retain executable
SHA-256 values; upstream source revision used for interpretation:
7d3e000c5961a544302072058a1184e9a588837b (configure.ac identifies 16.15).
Ubuntu packaging can include downstream changes; no byte-identical upstream
rebuild or cross-version portability is claimed.

The harness accepts no database URL or existing data directory. It creates a
private temporary cluster, disables TCP, restricts socket permissions, sets
timeouts, and stops/removes only that cluster. Run on disposable research
infrastructure, not a production host. Allow space for a small initialized
cluster and WAL. No existing database is accessed.

## Protocol

Each execution uses one fresh checksum-enabled cluster. Five cases run in fixed
order, each with a new permanent table: 256 integer primary keys, a nonindexed
64-character text payload, fillfactor 70. An anchor table is created beforehand.
Each observer command uses a new completed connection/transaction.

Controls:
- No holder.
- REPEATABLE READ with BEGIN only, no data query before insertion.
- READ COMMITTED with a completed SELECT on anchor.
- REPEATABLE READ with the same completed SELECT on anchor.
- READ COMMITTED calling pg_current_xact_id(), deliberately assigning an XID.

The holder is idle before insertion and before the first VACUUM. The observer
captures backend_xmin, backend_xid and public-relation locks externally, so this
measurement does not itself request a snapshot or XID in the holder. Only the
two anchor-read arms hold an anchor relation lock at that point. None has read
coverage. The observer then inserts and commits all 256 rows.

Four stages: after insertion; after VACUUM (ANALYZE, VERBOSE) while holder
remains open; after holder COMMIT without another VACUUM; after another VACUUM.
Immediately before COMMIT, a late holder SELECT records its own row count.
It returns 0 for the old REPEATABLE READ snapshot and 256 for the other holders.
The BEGIN-only arm acquires its first data snapshot at this late query.

Every stage captures pg_visibility map summaries before/after EXPLAIN, full
JSON EXPLAIN ANALYZE, independently selected ordered keys, and main-relation
heap page count. Sequential/bitmap plans are discouraged; actual plans must be
Index Only Scan with one loop. Parallel query and JIT are disabled for these
queries. Autovacuum is disabled only in the disposable cluster.

## Evidence and acceptance

results-1.json, results-2.json and results-3.json contain full ordered SQL/psql output, VACUUM
messages, holder protocol, exit statuses, environment and hashes. Sixty plans
across fifteen cases (five per cluster) agree on the derived transitions. This is
same-host repetition, not independent replication or a statistical sample.

verify_record.py checks the transition oracle and binds summaries to recorded
SQL outputs. Negative tests reject altered hashes, missing controls, bad status,
mismatched plans/maps/keys/holder state, and an absent COMMIT or VACUUM.
It is an internal-consistency check, not proof against a fabricated transcript.
build_summary.py generates summary.json and results-table.md from all three records.
Do not hand-edit generated results.

The exact 256 fetches and five pages describe this fixture. Heap Fetches counts
visibility-fetch attempts, not unique pages or physical disk reads. No elapsed
time, throughput, corruption, recovery, fleet behavior, active long-running
READ COMMITTED statement, replication slot, exported snapshot, prepared
transaction or other server version is tested.

Read synthesis.md for conclusions, source links and connections to the corpus.
Upstream sources are linked, not copied into this package. Synthetic fixture data
are generated by Hesela; no third-party dataset or production data are included.
Reuse of repository material follows the project's existing policy.

## Publication review, 2026-10-22

The unchanged runner reproduced every summarized observation in a third private
cluster. Original captures remain byte-identical. Review found that a missing
command status and a VACUUM targeting another table were accepted. The verifier
now requires command statuses and the exact ordered observer SQL, including
insertion, map target, VACUUM target and deletion. Holder observations must
precede insertion; environment/query metadata must match their transcript.
Nine additional regression tests bring the suite to 26. The verifier establishes
internal consistency, not transcript authenticity or comprehensive fault detection.

The PostgreSQL source interpretation is pinned; documentation functions and the
Steam research comparison are source review, not additional experimental arms.
See source-review.md for the research boundary. Existing captures retain their
actual generation dates; this review date does not replace them.
