ALTER_SUBSCRIPTION(7pg17)
π ALTER SUBSCRIPTION (7pg17)
okay bestie, welcome to the glow-up page for ALTER SUBSCRIPTION β that's the PostgreSQL 17.11 documentation manual, if the header didn't already spill the tea β¨. This is the command that changes the definition of a subscription, and honestly? it's giving main character energy π
β¨ SYNOPSIS β¨
like, here's the whole menu, verbatim, no cap:
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
π DESCRIPTION π
ALTER SUBSCRIPTION can change most of the subscription properties that you could've specified in CREATE SUBSCRIPTION (CREATE_SUBSCRIPTION(7)). so basically it's the character-development arc for your subscription π¦
You must own the subscription to use ALTER SUBSCRIPTION β no borrowing your friend's subscription, sorry π. To rename a subscription or alter the owner, you need CREATE permission on the database. And on top of that, to alter the owner you must be able to SET ROLE to the new owning role. Oh and β if the subscription has password_required=false, only superusers can modify it. periodt π
πΈ the refreshing-slots lore
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, you ask? Because it is necessary to remove these slots so that the resources allocated for the subscription on the remote host are released. resource hygiene, we love to see it π§
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 inDROP SUBSCRIPTION(DROP_SUBSCRIPTION(7)).
π₯ the "can't do this inside a transaction block" list
These commands cannot be executed inside a transaction block π«:
ALTER SUBSCRIPTION ... REFRESH PUBLICATIONALTER SUBSCRIPTION ... {SET|ADD|DROP} PUBLICATION ...with refresh option astrueALTER SUBSCRIPTION ... SET (failover = true|false)
π the two-phase commit situation
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. its little name tag π·οΈCONNECTION 'conninfo'β this clause replaces the connection string originally set byCREATE SUBSCRIPTION(CREATE_SUBSCRIPTION(7)). See there for more information. it's the glow-up of your connection string β¨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. (manifesting them into existence, basically π) 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. like catching up on the group chat π
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. we stan a comeback era π₯DISABLEβ disables a running subscription, stopping the logical replication worker at the end of the transaction. it's not you it's me π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, andfailover. 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. mismatch = messy, bestie π
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.6 for the details of logical replication conflicts. just scroll past it, bestie π
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. the new parent, if you will π«Άnew_nameβ the new name for the subscription. rebranding szn πΈ
π‘ When specifying a parameter of typeboolean, the= valuepart can be omitted, which is equivalent to specifyingTRUE. lazy-girl hack, but make it SQL π
β 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;
okay those two are literally so clean, ate β¨
π¦ COMPATIBILITY π¦
ALTER SUBSCRIPTION is a PostgreSQL extension. homegrown, iconic, no notes π
π SEE ALSO π
CREATE SUBSCRIPTION(CREATE_SUBSCRIPTION(7))DROP SUBSCRIPTION(DROP_SUBSCRIPTION(7))CREATE PUBLICATION(CREATE_PUBLICATION(7))ALTER PUBLICATION(ALTER_PUBLICATION(7))
the whole friend group, fr fr π«Ά
okay that's the whole page, bestie π this was PostgreSQL 17.11 documentation, dated 2026 β go forth and alter your subscriptions, and remember: you own the subscription, the subscription doesn't own you πβ¨π¦
π¦ 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