ALTER_PUBLICATION(7pg17)

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

πŸ’… ALTER PUBLICATION πŸ’…

okay so bestie, welcome to the PostgreSQL 17.11 Documentation page for ALTER PUBLICATION β€” it's one of the <italic>7</italic>-suffix manual pages (the SQL-command girlies, iykyk), and it's literally the glow-up command for your publications. let's get into it πŸŽ€


✨ 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 ) ]

like, look at all those variants. she's versatile. πŸ’…


🌸 DESCRIPTION 🌸

okay so ALTER PUBLICATION is the command that changes the attributes of a publication. simple as that. but the how depends on which variant you pick, so buckle up πŸ¦‹

the first three variants change which tables/schemas are part of the publication. here's the tea:

  • SET clause β†’ replaces the whole list of tables/schemas in the publication with the list you specified. the existing tables/schemas that were present in the publication get removed. it's giving delete-and-replace energy, not merge.
  • ADD and DROP clauses β†’ add and remove one or more tables/schemas from the publication. much chiller.
⚠️ 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. no cap, it literally won't kick in otherwise.

also note that DROP TABLES IN SCHEMA will not drop any schema tables that were specified using FOR TABLE/ADD TABLE. she does not touch those. πŸ™ˆ

the fourth variant (the SET ( publication_parameter [= value] [, ... ] ) one) can change all of the publication properties specified in CREATE PUBLICATION (CREATE_PUBLICATION(7)). properties not mentioned in the command retain their previous settings β€” she's not going to silently reset your other stuff, bestie. 🫢

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


🧚 who's allowed to do this

you must own the publication to use ALTER PUBLICATION. periodt. andddd:

  • 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. main character energy fr fr.
πŸ’€ one more huge caveat: adding/setting any schema when the publication also publishes a table with a column list, and vice versa, is not supported. that combo is a no. not supported. don't do it.

πŸŽ€ PARAMETERS πŸŽ€

  • name β€” the name of an existing publication whose definition is to be altered. yep, she must already exist.
  • 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 (CREATE_PUBLICATION(7)) 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 β€” yes, required, don't skip them. 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)). see there for more information. (go read that one too, bestie, it's the origin story.)
  • 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;

look at her go. five examples, all slaying. πŸ¦‹


🌈 COMPATIBILITY 🌈

ALTER PUBLICATION is a PostgreSQL extension. she's homegrown, not standard SQL. πŸ’œ


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie!! 🫢 this was PostgreSQL 17.11, dated 2026, filed under ALTER PUBLICATION(7) β€” go forth and alter your publications responsibly, mwah πŸ’–βœ¨πŸ“

πŸ“¦ where this page comes from