David - Musings of an SRE

Fixing Postgresql Replication Checkpoint Wrong Magic 0 Error

Just the other day, I had a hardware failure on one of my servers. After fixing the main issue, I brought my VMs up.

But one of my VMs that hosted a development postgresql server would keep entering a crash loop. This can happen when there’s an unexpected or forced shutdown before postgresql can gracefully shutdown.

LOG:  starting PostgreSQL 16.2 (Ubuntu 16.2-1.pgdg22.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
LOG:  listening on IPv6 address "::1", port 5432
LOG:  listening on IPv4 address "127.0.0.1", port 5432
LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
LOG:  database system was interrupted; last known up at 2024-07-28 15:57:43 UTC
LOG:  database system was not properly shut down; automatic recovery in progress
PANIC:  replication checkpoint has wrong magic 0 instead of 307747550
LOG:  startup process (PID 831) was terminated by signal 6: Aborted
LOG:  aborting startup due to startup process failure
LOG:  database system is shut down

To get it up and running again, just head down to your postgresql data dir (usually within /var/lib/postgresql/<version>/main/) and search for the file pg_logical/replorigin_checkpoint

Rename it to something else, I personally would rename it to replorigin_checkpoint.bak and restart your postgresql.

You should now have a running