Postgresql 中文操作指南
31.1. Publication #
可以在任何物理复制主数据库上定义_publication_。定义发布的节点被称为_publisher_。发布是一组由表或一群表生成的更改,也可以描述为更改集或复制集。每个发布仅存在于一个数据库中。
A publication can be defined on any physical replication primary. The node where a publication is defined is referred to as publisher. A publication is a set of changes generated from a table or a group of tables, and might also be described as a change set or replication set. Each publication exists in only one database.
发布不同于模式,并且不影响访问表的方式。如有需要,每个表可以添加到多个发布中。目前发布仅可以包含模式中的表和所有表。必须明确添加对象,除非为_ALL TABLES_ 创建发布。
Publications are different from schemas and do not affect how the table is accessed. Each table can be added to multiple publications if needed. Publications may currently only contain tables and all tables in schema. Objects must be added explicitly, except when a publication is created for ALL TABLES.
发布可以选择将其产生的更改限制在 INSERT、UPDATE、DELETE 和 TRUNCATE 的任意组合,类似于由特定事件类型触发的触发器的方式。默认情况下,所有操作类型都是复制的。这些发布规范仅适用于 DML 操作;它们不会影响初始数据同步副本。(行过滤器对 TRUNCATE 没有影响。请参见 Section 31.3)。
Publications can choose to limit the changes they produce to any combination of INSERT, UPDATE, DELETE, and TRUNCATE, similar to how triggers are fired by particular event types. By default, all operation types are replicated. These publication specifications apply only for DML operations; they do not affect the initial data synchronization copy. (Row filters have no effect for TRUNCATE. See Section 31.3).
已发布表必须配置了 replica identity ,才能复制 UPDATE 和 DELETE 操作,以便可以在订阅者侧识别要更新或删除的适当行。默认情况下,如果存在主键,则这是主键。另一个唯一索引(具有某些其他要求)也可以设置为副本标识。如果表没有任何合适的键,则可以将其设置为副本标识 FULL ,这意味着整行成为键。当指定副本标识 FULL 时,可以在订阅者侧使用索引搜索行。候选索引必须是 btree、不含部分,并且最左端的索引字段必须是引用已发布表列的列(而不是表达式)。对非唯一索引属性的这些限制遵循对主键强制实施的部分限制。如果没有此类合适的索引,则在订阅者侧进行搜索效率极低,因此,仅当没有其他解决方案可用时,才应将副本标识 FULL 用作后备。如果在发布者侧设置了 FULL 以外的副本标识,则在订户侧还必须设置包含相同列或更少列的副本标识。有关如何设置副本标识的详细信息,请参阅 REPLICA IDENTITY 。如果将没有副本标识的表添加到复制 UPDATE 或 DELETE 操作的发布中,则随后的 UPDATE 或 DELETE 操作将在发布者上导致错误。无论是否存在副本标识, INSERT 操作都可以继续进行。
A published table must have a replica identity configured in order to be able to replicate UPDATE and DELETE operations, so that appropriate rows to update or delete can be identified on the subscriber side. By default, this is the primary key, if there is one. Another unique index (with certain additional requirements) can also be set to be the replica identity. If the table does not have any suitable key, then it can be set to replica identity FULL, which means the entire row becomes the key. When replica identity FULL is specified, indexes can be used on the subscriber side for searching the rows. Candidate indexes must be btree, non-partial, and the leftmost index field must be a column (not an expression) that references the published table column. These restrictions on the non-unique index properties adhere to some of the restrictions that are enforced for primary keys. If there are no such suitable indexes, the search on the subscriber side can be very inefficient, therefore replica identity FULL should only be used as a fallback if no other solution is possible. If a replica identity other than FULL is set on the publisher side, a replica identity comprising the same or fewer columns must also be set on the subscriber side. See REPLICA IDENTITY for details on how to set the replica identity. If a table without a replica identity is added to a publication that replicates UPDATE or DELETE operations then subsequent UPDATE or DELETE operations will cause an error on the publisher. INSERT operations can proceed regardless of any replica identity.
每个发布可以有多个订阅者。
Every publication can have multiple subscribers.
使用 CREATE PUBLICATION 命令创建发布,以后可以使用相应命令对其进行更改或废弃。
A publication is created using the CREATE PUBLICATION command and may later be altered or dropped using corresponding commands.
可以使用 ALTER PUBLICATION 动态添加和删除各个表。 ADD TABLE 和 DROP TABLE 操作都是事务性的;因此,一旦事务提交,表将在正确快照处开始或停止复制。
The individual tables can be added and removed dynamically using ALTER PUBLICATION. Both the ADD TABLE and DROP TABLE operations are transactional; so the table will start or stop replicating at the correct snapshot once the transaction has committed.