# PostgreSQL archive cleanup: native filename probe

This is a filename-selection experiment, not a WAL validator or a restore test.
All 23 fixture files contain the same explicitly synthetic, invalid-WAL payload.
No database, archive service or production data is accessed.

## Recorded result

On 2026-11-28, PostgreSQL 16.15 (Ubuntu 16.15-0ubuntu0.24.04.1) passed
10 cases: seven successful selections and three rejected-input/option controls.
Every invocation used -n. Before/after filename, size and SHA256 inventories match.

The cutoff is 000000020000000000000010. The tool lists the earlier-position
00000003000000000000000F, despite its larger timeline prefix, but does not list
the later-position 000000010000000000000011. The cutoff and its partial variant
remain. This matches the deliberate timeline-independent comparison in upstream
source, which protects later segments from a parent timeline.

The matrix covers plain, .partial and .backup cutoff arguments, .gz stripping,
partial candidates, backup-history candidates, timeline-history files, lowercase
and unrelated names. Backup-history files are not selected by this 16.15 binary.
It rejects -b and --dry-run. PostgreSQL 18.0 source supports those options; we did
not execute that version. A backup-history filename accepted as the cutoff is
not the same as support for deleting backup-history candidates.

## Reproduce

Use a trusted PostgreSQL 16.15 binary; no binary or third-party package is
redistributed here. The recorded binary came from Ubuntu's
postgresql-16_16.15-0ubuntu0.24.04.1_amd64.deb. Results record its SHA256.

```sh
python3 -B probe.py --binary /path/to/pg_archivecleanup --output replay.json
python3 -B -m unittest discover -s . -p test_probe.py
```

The probe creates its own temporary directory; it accepts no archive-directory
argument and always places -n before optional arguments. Expected candidate sets
are explicit. It fails on unexpected output, exit status or file mutation.
The tests validate the committed results.json, not the newly generated replay.json.
Compare cases, fixture and binary identity; timestamps/platform may differ.
Output ordering is recorded but candidate comparisons are order-independent.
Do not pipe dry-run output to a deletion command.

## Evidence and limits

- results.json: native output, command arguments, checksums and inventories.
- probe.py: reproducible protocol.
- test_probe.py: offline receipt validation and independent boundary controls.
- PostgreSQL 16.15 source: https://github.com/postgres/postgres/blob/7d3e000c5961a544302072058a1184e9a588837b/src/bin/pg_archivecleanup/pg_archivecleanup.c
- PostgreSQL 18.0 source: https://github.com/postgres/postgres/blob/3d6a828938a5fa0444275d3d2f67b64ec3199eb7/src/bin/pg_archivecleanup/pg_archivecleanup.c
- Version 16 documentation: https://www.postgresql.org/docs/16/pgarchivecleanup.html
- Version 18 documentation: https://www.postgresql.org/docs/18/pgarchivecleanup.html

There is no measured deletion, WAL replay, crash, throughput or recovery success.
Finite synthetic cases do not prove general correctness or retention safety.
Choosing a safe cutoff still requires accounting for all required backup and
recovery dependencies. A standby staging cutoff is not a shared-archive policy.

Hesela-authored probe and tests: MIT License. Copyright (c) 2026 Hesela team.
Permission is granted, free of charge, to use, copy, modify, merge, publish,
distribute, sublicense and/or sell copies, provided this notice is included.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY ARISING FROM USE OF THE SOFTWARE.
