ALTER_PUBLICATION(7pg16)
β¨ 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
SETclause 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
ADDandDROPclauses 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 SCHEMAwill not drop any schema tables that were specified usingFOR 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 SCHEMAandSET TABLES IN SCHEMAto a publication requires the invoking user to be a superuser. π - To alter the owner, you must be able to
SET ROLEto the new owning role, and that role must haveCREATEprivilege on the database. - Also, the new owner of a
FOR ALL TABLESorFOR TABLES IN SCHEMApublication 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
ONLYis specified before the table name, only that table is affected. - If
ONLYis 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
WHEREclause 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.
- If
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 byCREATE 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 π
CREATE PUBLICATION(CREATE_PUBLICATION(7))DROP PUBLICATION(DROP_PUBLICATION(7))CREATE SUBSCRIPTION(CREATE_SUBSCRIPTION(7))ALTER SUBSCRIPTION(ALTER_SUBSCRIPTION(7))
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
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms