CREATE SUBSCRIPTION CREATE SUBSCRIPTION 7 SQL - Language Statements CREATE SUBSCRIPTION define a new subscription CREATE SUBSCRIPTION subscription_name CONNECTION 'conninfo' PUBLICATION { publication_name [, ...] } [ WITH ( option [, ... ] ) ] where option can be: | ENABLED | DISABLED | CREATE SLOT | NOCREATE SLOT | SLOT NAME = slot_name | COPY DATA | NOCOPY DATA | NOCONNECT Description CREATE SUBSCRIPTION adds a new subscription for a current database. The subscription name must be distinct from the name of any existing subscription in the database. The subscription represents a replication connection to the publisher. As such this command does not only add definitions in the local catalogs but also creates a replication slot on the publisher. A logical replication worker will be started to replicate data for the new subscription at the commit of the transaction where this command is run. CREATE SUBSCRIPTION cannot be executed inside a transaction block when CREATE SLOT is specified. Additional info about subscriptions and logical replication as a whole can is available at and . Parameters subscription_name The name of the new subscription. CONNECTION 'conninfo' The connection string to the publisher. For details see . PUBLICATION publication_name Name(s) of the publications on the publisher to subscribe to. ENABLED DISABLED Specifies whether the subscription should be actively replicating or if it should be just setup but not started yet. Note that the replication slot as described above is created in either case. ENABLED is the default. CREATE SLOT NOCREATE SLOT Specifies whether the command should create the replication slot on the publisher. CREATE SLOT is the default. SLOT NAME = slot_name Name of the replication slot to use. The default behavior is to use subscription_name for slot name. COPY DATA NOCOPY DATA Specifies if the existing data in the publications that are being subscribed to should be copied once the replication starts. COPY DATA is the default. NOCONNECT Instructs CREATE SUBSCRIPTION to skip the initial connection to the provider. This will change default values of other options to DISABLED, NOCREATE SLOT, and NOCOPY DATA. It's not allowed to combine NOCONNECT and ENABLED, CREATE SLOT, or COPY DATA. Since no connection is made when this option is specified, the tables are not subscribed, so after you enable the subscription nothing will be replicated. It is required to run ALTER SUBSCRIPTION ... REFRESH PUBLICATION in order for tables to be subscribed. Notes See for details on how to configure access control between the subscription and the publication instance. Examples Create a subscription to a remote server that replicates tables in the publications mypublication and insert_only and starts replicating immediately on commit: CREATE SUBSCRIPTION mysub CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb' PUBLICATION mypublication, insert_only; Create a subscription to a remote server that replicates tables in the insert_only publication and does not start replicating until enabled at a later time. CREATE SUBSCRIPTION mysub CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb' PUBLICATION insert_only WITH (DISABLED); Compatibility CREATE SUBSCRIPTION is a PostgreSQL extension. See Also