1CREATE SUBSCRIPTION(7)   PostgreSQL 11.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. 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 resent from the publisher.
76
77               A different setting might be appropriate when doing synchronous
78               logical replication. The logical replication workers report the
79               positions of writes and flushes to the publisher, and when
80               using synchronous replication, the publisher will wait for the
81               actual flush. This means that setting synchronous_commit for
82               the subscriber to off when the subscription is used for
83               synchronous replication might increase the latency for COMMIT
84               on the publisher. In this scenario, it can be advantageous to
85               set synchronous_commit to local or higher.
86
87           connect (boolean)
88               Specifies whether the CREATE SUBSCRIPTION should connect to the
89               publisher at all. Setting this to false will change default
90               values of enabled, create_slot and copy_data to false.
91
92               It is not allowed to combine connect set to false and enabled,
93               create_slot, or copy_data set to true.
94
95               Since no connection is made when this option is set to false,
96               the tables are not subscribed, and so after you enable the
97               subscription nothing will be replicated. It is required to run
98               ALTER SUBSCRIPTION ... REFRESH PUBLICATION in order for tables
99               to be subscribed.
100
101

NOTES

103       See Section 31.7 for details on how to configure access control between
104       the subscription and the publication instance.
105
106       When creating a replication slot (the default behavior), CREATE
107       SUBSCRIPTION cannot be executed inside a transaction block.
108
109       Creating a subscription that connects to the same database cluster (for
110       example, to replicate between databases in the same cluster or to
111       replicate within the same database) will only succeed if the
112       replication slot is not created as part of the same command. Otherwise,
113       the CREATE SUBSCRIPTION call will hang. To make this work, create the
114       replication slot separately (using the function
115       pg_create_logical_replication_slot with the plugin name pgoutput) and
116       create the subscription using the parameter create_slot = false. This
117       is an implementation restriction that might be lifted in a future
118       release.
119

EXAMPLES

121       Create a subscription to a remote server that replicates tables in the
122       publications mypublication and insert_only and starts replicating
123       immediately on commit:
124
125           CREATE SUBSCRIPTION mysub
126                    CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb'
127                   PUBLICATION mypublication, insert_only;
128
129       Create a subscription to a remote server that replicates tables in the
130       insert_only publication and does not start replicating until enabled at
131       a later time.
132
133           CREATE SUBSCRIPTION mysub
134                    CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb'
135                   PUBLICATION insert_only
136                          WITH (enabled = false);
137

COMPATIBILITY

139       CREATE SUBSCRIPTION is a PostgreSQL extension.
140

SEE ALSO

142       ALTER SUBSCRIPTION (ALTER_SUBSCRIPTION(7)), DROP SUBSCRIPTION
143       (DROP_SUBSCRIPTION(7)), CREATE PUBLICATION (CREATE_PUBLICATION(7)),
144       ALTER PUBLICATION (ALTER_PUBLICATION(7))
145
146
147
148PostgreSQL 11.3                      2019               CREATE SUBSCRIPTION(7)
Impressum