1CREATE SUBSCRIPTION(7)   PostgreSQL 14.3 Documentation  CREATE SUBSCRIPTION(7)
2
3
4

NAME

6       CREATE_SUBSCRIPTION - define a new subscription
7

SYNOPSIS

9       CREATE SUBSCRIPTION subscription_name
10           CONNECTION 'conninfo'
11           PUBLICATION publication_name [, ...]
12           [ WITH ( subscription_parameter [= value] [, ... ] ) ]
13

DESCRIPTION

15       CREATE SUBSCRIPTION adds a new subscription for the current database.
16       The subscription name must be distinct from the name of any existing
17       subscription in the database.
18
19       The subscription represents a replication connection to the publisher.
20       As such this command does not only add definitions in the local
21       catalogs but also creates a replication slot on the publisher.
22
23       A logical replication worker will be started to replicate data for the
24       new subscription at the commit of the transaction where this command is
25       run.
26
27       Additional information about subscriptions and logical replication as a
28       whole is available at Section 31.2 and Chapter 31.
29

PARAMETERS

31       subscription_name
32           The name of the new subscription.
33
34       CONNECTION 'conninfo'
35           The connection string to the publisher. For details see
36           Section 34.1.1.
37
38       PUBLICATION publication_name
39           Names of the publications on the publisher to subscribe to.
40
41       WITH ( subscription_parameter [= value] [, ... ] )
42           This clause specifies optional parameters for a subscription. The
43           following parameters are supported:
44
45           copy_data (boolean)
46               Specifies whether the existing data in the publications that
47               are being subscribed to should be copied once the replication
48               starts. The default is true.
49
50           create_slot (boolean)
51               Specifies whether the command should create the replication
52               slot on the publisher. The default is true.
53
54           enabled (boolean)
55               Specifies whether the subscription should be actively
56               replicating, or whether it should be just setup but not started
57               yet. The default is true.
58
59           slot_name (string)
60               Name of the replication slot to use. The default behavior is to
61               use the name of the subscription for the slot name.
62
63               When slot_name is set to NONE, there will be no replication
64               slot associated with the subscription. This can be used if the
65               replication slot will be created later manually. Such
66               subscriptions must also have both enabled and create_slot set
67               to false.
68
69           synchronous_commit (enum)
70               The value of this parameter overrides the synchronous_commit
71               setting within this subscription's apply worker processes. The
72               default value is off.
73
74               It is safe to use off for logical replication: If the
75               subscriber loses transactions because of missing
76               synchronization, the data will be sent again from the
77               publisher.
78
79               A different setting might be appropriate when doing synchronous
80               logical replication. The logical replication workers report the
81               positions of writes and flushes to the publisher, and when
82               using synchronous replication, the publisher will wait for the
83               actual flush. This means that setting synchronous_commit for
84               the subscriber to off when the subscription is used for
85               synchronous replication might increase the latency for COMMIT
86               on the publisher. In this scenario, it can be advantageous to
87               set synchronous_commit to local or higher.
88
89           binary (boolean)
90               Specifies whether the subscription will request the publisher
91               to send the data in binary format (as opposed to text). The
92               default is false. Even when this option is enabled, only data
93               types that have binary send and receive functions will be
94               transferred in binary.
95
96               When doing cross-version replication, it could happen that the
97               publisher has a binary send function for some data type, but
98               the subscriber lacks a binary receive function for the type. In
99               such a case, data transfer will fail, and the binary option
100               cannot be used.
101
102           connect (boolean)
103               Specifies whether the CREATE SUBSCRIPTION should connect to the
104               publisher at all. Setting this to false will change default
105               values of enabled, create_slot and copy_data to false.
106
107               It is not allowed to combine connect set to false and enabled,
108               create_slot, or copy_data set to true.
109
110               Since no connection is made when this option is set to false,
111               the tables are not subscribed, and so after you enable the
112               subscription nothing will be replicated. It is required to run
113               ALTER SUBSCRIPTION ... REFRESH PUBLICATION in order for tables
114               to be subscribed.
115
116           streaming (boolean)
117               Specifies whether streaming of in-progress transactions should
118               be enabled for this subscription. By default, all transactions
119               are fully decoded on the publisher, and only then sent to the
120               subscriber as a whole.
121

NOTES

123       See Section 31.7 for details on how to configure access control between
124       the subscription and the publication instance.
125
126       When creating a replication slot (the default behavior), CREATE
127       SUBSCRIPTION cannot be executed inside a transaction block.
128
129       Creating a subscription that connects to the same database cluster (for
130       example, to replicate between databases in the same cluster or to
131       replicate within the same database) will only succeed if the
132       replication slot is not created as part of the same command. Otherwise,
133       the CREATE SUBSCRIPTION call will hang. To make this work, create the
134       replication slot separately (using the function
135       pg_create_logical_replication_slot with the plugin name pgoutput) and
136       create the subscription using the parameter create_slot = false. This
137       is an implementation restriction that might be lifted in a future
138       release.
139

EXAMPLES

141       Create a subscription to a remote server that replicates tables in the
142       publications mypublication and insert_only and starts replicating
143       immediately on commit:
144
145           CREATE SUBSCRIPTION mysub
146                    CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb'
147                   PUBLICATION mypublication, insert_only;
148
149       Create a subscription to a remote server that replicates tables in the
150       insert_only publication and does not start replicating until enabled at
151       a later time.
152
153           CREATE SUBSCRIPTION mysub
154                    CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb'
155                   PUBLICATION insert_only
156                          WITH (enabled = false);
157

COMPATIBILITY

159       CREATE SUBSCRIPTION is a PostgreSQL extension.
160

SEE ALSO

162       ALTER SUBSCRIPTION (ALTER_SUBSCRIPTION(7)), DROP SUBSCRIPTION
163       (DROP_SUBSCRIPTION(7)), CREATE PUBLICATION (CREATE_PUBLICATION(7)),
164       ALTER PUBLICATION (ALTER_PUBLICATION(7))
165
166
167
168PostgreSQL 14.3                      2022               CREATE SUBSCRIPTION(7)
Impressum