ALTER_PUBLICATION(7pg17)
π 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:
SETclause β 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.ADDandDROPclauses β 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 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 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. ifONLYis specified before the table name, only that table is affected. ifONLYis 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 byCREATE 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 π
CREATE PUBLICATION(CREATE_PUBLICATION(7))DROP PUBLICATION(DROP_PUBLICATION(7))CREATE SUBSCRIPTION(CREATE_SUBSCRIPTION(7))ALTER SUBSCRIPTION(ALTER_SUBSCRIPTION(7))
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
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-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