[PATCH] Fix minRecoveryPoint not advanced past checkpoint in CreateRestartPoint - Mailing list pgsql-hackers

From Adam Lee
Subject [PATCH] Fix minRecoveryPoint not advanced past checkpoint in CreateRestartPoint
Date
Msg-id aczc9cxkr7SEHXV5@MAC-CVW1VHW5R6
Whole thread Raw
Responses Re: [PATCH] Fix minRecoveryPoint not advanced past checkpoint in CreateRestartPoint
List pgsql-hackers
Hi hackers,

I ran into this while working on recovery pre-check logic that relies on
pg_controldata to verify whether replay has reached a specific restore point.

Reproducer:

```
  -- on primary:
  CHECKPOINT;
  SELECT pg_create_restore_point('test_rp');

  -- recover with:
  --   recovery_target_name = 'test_rp'
  --   recovery_target_action = 'shutdown'

  -- after recovery shuts down:
  pg_controldata shows minRecoveryPoint 104 bytes behind
  pg_create_restore_point's return value (104 bytes = one
  RESTORE_POINT WAL record).
```

My RCA:

When recovery_target_action=shutdown triggers, the checkpointer performs a
shutdown restartpoint via CreateRestartPoint(). If a CHECKPOINT record was
replayed shortly before the recovery target, CreateRestartPoint advances
minRecoveryPoint to the end of that CHECKPOINT record.

However, any no-op records replayed after the CHECKPOINT (such as
RESTORE_POINT) do not dirty pages, so the lazy minRecoveryPoint update that
normally happens during page flushes never fires for them. As a result,
minRecoveryPoint in pg_control ends up behind the actual replay position.

My Fix:

The attached patch fixes this by reading the current replay position from
shared memory after advancing minRecoveryPoint to the checkpoint end, and
advancing further if replay has progressed past it. This is safe because
CheckPointGuts() has already flushed all dirty buffers and the startup process
has exited, so replayEndRecPtr is stable and all pages are on disk.

-- 
Adam

Attachment

pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: Eliminating SPI / SQL from some RI triggers - take 3
Next
From: "cca5507"
Date:
Subject: Re: tuple radix sort