summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/ref/alter_subscription.sgml
blob: 353ea5def231ab9f8d10d914b1a0234b308ba858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<!--
doc/src/sgml/ref/alter_subscription.sgml
PostgreSQL documentation
-->

<refentry id="sql-altersubscription">
 <indexterm zone="sql-altersubscription">
  <primary>ALTER SUBSCRIPTION</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>ALTER SUBSCRIPTION</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>ALTER SUBSCRIPTION</refname>
  <refpurpose>change the definition of a subscription</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> CONNECTION '<replaceable>conninfo</replaceable>'
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> SET PUBLICATION <replaceable class="parameter">publication_name</replaceable> [, ...] [ WITH ( <replaceable class="parameter">publication_option</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> ADD PUBLICATION <replaceable class="parameter">publication_name</replaceable> [, ...] [ WITH ( <replaceable class="parameter">publication_option</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> DROP PUBLICATION <replaceable class="parameter">publication_name</replaceable> [, ...] [ WITH ( <replaceable class="parameter">publication_option</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> REFRESH PUBLICATION [ WITH ( <replaceable class="parameter">refresh_option</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> ENABLE
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> DISABLE
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> SET ( <replaceable class="parameter">subscription_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] )
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> SKIP ( <replaceable class="parameter">skip_option</replaceable> = <replaceable class="parameter">value</replaceable> )
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>ALTER SUBSCRIPTION</command> can change most of the subscription
   properties that can be specified
   in <xref linkend="sql-createsubscription"/>.
  </para>

  <para>
   You must own the subscription to use <command>ALTER SUBSCRIPTION</command>.
   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.)
  </para>

  <para>
   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, <productname>PostgreSQL</productname>
   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
   <xref linkend="sql-dropsubscription"/>.
  </para>

  <para>
   Commands <command>ALTER SUBSCRIPTION ... REFRESH PUBLICATION</command> and
   <command>ALTER SUBSCRIPTION ... {SET|ADD|DROP} PUBLICATION ...</command>
   with <literal>refresh</literal> option as <literal>true</literal> cannot be
   executed inside a transaction block.

   These commands also cannot be executed when the subscription has
   <literal>two_phase</literal> commit enabled,
   unless <literal>copy_data</literal> is <literal>false</literal>.
   See column <structfield>subtwophasestate</structfield> of
   <link linkend="catalog-pg-subscription"><structname>pg_subscription</structname></link>
   to know the actual two-phase state.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

  <variablelist>
   <varlistentry>
    <term><replaceable class="parameter">name</replaceable></term>
    <listitem>
     <para>
      The name of a subscription whose properties are to be altered.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>CONNECTION '<replaceable class="parameter">conninfo</replaceable>'</literal></term>
    <listitem>
     <para>
      This clause replaces the connection string originally set by
      <xref linkend="sql-createsubscription"/>.  See there for more
      information.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>SET PUBLICATION <replaceable class="parameter">publication_name</replaceable></literal></term>
    <term><literal>ADD PUBLICATION <replaceable class="parameter">publication_name</replaceable></literal></term>
    <term><literal>DROP PUBLICATION <replaceable class="parameter">publication_name</replaceable></literal></term>
    <listitem>
     <para>
      These forms change the list of subscribed publications.
      <literal>SET</literal>
      replaces the entire list of publications with a new list,
      <literal>ADD</literal> adds additional publications to the list of
      publications, and <literal>DROP</literal> removes the publications from
      the list of publications.  We allow non-existent publications to be
      specified in <literal>ADD</literal> and <literal>SET</literal> variants
      so that users can add those later.  See <xref linkend="sql-createsubscription"/>
      for more information.  By default, this command will also act like
      <literal>REFRESH PUBLICATION</literal>.
     </para>

     <para>
      <replaceable>publication_option</replaceable> specifies additional
      options for this operation.  The supported options are:

      <variablelist>
       <varlistentry>
        <term><literal>refresh</literal> (<type>boolean</type>)</term>
        <listitem>
         <para>
          When false, the command will not try to refresh table information.
          <literal>REFRESH PUBLICATION</literal> should then be executed separately.
          The default is <literal>true</literal>.
         </para>
        </listitem>
       </varlistentry>
      </variablelist>

      Additionally, the options described under
      <literal>REFRESH PUBLICATION</literal> may be specified, to control the
      implicit refresh operation.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>REFRESH PUBLICATION</literal></term>
    <listitem>
     <para>
      Fetch missing table information from publisher.  This will start
      replication of tables that were added to the subscribed-to publications
      since <command>CREATE SUBSCRIPTION</command> or
      the last invocation of <command>REFRESH PUBLICATION</command>.
     </para>

     <para>
      <replaceable>refresh_option</replaceable> specifies additional options for the
      refresh operation.  The supported options are:

      <variablelist>
       <varlistentry>
        <term><literal>copy_data</literal> (<type>boolean</type>)</term>
        <listitem>
         <para>
          Specifies whether to copy pre-existing data in the publications
          that are being subscribed to when the replication starts.
          The default is <literal>true</literal>.
         </para>
         <para>
          Previously subscribed tables are not copied, even if a table's row
          filter <literal>WHERE</literal> clause has since been modified.
         </para>
        </listitem>
       </varlistentry>
      </variablelist></para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>ENABLE</literal></term>
    <listitem>
     <para>
      Enables a previously disabled subscription, starting the logical
      replication worker at the end of the transaction.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>DISABLE</literal></term>
    <listitem>
     <para>
      Disables a running subscription, stopping the logical replication
      worker at the end of the transaction.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>SET ( <replaceable class="parameter">subscription_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] )</literal></term>
    <listitem>
     <para>
      This clause alters parameters originally set by
      <xref linkend="sql-createsubscription"/>.  See there for more
      information.  The parameters that can be altered
      are <literal>slot_name</literal>,
      <literal>synchronous_commit</literal>,
      <literal>binary</literal>, <literal>streaming</literal>, and
      <literal>disable_on_error</literal>.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>SKIP ( <replaceable class="parameter">skip_option</replaceable> = <replaceable class="parameter">value</replaceable> )</literal></term>
    <listitem>
     <para>
      Skips applying all changes of the remote transaction.  If incoming data
      violates any constraints, logical replication will stop until it is
      resolved.  By using the <command>ALTER SUBSCRIPTION ... SKIP</command> command,
      the logical replication worker skips all data modification changes within
      the transaction.  This option has no effect on the transactions that are
      already prepared by enabling <literal>two_phase</literal> on
      subscriber.
      After the logical replication worker successfully skips the transaction or
      finishes a transaction, the LSN (stored in
      <structname>pg_subscription</structname>.<structfield>subskiplsn</structfield>)
      is cleared.  See <xref linkend="logical-replication-conflicts"/> for
      the details of logical replication conflicts.  Using this command requires
      superuser privilege.
     </para>

     <para>
      <replaceable>skip_option</replaceable> specifies options for this operation.
      The supported option is:

      <variablelist>
       <varlistentry>
        <term><literal>lsn</literal> (<type>pg_lsn</type>)</term>
        <listitem>
         <para>
          Specifies the finish LSN of the remote transaction whose changes
          are to be skipped by the logical replication worker.  The finish LSN
          is the LSN at which the transaction is either committed or prepared.
          Skipping individual subtransactions is not supported.  Setting
          <literal>NONE</literal> resets the LSN.
         </para>
        </listitem>
       </varlistentry>
      </variablelist></para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">new_owner</replaceable></term>
    <listitem>
     <para>
      The user name of the new owner of the subscription.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">new_name</replaceable></term>
    <listitem>
     <para>
      The new name for the subscription.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1>
  <title>Examples</title>

  <para>
   Change the publication subscribed by a subscription to
   <literal>insert_only</literal>:
<programlisting>
ALTER SUBSCRIPTION mysub SET PUBLICATION insert_only;
</programlisting>
  </para>

  <para>
   Disable (stop) the subscription:
<programlisting>
ALTER SUBSCRIPTION mysub DISABLE;
</programlisting></para>
 </refsect1>

 <refsect1>
  <title>Compatibility</title>

  <para>
   <command>ALTER SUBSCRIPTION</command> is a <productname>PostgreSQL</productname>
   extension.
  </para>
 </refsect1>

 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-createsubscription"/></member>
   <member><xref linkend="sql-dropsubscription"/></member>
   <member><xref linkend="sql-createpublication"/></member>
   <member><xref linkend="sql-alterpublication"/></member>
  </simplelist>
 </refsect1>
</refentry>