ALTER_SUBSCRIPTION(7)
โจ ALTER_SUBSCRIPTION โจ
okay bestie, so this page is literally called ALTER_SUBSCRIPTION and it lives in the PostgreSQL 18.6 manual ๐ it's the glow-up page for your subscriptions โ the place where you change the definition of a subscription after you've already made it. no cap.
๐ธ NAME ๐ธ
ALTER_SUBSCRIPTION โ change the definition of a subscription ๐ฆ
๐ SYNOPSIS ๐
ALTER SUBSCRIPTION name CONNECTION 'conninfo'
ALTER SUBSCRIPTION name SET PUBLICATION publication_name [, ...] [ WITH ( publication_option [= value] [, ... ] ) ]
ALTER SUBSCRIPTION name ADD PUBLICATION publication_name [, ...] [ WITH ( publication_option [= value] [, ... ] ) ]
ALTER SUBSCRIPTION name DROP PUBLICATION publication_name [, ...] [ WITH ( publication_option [= value] [, ... ] ) ]
ALTER SUBSCRIPTION name REFRESH PUBLICATION [ WITH ( refresh_option [= value] [, ... ] ) ]
ALTER SUBSCRIPTION name ENABLE
ALTER SUBSCRIPTION name DISABLE
ALTER SUBSCRIPTION name SET ( subscription_parameter [= value] [, ... ] )
ALTER SUBSCRIPTION name SKIP ( skip_option = value )
ALTER SUBSCRIPTION name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER SUBSCRIPTION name RENAME TO new_name
look at all those forms, she's versatile ๐
๐ DESCRIPTION ๐
so ALTER SUBSCRIPTION can change most of the subscription properties that you'd set in CREATE SUBSCRIPTION (CREATE_SUBSCRIPTION(7)). not all, but most. she ate.
You must own the subscription to use ALTER SUBSCRIPTION. To rename a subscription or alter the owner, you need CREATE permission on the database. And lowkey on top of that โ to alter the owner, you must be able to SET ROLE to the new owning role. If the subscription has password_required=false, only superusers can modify it. ๐
When refreshing a publication we remove the relations that are no longer part of the publication, and we also remove the table synchronization slots if there are any. why tho? bc it's necessary to remove these slots so that the resources allocated for the subscription on the remote host are released. fr fr, don't skip that. If due to network breakdown or some other error, PostgreSQL is unable to remove the slots, an error will be reported ๐ญ. To proceed in this situation, the user either needs to retry the operation or disassociate the slot from the subscription and drop the subscription as explained in DROP SUBSCRIPTION (DROP_SUBSCRIPTION(7)).
not me being dramatic but this next part matters: these commands cannot be executed inside a transaction block ๐ซ -ALTER SUBSCRIPTION ... REFRESH PUBLICATION-ALTER SUBSCRIPTION ... {SET|ADD|DROP} PUBLICATION ...with refresh option astrue-ALTER SUBSCRIPTION ... SET (failover = true|false)-ALTER SUBSCRIPTION ... SET (two_phase = false)
Commands ALTER SUBSCRIPTION ... REFRESH PUBLICATION and ALTER SUBSCRIPTION ... {SET|ADD|DROP} PUBLICATION ... with refresh option as true also cannot be executed when the subscription has two-phase commit enabled, unless copy_data is false. ๐ See column subtwophasestate of pg_subscription to know the actual two-phase state. iykyk.
๐ PARAMETERS ๐
nameโ the name of a subscription whose properties are to be altered. just the name bestie.CONNECTION 'conninfo'โ this clause replaces the connection string originally set byCREATE SUBSCRIPTION(CREATE_SUBSCRIPTION(7)). See there for more information. ๐ซถSET PUBLICATION publication_nameADD PUBLICATION publication_nameDROP PUBLICATION publication_name
These forms change the list of subscribed publications. SET replaces the entire list of publications with a new list, ADD adds additional publications to the list of publications, and DROP removes the publications from the list of publications. We allow non-existent publications to be specified in ADD and SET variants so that users can add those later ๐. See CREATE SUBSCRIPTION (CREATE_SUBSCRIPTION(7)) for more information. By default, this command will also act like REFRESH PUBLICATION.
publication_option specifies additional options for this operation. The supported options are:
refresh(boolean) โ whenfalse, the command will not try to refresh table information.REFRESH PUBLICATIONshould then be executed separately. The default istrue. โจ
Additionally, the options described under REFRESH PUBLICATION may be specified, to control the implicit refresh operation.
REFRESH PUBLICATIONโ fetch missing table information from publisher. This will start replication of tables that were added to the subscribed-to publications sinceCREATE SUBSCRIPTIONor the last invocation ofREFRESH PUBLICATION. ๐ธ
refresh_option specifies additional options for the refresh operation. The supported options are:
copy_data(boolean) โ specifies whether to copy pre-existing data in the publications that are being subscribed to when the replication starts. The default istrue.
Previously subscribed tables are not copied, even if a table's row filter WHERE clause has since been modified. ๐
See Notes for details of how copy_data = true can interact with the origin parameter.
See the binary parameter of CREATE SUBSCRIPTION for details about copying pre-existing data in binary format.
ENABLEโ enables a previously disabled subscription, starting the logical replication worker at the end of the transaction. she's back ๐DISABLEโ disables a running subscription, stopping the logical replication worker at the end of the transaction. rest era ๐ดSET ( subscription_parameter [= value] [, ... ] )โ this clause alters parameters originally set byCREATE SUBSCRIPTION(CREATE_SUBSCRIPTION(7)). See there for more information. The parameters that can be altered areslot_name,synchronous_commit,binary,streaming,disable_on_error,password_required,run_as_owner,origin,failover, andtwo_phase. Only a superuser can setpassword_required = false. ๐
When altering the slot_name, the failover and two_phase property values of the named slot may differ from the counterpart failover and two_phase parameters specified in the subscription. When creating the slot, ensure the slot properties failover and two_phase match their counterpart parameters of the subscription. Otherwise, the slot on the publisher may behave differently from what these subscription options say: for example, the slot on the publisher could either be synced to the standbys even when the subscription's failover option is disabled or could be disabled for sync even when the subscription's failover option is enabled. ๐จ
The failover and two_phase parameters can only be altered when the subscription is disabled.
When altering two_phase from true to false, the backend process reports an error if any prepared transactions done by the logical replication worker (from when two_phase parameter was still true) are found. You can resolve prepared transactions on the publisher node, or manually roll them back on the subscriber, and then try again. The transactions prepared by logical replication worker corresponding to a particular subscription have the following pattern: โpg_gid_%u_%uโ (parameters: subscription oid, remote transaction id xid). To resolve such transactions manually, you need to roll back all the prepared transactions with corresponding subscription IDs in their names. Applications can check pg_prepared_xacts to find the required prepared transactions. After the two_phase option is changed from true to false, the publisher will replicate the transactions again when they are committed. ๐ฆ
SKIP ( skip_option = value )โ skips applying all changes of the remote transaction. If incoming data violates any constraints, logical replication will stop until it is resolved. By using theALTER SUBSCRIPTION ... SKIPcommand, the logical replication worker skips all data modification changes within the transaction. This option has no effect on the transactions that are already prepared by enablingtwo_phaseon the subscriber. After the logical replication worker successfully skips the transaction or finishes a transaction, the LSN (stored inpg_subscription.subskiplsn) is cleared. See Section 29.7 for the details of logical replication conflicts. ๐ค
skip_option specifies options for this operation. The supported option is:
lsn(pg_lsn) โ specifies the finish LSN of the remote transaction whose changes are to be skipped by the logical replication worker. The finish LSN is the LSN at which the transaction is either committed or prepared. Skipping individual subtransactions is not supported. SettingNONEresets the LSN. โญ
new_ownerโ the user name of the new owner of the subscription. ๐new_nameโ the new name for the subscription. rebrand era ๐
When specifying a parameter of type boolean, the = value part can be omitted, which is equivalent to specifying TRUE. (so SET (failover) hits the same as SET (failover = true), you're welcome ๐)
๐ฆ EXAMPLES ๐ฆ
Change the publication subscribed by a subscription to insert_only:
ALTER SUBSCRIPTION mysub SET PUBLICATION insert_only;
Disable (stop) the subscription:
ALTER SUBSCRIPTION mysub DISABLE;
so clean, so simple, periodt โจ
๐ COMPATIBILITY ๐
ALTER SUBSCRIPTION is a PostgreSQL extension. (she's homegrown, a limited edition ๐
)
๐ซถ SEE ALSO ๐ซถ
CREATE SUBSCRIPTION (CREATE_SUBSCRIPTION(7)), DROP SUBSCRIPTION (DROP_SUBSCRIPTION(7)), CREATE PUBLICATION (CREATE_PUBLICATION(7)), ALTER PUBLICATION (ALTER_PUBLICATION(7))
and that's the whole page bestie ๐ that was PostgreSQL 18.6, dated 2026, and this manual page was ALTER SUBSCRIPTION(7) the entire time ๐ mwah, go alter something ๐
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms