简体   繁体   English

在PostgreSQL流复制中使用archive_command

[英]use of archive_command in PostgreSQL streaming replication

When using streaming replication can someone please explain the purpose of archive_command and restore_command in PostgreSQL? 使用流复制时,是否可以有人解释PostgreSQL中archive_command和restore_command的用途?

As i studied in streaming replication secondary server read and apply the partially filled WAL files.suppose i have my wal segment location in pg_xlog and using archive_command i am copying this to my local archive directory say /arclogs. 正如我在流复制辅助服务器中研究的那样,读取并应用部分填充的WAL文件。假设我在pg_xlog中有wal段位置,并使用archive_command将其复制到本地存档目录中,例如/ arclogs。

So if secondary server is going to read the partially filled archive logs from pg_xlog over the network then what's the use of files kept in /arclogs. 因此,如果辅助服务器要通过网络从pg_xlog读取部分填充的存档日志,那么/ arclogs中保存的文件的用途是什么。 and also the files will be sent to /arclogs only when they will be 16 mb? 而且文件只有在16 MB时才会发送到/ arclogs吗?

I'm new to PostgreSQL & your help will be appericated. 我是PostgreSQL的新手,您的帮助将非常热烈。

The master will normally only retain a limited amount of WAL in pg_xlog , controlled by the master's wal_keep_segments setting. 主机通常在pg_xlog仅保留有限数量的WAL, pg_xlog由主机的wal_keep_segments设置控制。 If the replica is too slow or disconnected for too long, the master will delete those transaction logs to ensure it can continue running without running out of disk space. 如果副本太慢或断开连接的时间太长,则主服务器将删除这些事务日志,以确保副本可以继续运行而不会用完磁盘空间。

If that happens the replica has no way to catch up to the master, since it needs a continuous and gap-free stream of WAL. 如果发生这种情况,副本将无法追上原版,因为它需要连续无间隙的WAL流。

So you can: 所以你可以:

  • Enable WAL archiving ( archive_command and archive_mode ) as a fallback, so the replica can switch to replaying WAL from archives if the master deletes WAL it needs from its pg_xlog . 启用WAL归档( archive_commandarchive_mode )作为后备,因此,如果主服务器从pg_xlog删除所需的WAL,则副本可以切换到从归档重放WAL。 The replica fetches the WAL with its restore_command . 副本使用其restore_command获取WAL。 Importantly, the archived WAL does not need to be on the same machine as the master, and usually isn't. 重要的是,存档的WAL不必与主服务器在同一台计算机上,通常也不需要。

or 要么

  • Use a physical replication slot ( primary_slot_name in recovery.conf ) to connect the replica to the master. 使用物理复制插槽( recovery.conf primary_slot_name )将副本连接到主数据库。 If a slot is used, the master knows what WAL the replica requires even when the replica is disconnected. 如果使用插槽,则即使副本断开连接,主服务器也知道副本需要什么WAL。 So it won't remove WAL still needed by a replica from pg_xlog . 因此,它不会从pg_xlog删除副本仍然需要的WAL。 But the downside is that pg_xlog can fill up if a replica is down for too long, causing the master to fail due to lack of disk space. 但是缺点是,如果副本关闭时间太长, pg_xlog可能会填满,从而由于磁盘空间不足而导致主服务器失败。

or 要么

  • Do neither, and allow replicas to fail if they fall too far behind. 不执行任何操作,如果副本落后太久,则允许副本失败。 Then re-create them from a new base backup if this happens. 如果发生这种情况,然后从新的基本备份中重新创建它们。

The documentation really needs an overview piece to put all this together. 文档确实需要一个概述,以将所有这些内容放在一起。

WAL archiving has an additional benefit: If you make a base backup of the server you can use it, plus WAL archives, to do a point-in-time restore of the master. WAL归档还有另一个好处:如果对服务器进行基本备份 ,则可以使用它以及WAL存档来对主数据库进行时间点还原 This lets you recover data from things like accidental table drops. 这使您可以从意外表丢失之类的事件中恢复数据。 PgBarman is one of the tools that can help you with this. PgBarman是可以帮助您解决此问题的工具之一。

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

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