Postgresql 中文操作指南

ALTER PUBLICATION

ALTER PUBLICATION — 更改发布的定义

ALTER PUBLICATION — change the definition of a publication

Synopsis

ALTER PUBLICATION name ADD publication_object [, ...]
ALTER PUBLICATION name SET publication_object [, ...]
ALTER PUBLICATION name DROP publication_object [, ...]
ALTER PUBLICATION name SET ( publication_parameter [= value] [, ... ] )
ALTER PUBLICATION name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER PUBLICATION name RENAME TO new_name

where publication_object is one of:

    TABLE [ ONLY ] table_name [ * ] [ ( column_name [, ... ] ) ] [ WHERE ( expression ) ] [, ... ]
    TABLES IN SCHEMA { schema_name | CURRENT_SCHEMA } [, ... ]

Description

命令 ALTER PUBLICATION 可以更改发布的属性。

The command ALTER PUBLICATION can change the attributes of a publication.

前三个 varient 更改了哪些表/模式是发布的一部分。 SET 子句将用指定列表替换发布中的表/模式列表;原来在发布中出现的表/模式将被删除。 ADDDROP 子句将向发布添加或从此发布删除一个或多个表/模式。请注意,向已被订阅的发布中添加表/模式需要订阅方执行 ALTER SUBSCRIPTION …​ REFRESH PUBLICATION 操作才能生效。另请注意, DROP TABLES IN SCHEMA 不会删除使用 FOR TABLE / ADD TABLE 指定的任何模式表,并且不允许将 DROPWHERE 子句结合使用。

The first three variants change which tables/schemas are part of the publication. The SET clause will replace the list of tables/schemas in the publication with the specified list; the existing tables/schemas that were present in the publication will be removed. The ADD and DROP clauses will add and remove one or more tables/schemas from the publication. Note that adding tables/schemas to a publication that is already subscribed to will require an ALTER SUBSCRIPTION …​ REFRESH PUBLICATION action on the subscribing side in order to become effective. Note also that DROP TABLES IN SCHEMA will not drop any schema tables that were specified using FOR TABLE/ ADD TABLE, and the combination of DROP with a WHERE clause is not allowed.

概要中列出的此命令的第四个 varient 可以更改 CREATE PUBLICATION 中指定的所有发布属性。命令中未提及的属性保留其以前设置。

The fourth variant of this command listed in the synopsis can change all of the publication properties specified in CREATE PUBLICATION. Properties not mentioned in the command retain their previous settings.

其余 varient 更改所有者和发布的名称。

The remaining variants change the owner and the name of the publication.

您必须拥有该发布才能使用 ALTER PUBLICATION 。将表添加到发布中还需要拥有该表。 ADD TABLES IN SCHEMASET TABLES IN SCHEMA 向发布中添加表需要调用用户为超级用户。要更改所有者,您必须能够 SET ROLE 至新的所有者角色,且该角色必须在数据库上具有 CREATE 特权。此外, FOR ALL TABLESFOR TABLES IN SCHEMA 发布的新所有者必须是超级用户。但是,超级用户可以更改发布的所有权,而无需考虑这些限制。

You must own the publication to use ALTER PUBLICATION. Adding a table to a publication additionally requires owning that table. The ADD TABLES IN SCHEMA and SET TABLES IN SCHEMA to a publication requires the invoking user to be a superuser. To alter the owner, you must be able to SET ROLE to the new owning role, and that role must have CREATE privilege on the database. Also, the new owner of a FOR ALL TABLES or FOR TABLES IN SCHEMA publication must be a superuser. However, a superuser can change the ownership of a publication regardless of these restrictions.

当发布也发布带有列列表的表格时,添加/设置任何模式,反之亦然不受支持。

Adding/Setting any schema when the publication also publishes a table with a column list, and vice versa is not supported.

Parameters

  • name

    • The name of an existing publication whose definition is to be altered.

  • table_name

    • Name of an existing table. If ONLY is specified before the table name, only that table is affected. If ONLY is not specified, the table and all its descendant tables (if any) are affected. Optionally, * can be specified after the table name to explicitly indicate that descendant tables are included.

    • Optionally, a column list can be specified. See CREATE PUBLICATION for details. Note that a subscription having several publications in which the same table has been published with different column lists is not supported. See Warning: Combining Column Lists from Multiple Publications for details of potential problems when altering column lists.

    • If the optional WHERE clause is specified, rows for which the expression evaluates to false or null will not be published. Note that parentheses are required around the expression. The expression is evaluated with the role used for the replication connection.

  • schema_name

    • Name of an existing schema.

  • SET ( _publication_parameter [= value] [, …​ ] )_

    • This clause alters publication parameters originally set by CREATE PUBLICATION. See there for more information.

  • new_owner

    • The user name of the new owner of the publication.

  • new_name

    • The new name for the publication.

Examples

将发布更改为仅发布删除和更新:

Change the publication to publish only deletes and updates:

ALTER PUBLICATION noinsert SET (publish = 'update, delete');

将一些表格添加到发布中:

Add some tables to the publication:

ALTER PUBLICATION mypublication ADD TABLE users (user_id, firstname), departments;

更改表格发布的列集:

Change the set of columns published for a table:

ALTER PUBLICATION mypublication SET TABLE users (user_id, firstname, lastname), TABLE departments;

将模式 marketingsales 添加到发布 sales_publication 中:

Add schemas marketing and sales to the publication sales_publication:

ALTER PUBLICATION sales_publication ADD TABLES IN SCHEMA marketing, sales;

将表 usersdepartments 和模式 production 添加到发布 production_publication 中:

Add tables users, departments and schema production to the publication production_publication:

ALTER PUBLICATION production_publication ADD TABLE users, departments, TABLES IN SCHEMA production;

Compatibility

ALTER PUBLICATION 是 PostgreSQL 扩展。

ALTER PUBLICATION is a PostgreSQL extension.