PostgreSQL PANIC: could not locate a valid checkpoint record

We have received the following error message.

PostgreSQL PANIC: could not locate a valid checkpoint record

PostgreSQL PANIC: could not locate a valid checkpoint record

Reason: It’s looking for a checkpoint record in the transaction log that probably doesn’t exist or is corrupted. We have to reset the write-ahead log and other control information of a PostgreSQL database cluster.

Solution:
We have to reset the write-ahead log and other control information of a PostgreSQL database cluster.

1. Stop the postgresql server if not stopped.

2. Switch to user postgres.

sudo su - postgres

3. Go to the path where pg_resetwal is present.
Path on Ubuntu for PostgreSQL version 12.
cd /usr/lib/postgresql/12/bin
4. Then, run the following command.

./pg_resetwal -f /var/lib/postgresql/12/main

Output:

Write-ahead log reset

sudo su - postgres

5. Start PostgreSQL cluster.