[英]WAL archiving in postgres is not working
I have enabled WAL archiving in postgres configuration file. 我已在postgres配置文件中启用WAL归档。 When I restarted Postgres service WAL recovery is not working.
重新启动Postgres服务时,WAL恢复无法正常工作。 There was no wal recovery entries in logs.
日志中没有wal恢复条目。
Created directory for wal:
mkdir -p /var/lib/pgsql/wals/
mkdir -p /var/lib/pgsql/backups/
chown postgres:postgres -R /var/lib/pgsql/backups/
chown postgres:postgres -R /var/lib/pgsql/wals/
Edited the postgresql.conf with the below changes:
wal_level=archive
archive_mode=on
archive_command = 'test ! -f /var/lib/pgsql/wals/%f && cp %p /var/lib/pgsql/wals/%f'
sudo service postgresql restart 10
sudo su - postgres
pg_basebackup -D /var/lib/pgsql/data #created base backup
tar -C /var/lib/pgsql/data/ -czvf /var/lib/pgsql/backups/pg_basebackup_backup.tar.gz .
sudo service postgresql stop 10
tar xvf /var/lib/pgsql/backups/pg_basebackup_backup.tar.gz -C /var/lib/pgsql/data
echo "restore_command = 'cp /var/lib/pgsql/wals/%f %p'">/var/lib/pgsql/recovery.conf
cp /var/lib/pgsql/recovery.conf /var/lib/pgsql/data/
sudo service postgresql stop 10
sudo service postgresql start 10
There was no wal recovery entries in logs and the two rows which I deleted didn't get restored. 日志中没有沃尔玛恢复条目,删除的两行也没有恢复。
pg_basebackup can catch all WAL segments during backup. pg_basebackup可以在备份期间捕获所有WAL段。 I use basebackup into tar format with "-X stream" option and all works well.
我使用带有“ -X流”选项的basebackup转换为tar格式,并且一切正常。 See here - pg_basebackup – bash script for backup and archiving on Google storage It works excellent - I backup database 4.5+ TB big which takes almost 2 days.
请参阅此处-pg_basebackup-用于在Google存储上进行备份和归档的bash脚本效果非常好-我备份了4.5+ TB的数据库,需要大约2天的时间。
Restoration is described here - pg_basebackup / pg-barman – restore tar backup 这里描述了恢复-pg_basebackup / pg-barman –恢复tar备份
All works - we already had incidents when we had to restore from these backups. 所有工作-当我们不得不从这些备份中还原时,我们已经遇到了麻烦。
The WAL containing the two deleted rows probably hasn't been archived yet. 包含两行删除的WAL可能尚未归档。
archive_command
is run whenever a 16 MB WAL segment is full or something forces a log switch. 每当16 MB WAL段已满或由于某种原因迫使日志切换时,都会运行
archive_command
。
To be able to recover the latest changes that have not been archived yet, you have to copy the contents of pg_wal
to the pg_wal
directory in the restored base backup. 为了能够恢复尚未归档的最新更改,必须将
pg_wal
的内容复制到已还原的基本备份中的pg_wal
目录中。
You can also consider streaming replication or pg_receivewal
if you cannot afford to lose transactions. 如果您承受不起丢失事务的
pg_receivewal
,也可以考虑使用流复制或pg_receivewal
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.