ALTER SUBSCRIPTION
ALTER SUBSCRIPTION — change the definition of a subscription
Synopsis
ALTER SUBSCRIPTIONnameCONNECTION 'conninfo' ALTER SUBSCRIPTIONnameSET PUBLICATIONpublication_name[, ...] [ WITH (publication_option[=value] [, ... ] ) ] ALTER SUBSCRIPTIONnameADD PUBLICATIONpublication_name[, ...] [ WITH (publication_option[=value] [, ... ] ) ] ALTER SUBSCRIPTIONnameDROP PUBLICATIONpublication_name[, ...] [ WITH (publication_option[=value] [, ... ] ) ] ALTER SUBSCRIPTIONnameREFRESH PUBLICATION [ WITH (refresh_option[=value] [, ... ] ) ] ALTER SUBSCRIPTIONnameENABLE ALTER SUBSCRIPTIONnameDISABLE ALTER SUBSCRIPTIONnameSET (subscription_parameter[=value] [, ... ] ) ALTER SUBSCRIPTIONnameOWNER TO {new_owner| CURRENT_ROLE | CURRENT_USER | SESSION_USER } ALTER SUBSCRIPTIONnameRENAME TOnew_name
Description
ALTER SUBSCRIPTION can change most of the subscription properties that can be specified in CREATE SUBSCRIPTION.
You must own the subscription to use ALTER SUBSCRIPTION. To alter the owner, you must also be a direct or indirect member of the new owning role. The new owner has to be a superuser. (Currently, all subscription owners must be superusers, so the owner checks will be bypassed in practice. But this might change in the future.)
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. It is necessary to remove these slots so that the resources allocated for the subscription on the remote host are released. 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.
Commands ALTER SUBSCRIPTION ... REFRESH PUBLICATION and ALTER SUBSCRIPTION ... {SET|ADD|DROP} PUBLICATION ... with refresh option as true cannot be executed inside a transaction block.
Parameters
nameThe name of a subscription whose properties are to be altered.
CONNECTION 'conninfo'This clause alters the connection property originally set by CREATE SUBSCRIPTION. See there for more information.
SET PUBLICATIONpublication_nameADD PUBLICATIONpublication_nameDROP PUBLICATIONpublication_nameChanges the list of subscribed publications.
SETreplaces the entire list of publications with a new list,ADDadds additional publications to the list of publications, andDROPremoves the publications from the list of publications. See CREATE SUBSCRIPTION for more information. By default, this command will also act likeREFRESH PUBLICATION.publication_optionspecifies additional options for this operation. The supported options are:refresh(boolean)When false, the command will not try to refresh table information.
REFRESH PUBLICATIONshould then be executed separately. The default istrue.
Additionally, the options described under
REFRESH PUBLICATIONmay be specified, to control the implicit refresh operation.REFRESH PUBLICATIONFetch missing table information from publisher. This will start replication of tables that were added to the subscribed-to publications since the last invocation of
REFRESH PUBLICATIONor sinceCREATE SUBSCRIPTION.refresh_optionspecifies additional options for the refresh operation. The supported options are:copy_data(boolean)Specifies whether the existing data in the publications that are being subscribed to should be copied once the replication starts. The default is
true. (Previously subscribed tables are not copied.)
ENABLEEnables the previously disabled subscription, starting the logical replication worker at the end of transaction.
DISABLEDisables the running subscription, stopping the logical replication worker at the end of transaction.
SET (subscription_parameter[=value] [, ... ] )This clause alters parameters originally set by CREATE SUBSCRIPTION. See there for more information. The parameters that can be altered are
slot_name,synchronous_commit,binary, andstreaming.new_ownerThe user name of the new owner of the subscription.
new_nameThe new name for the subscription.
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;
Compatibility
ALTER SUBSCRIPTION is a PostgreSQL extension.