№ 10938 В разделе
Sysadmin
от March 20th, 2020,
В подшивках: Backups, Linux, PostgreSQL
Master database: postgresql-10, in production
Backup storage: minio with empty pg-walg-backup
bucket
Task: Create slave postgresql-10 server with recovery
Install wal-g binary manually or use my Ubuntu repository (install walg-lzo).
Create special script for wal-g with variables, save to /var/lib/postgresql/walg-postgresql
#!/bin/bash source /etc/profile export AWS_ENDPOINT=http://minio.myserv.com:9000 export AWS_ACCESS_KEY_ID="KEYNAMEKEYNAMEKEYNAME" export AWS_SECRET_ACCESS_KEY="SECRETSECRETSECRETSECRETSECRETSECRET" export WALE_S3_PREFIX="s3://pg-walg-backup/" export AWS_S3_FORCE_PATH_STYLE="true" export AWS_REGION=us-east-1 export PGHOST=/var/run/postgresql export PGUSER=postgres export PGPORT=5433 wal-g $@
It is not secure to store this file global readable. Best choice to place it in postgres home directory without read by others:
chmod 500 /var/lib/postgresql/walg-postgresql chown postgres:postgres /var/lib/postgresql/walg-postgresql
Add to postgresql.conf
:
archive_mode = on archive_command = '/var/lib/postgresql/walg-postgresql wal-push %p'
Ok, now run backup-push to create full backup:
/var/lib/postgresql/walg-postgresql backup-push /pg_data/10/main
Stop postgresql and remove data directory, wal-g requires empty directory before restore.
Now run:
/var/lib/postgresql/walg-postgresql backup-fetch /pgdata/10/main LATEST
Create /pgdata/10/main/recovery.conf
:
standby_mode = 'on' restore_command = 'walg-postgresql wal-fetch "%f" "%p"'
Now see logfile for wal restoring, database in recovery mode.
Postgresql 12: recovery settings moved to postgresql.conf. To start infinite recovery create flag file /var/lib/postgresql/12/main/standby.signal
.
Fortune cookie: The last time we mixed religion and government people were burned at the stake. -- bumper sticker
Leave a Reply