How to Restore PostgreSQL Database from WAL Without Backup

postgresqlpostgresql-9.6restore

I am trying to restore data in my database. How can I restore data from WAL without any database backups? Can I generate a backup file from WAL logs?

Best Answer

If you only have the WAL, with no base backup (copy of the data directory, pg_basebackup, etc), you cannot restore. Full stop. And no, you cannot use a dump from pg_dump to restore WAL on top of.

WAL only contains changes to the data directory, and is meaningless without a base backup to apply it to.

Imagine you have a half page from one of your bank statements, without a running balance shown in a column. You want to use it to find out the balance on your account. You cannot possibly do that, since you don't know the starting or ending balance. Same issue here.