ALTER PUBLICATION

ALTER PUBLICATION

7

SQL - Language Statements

ALTER PUBLICATION

change the definition of a publication

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

) \] \[, \... \] ALL TABLES IN SCHEMA {

schema\_name

\| CURRENT\_SCHEMA } \[, \... \]

Description
===========

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

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 the combination of
`DROP` with a `WHERE` clause is not allowed.

The fourth variant of this command listed in the synopsis can change all
of the publication properties specified in
[???](#sql-createpublication). Properties not mentioned in the command
retain their previous settings.

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

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

Adding/Setting a table that is part of schema specified in
`ALL TABLES IN SCHEMA`, adding/setting a schema to a publication that
already has a table that is part of the specified schema or
adding/setting a table to a publication that already has a table\'s
schema as part of the specified schema 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
    [???](#sql-createpublication) for details.

    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
    [???](#sql-createpublication). 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;

Add schemas marketing and sales to the publication sales\_publication:

    ALTER PUBLICATION sales_publication ADD ALL TABLES IN SCHEMA marketing, sales;

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

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

Compatibility
=============

`ALTER PUBLICATION` is a PostgreSQL extension.

See Also
========
