简体   繁体   English

PostgreSQL / WAL归档:进行映像快照备份时,可以将archive_command保留为空吗?

[英]PostgreSQL / WAL-archiving: can I leave archive_command empty when doing image snapshot backups?

I have a PostgreSQL 9.5 instance running off an Azure VM. 我有一个在Azure VM上运行的PostgreSQL 9.5实例。 As described here , I must specify a post- and a prescript to tell Azure: "Yes, I've taken care of putting the VM in a state, so the entire VM/blob can be backed up as a snapshot that can be restored as a working new VM" and "Now I'm done" , thus Azure will flag the backup as Application consistent . 如上所述这里 ,我必须指定一个后和规定性告诉Azure的:“是的,我已经采取了把虚拟机的状态的照顾,所以整个VM / BLOB可以备份作为可以恢复的快照作为工作中的新VM”“现在我已经完成” ,因此Azure会将备份标记为“ 应用程序一致”

In terms of PostgreSQL, I have read the docs on continuous archiving , that instruct why and how to enable WAL Archiving to allow for backups. 关于PostgreSQL,我已经阅读了有关连续归档的文档,该文档说明了为什么以及如何启用WAL归档以允许进行备份。 And here comes my question: 这是我的问题:

If I set archive_mode = on and wal_level = archive , can I leave the archive_command empty, and does this even make sense? 如果我将archive_mode = on设置archive_mode = on wal_level = archive ,是否可以将archive_command保留为空,这是否有意义? Or - should I do some kind of archiving here (like eg copying the log segments to another location / disk), and is this archiving necessary to ensure a working database upon restoring the VM in my scenario? 或者-我是否应该在此处进行某种归档(例如,将日志段复制到另一个位置/磁盘),并且这种归档是否有必要,以确保在恢复我的方案中的VM时能确保数据库正常工作?

I only need to tell the PostgreSQL "Wait a minute / hold your data-writes (or whatever goes on), while I create a snapshot of the entire VM" . 我只需要告诉PostgreSQL “在创建整个VM的快照时,请稍等/保持数据写入(或进行的所有操作)” The plan is to execute pg_start_backup() before , take the snapshot and then pg_stop_backup() . 计划是先执行pg_start_backup()先拍摄快照,然后执行pg_stop_backup()

I do realize, this method (if it's even valid) is essentially a file system level backup, and according to docs , the postgres-service must be shut down for the fs-backup to be valid. 我确实意识到,这种方法(即使它是有效的)本质上是文件系统级别的备份,并且根据docs ,必须关闭postgres-service才能使fs-backup生效。 Another place I've read that hitting the pg_start_backup() should be enough to guarantee for a valid stand-alone physical backup. 我读过的另一个地方 ,点击pg_start_backup()应该足以保证有效的独立物理备份。

If the snapshots you plan to take are truly atomic, that is, the restored snapshot represents the state of the file system at some point in time, you can just restart the database from such a snapshot, and it will perform crash recovery and come up in a consistent state. 如果计划拍摄的快照确实是原子快照,即还原的快照表示某个时间点文件系统的状态,则只需从该快照重新启动数据库,它将执行崩溃恢复并启动处于一致状态。

In that case, there is no need to care about WAL archiving or backup mode. 在这种情况下,无需关心WAL归档或备份模式。 You could set archive_mod = off and not worry about it. 您可以将archive_mod = off设置archive_mod = off ,而不用担心。

If the snapshot is not truly atomic, or you want point-in-time-recovery (the ability to restore the database to a point in time between backups), you need WAL archiving set up and running, because you need the WALs to restore the database to a consistent state. 如果快照不是真正的原子快照,或者您要进行时间点恢复 (将数据库还原到两次备份之间的某个时间点的能力),则需要设置并运行WAL归档,因为需要WAL来还原数据库处于一致状态。

In that case archive_mode must be on and archive_command must be a command that returns success only if the WAL file has been archived successfully. 在这种情况下, archive_mode必须onarchive_command必须是仅在WAL文件已成功存档后才返回成功的命令。 If only one WAL is missing between your last backup and the time to which you want to restore the database, it will not work. 如果在上一次备份和要还原数据库的时间之间仅缺少一个WAL,它将无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM