1CREATE SUBSCRIPTION(7) PostgreSQL 12.6 Documentation CREATE SUBSCRIPTION(7)
2
3
4
6 CREATE_SUBSCRIPTION - define a new subscription
7
9 CREATE SUBSCRIPTION subscription_name
10 CONNECTION 'conninfo'
11 PUBLICATION publication_name [, ...]
12 [ WITH ( subscription_parameter [= value] [, ... ] ) ]
13
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 30.2 and Chapter 30.
29
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 33.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. The default value is off.
72
73 It is safe to use off for logical replication: If the
74 subscriber loses transactions because of missing
75 synchronization, the data will be sent again from the
76 publisher.
77
78 A different setting might be appropriate when doing synchronous
79 logical replication. The logical replication workers report the
80 positions of writes and flushes to the publisher, and when
81 using synchronous replication, the publisher will wait for the
82 actual flush. This means that setting synchronous_commit for
83 the subscriber to off when the subscription is used for
84 synchronous replication might increase the latency for COMMIT
85 on the publisher. In this scenario, it can be advantageous to
86 set synchronous_commit to local or higher.
87
88 connect (boolean)
89 Specifies whether the CREATE SUBSCRIPTION should connect to the
90 publisher at all. Setting this to false will change default
91 values of enabled, create_slot and copy_data to false.
92
93 It is not allowed to combine connect set to false and enabled,
94 create_slot, or copy_data set to true.
95
96 Since no connection is made when this option is set to false,
97 the tables are not subscribed, and so after you enable the
98 subscription nothing will be replicated. It is required to run
99 ALTER SUBSCRIPTION ... REFRESH PUBLICATION in order for tables
100 to be subscribed.
101
102
104 See Section 30.7 for details on how to configure access control between
105 the subscription and the publication instance.
106
107 When creating a replication slot (the default behavior), CREATE
108 SUBSCRIPTION cannot be executed inside a transaction block.
109
110 Creating a subscription that connects to the same database cluster (for
111 example, to replicate between databases in the same cluster or to
112 replicate within the same database) will only succeed if the
113 replication slot is not created as part of the same command. Otherwise,
114 the CREATE SUBSCRIPTION call will hang. To make this work, create the
115 replication slot separately (using the function
116 pg_create_logical_replication_slot with the plugin name pgoutput) and
117 create the subscription using the parameter create_slot = false. This
118 is an implementation restriction that might be lifted in a future
119 release.
120
122 Create a subscription to a remote server that replicates tables in the
123 publications mypublication and insert_only and starts replicating
124 immediately on commit:
125
126 CREATE SUBSCRIPTION mysub
127 CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb'
128 PUBLICATION mypublication, insert_only;
129
130 Create a subscription to a remote server that replicates tables in the
131 insert_only publication and does not start replicating until enabled at
132 a later time.
133
134 CREATE SUBSCRIPTION mysub
135 CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb'
136 PUBLICATION insert_only
137 WITH (enabled = false);
138
140 CREATE SUBSCRIPTION is a PostgreSQL extension.
141
143 ALTER SUBSCRIPTION (ALTER_SUBSCRIPTION(7)), DROP SUBSCRIPTION
144 (DROP_SUBSCRIPTION(7)), CREATE PUBLICATION (CREATE_PUBLICATION(7)),
145 ALTER PUBLICATION (ALTER_PUBLICATION(7))
146
147
148
149PostgreSQL 12.6 2021 CREATE SUBSCRIPTION(7)