ALTER_PUBLICATION(7pg16)

πŸ“¦ version 16.15, in opensuse-leap 16.0

✨ ALTER PUBLICATION πŸ’…

okay bestie, so this is the ALTER PUBLICATION page from the PostgreSQL 16 docs β€” it's the one that lets you remix an existing publication (you know, the thing logical replication uses to decide what gets sent out). Think of it as the glam makeover command for your replication setup. πŸŽ€


🌸 SYNOPSIS 🌸

ALTER PUBLICATION name ADD publication_object [, ...]
ALTER PUBLICATION name SET publication_object [, ...]
ALTER PUBLICATION name DROP publication_drop_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 table_and_columns [, ... ]
    TABLES IN SCHEMA { schema_name | CURRENT_SCHEMA } [, ... ]

and publication_drop_object is one of:

    TABLE [ ONLY ] table_name [ * ] [, ... ]
    TABLES IN SCHEMA { schema_name | CURRENT_SCHEMA } [, ... ]

and table_and_columns is:

    [ ONLY ] table_name [ * ] [ ( column_name [, ... ] ) ] [ WHERE ( expression ) ]

πŸ¦‹ DESCRIPTION πŸ¦‹

So ALTER PUBLICATION changes the attributes of a publication. That's the whole vibe. πŸ’«

The first three variants are the ones that change which tables/schemas are part of the publication:

  • The SET clause replaces the whole list of tables/schemas in the publication with the list you give it β€” meaning the existing tables/schemas that were already in there get removed. It's giving full glow-up, not a touch-up. πŸ’…
  • The ADD and DROP clauses add and remove one or more tables/schemas from the publication.
⚠️ lowkey important: adding tables/schemas to a publication that's already subscribed to needs an ALTER SUBSCRIPTION ... REFRESH PUBLICATION action on the subscribing side before it actually takes effect. No cap, it just won't kick in otherwise.
πŸ™ˆ also note: DROP TABLES IN SCHEMA will not drop any schema tables that were specified using FOR TABLE/ADD TABLE. Those were added a different way, so they leave a different way. iykyk.

The fourth variant in the synopsis (the SET ( publication_parameter [= value] [, ... ] ) one) can change all the publication properties that were originally specified in CREATE PUBLICATION (CREATE_PUBLICATION(7)). Any properties you don't mention in the command just keep their previous settings. Very "if you don't bring it up, we're not changing it" of it. ✨

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


Now the permission tea β˜• (this part is serious, bestie):

  • You must own the publication to use ALTER PUBLICATION.
  • Adding a table to a publication additionally requires owning that table. Own your stuff, periodt.
  • 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. Main character energy, honestly. πŸ’€
🚨 One more hard no: adding/setting any schema when the publication also publishes a table with a column list β€” or the reverse β€” is not supported. Pick a lane.

πŸ’– PARAMETERS πŸ’–

  • name β€” the name of an existing publication whose definition is about to get altered. Yes, it has to already exist. We're editing, not creating.
  • table_name β€” name of an existing table. Details, because they matter:
    • 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 (CREATE_PUBLICATION(7)) for the deets. Heads up though: 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 the 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. That's it, that's the whole thing. ✨
  • SET ( publication_parameter [= value] [, ... ] ) β€” this clause alters publication parameters originally set by CREATE PUBLICATION (CREATE_PUBLICATION(7)). Go look over there for more info, it's all documented.
  • new_owner β€” the user name of the new owner of the publication.
  • new_name β€” the new name for the publication. Rebrand era. πŸ¦‹

🌈 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 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, TABLES IN SCHEMA production;

⭐ COMPATIBILITY ⭐

ALTER PUBLICATION is a PostgreSQL extension. So like, don't go looking for it in other databases. It's ours. πŸ’…


πŸ“ SEE ALSO πŸ“


okay that's the whole page, go forth and alter your publications responsibly πŸ§šπŸ’œ β€” this one's from PostgreSQL 16.15, dated 2026, and it lives at ALTER PUBLICATION(7). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from