Failing assertion while taking a restartpoint during crash recovery

From: Imran Zaheer <imran(dot)zhir(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Failing assertion while taking a restartpoint during crash recovery
Date: 2026-08-15 07:57:15
Message-ID: CA+UBfamzfEReT0VOGRUW_=_AecCYQ-CNKLR_T4Q+YEmJAH3fdg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

While doing some benchmarking related to my work with the recovery
pipelining [1], I found that the checkpointer fails when trying to
take a time-based restartpoint during the crash recovery.

Right now I am facing this assertion failure.

TRAP: failed Assert("TransactionIdIsValid(initial)"), File:
"../../../../../home/imran/Desktop/work/pg/postgres/src/backend/storage/ipc/procarray.c",
Line: 1698, PID: 1279722
postgres: checkpointer (ExceptionalCondition+0x72)[0x5985b7bfb814]
postgres: checkpointer (+0x52ae2a)[0x5985b7a51e2a]
postgres: checkpointer
(GetOldestTransactionIdConsideredRunning+0x24)[0x5985b7a53797]
postgres: checkpointer (CreateRestartPoint+0x5f4)[0x5985b7707611]
postgres: checkpointer (CheckpointerMain+0x653)[0x5985b79a554b]
postgres: checkpointer (postmaster_child_launch+0x124)[0x5985b79a82bb]
postgres: checkpointer (+0x484204)[0x5985b79ab204]
postgres: checkpointer (PostmasterMain+0x130a)[0x5985b79aeaaf]
postgres: checkpointer (main+0x1e4)[0x5985b78c10b5]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x78c058829d90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x78c058829e40]
postgres: checkpointer (_start+0x25)[0x5985b7616065]

It looks like the checkpointer is not aware of whether hot standby
initialization was done during startup, which happens only in the case
of ArchiveRecoveryRequested [2]. In this specific case, the
checkpointer assumes hot standby initialization would have been done,
so it tries to call TruncateSUBTRANS(). A simple fix is to add
ArchiveRecoveryRequested to recovery shared memory XLogRecoveryCtl;
then the checkpointer will simply skip TruncateSUBTRANS if archive
recovery was not requested. I have attached my patch below.

Repro:

I had a script for my benchmarking work, but I changed it to reproduce
this specific bug [3].

Before running the script, set up the env file in `config/env.conf`.
You may need to increase WORKLOAD_DURATION so that crash recovery can
run long enough to trigger a restart point.

```
./run_test.sh -i # basebackup & archiving
./run_test.sh # cpy archive to pg_wal & run crash recovery
```

The script copies the archived wal to the basebackup pg_wal and then
starts the cluster. This will make the cluster undergo a crash
recovery. You will see the failing assertion in the log file created
`recoverylog`.

Looks like some work was already done trying to fix a similar issue in
the past [4],[5].

[1]: https://www.postgresql.org/message-id/CA%2BUBfa%3DvDV8wbmAV0pgrx-FuJh%2Bx8YOW23vJ90Jzr%3D14rV%2B9jA%40mail.gmail.com
[2]: https://github.com/postgres/postgres/blob/b59783502224c0ae721974a5d9b6fb915cbd37e1/src/backend/access/transam/xlog.c#L6212
[3]: https://github.com/imranzaheer612/pg-recovery-testing/tree/restartpoint-fail
[4]: https://www.postgresql.org/message-id/flat/17744-2c95e2b7783d7232%40postgresql.org
[5]: https://www.postgresql.org/message-id/flat/18119-5f60199d6207f4d1%40postgresql.org

Thanks,
Imran Zaheer

Attachment Content-Type Size
v1-0001-Fix-checkpointer-restartpoint-assertion-failure.patch text/x-patch 4.1 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zsolt Parragi 2026-08-15 08:10:31 Re: basebackup: do not verify checksums on pages written before enabling checksums
Previous Message Cagri Biroglu 2026-08-15 07:38:21 Re: Per-table resync for logical replication subscriptions