pitr_wal-g.md
November 15, 2019 ยท View on GitHub
Point in time recovery with wal-g
wal-g is the successor of wal-e, which no longer seems to be in active development! This example shows how to do point in time recovery with stolon using wal-g
wal-g correctly suggests to not put environment variables containing secret data (like aws secret keys) inside the archive_command since every user connected to postgres could read them. In its examples wal-g suggests to use the envdir command to set the wal-g required environment variables or (since some distribution don't have it) just use a custom script that sets them.
Backups
Base backups
Take the base backups using the wal-g backup-push command.
Archive backups
For doing this you should set at least the archive_mode and the archive_command pgParameters in the cluster spec. Wal-g will be used as the archive command:
stolonctl update --patch '{ "pgParameters" : { "archive_mode": "on", "archive_command": "envdir /etc/wal-g.d/env wal-g wal-push %p" } }'
Execute a point in time recovery
Note: looks like wal-g doesn't backups various config files like postgresql.conf, pg_hba.conf. While pg_hba.conf is currently generated by stolon, you'd like to keep the previous postgres parameters after the restore. For doing this there're two different ways:
- if you want to backup the
postgresql.confyou should do this outsidewal-g. To restore it you have to create adataRestoreCommandthat will restore it after thewal-g backup fetchcommand. - if you don't want to backup/restore it than you can just set all the
pgParametersinside the cluster specification
stolonctl init '{ "initMode": "pitr", "pitrConfig": { "dataRestoreCommand": "envdir /etc/wal-g.d/env wal-g backup-fetch %d LATEST" , "archiveRecoverySettings": { "restoreCommand": "envdir /etc/wal-g.d/env wal-g wal-fetch \"%f\" \"%p\"" } } }'