Re: Slot's restart_lsn may point to removed WAL segment after hard restart unexpectedly

Vitaly Davydov <v.davydov@postgrespro.ru>

From: Давыдов Виталий <v.davydov@postgrespro.ru>
To: "Vitaly Davydov" <v.davydov@postgrespro.ru>
Cc: "pgsql-hackers" <pgsql-hackers@postgresql.org>
Date: 2024-11-21T16:13:23Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Update comment for ReplicationSlot.last_saved_restart_lsn

  2. Fix CheckPointReplicationSlots() with max_replication_slots == 0

  3. Remove excess assert from InvalidatePossiblyObsoleteSlot()

  4. Improve runtime and output of tests for replication slots checkpointing.

  5. Keep WAL segments by slot's last saved restart LSN

  6. Fix an assert in CheckPointReplicationSlots().

Attachments

On Thursday, November 21, 2024 17:56 MSK, "Vitaly Davydov" <v.davydov@postgrespro.ru> wrote:

> I'm trying to create a perl test to reproduce it. Please, give me some time to create the test script.

Attached is the test script which reproduces my problem. It should be run on a patched postgresql with the following changes (see below). It is the easiest way to emulate long checkpoint during high load.

CheckPointBuffers(int flags)
{
    BufferSync(flags);
+    pg_usleep(10000000);
}

I used the following command line to run the script, where <postgresqldir> - the directory with postgresql sources. The module IPC::Run should be installed as well. PATH and LD_LIBRARY_PATH should be set to a proper postgresql binary and libraries as well.

perl -I <postgresqldir>/src/test/perl/ restartlsn.pl

Finally, it should produce the following error into the log:

error running SQL: 'psql:<stdin>:1: ERROR:  requested WAL segment pg_wal/000000010000000000000001 has already been removed'

With best regards,
Vitaly