|
24 | 24 | </para>
|
25 | 25 |
|
26 | 26 | <para>
|
27 |
| - Logical replication sends changes on the publisher to the subscriber as |
28 |
| - they occur in real-time. The subscriber applies the data in the same order |
29 |
| - as the publisher so that transactional consistency is guaranteed for |
| 27 | + Logical replication of a table typically starts with a taking a snapshot |
| 28 | + of the data on the publisher database and copying that to the subscriber. |
| 29 | + Once that is done, the changes on the publisher are sent to the subscriber |
| 30 | + as they occur in real-time. The subscriber applies the data in the same |
| 31 | + order as the publisher so that transactional consistency is guaranteed for |
30 | 32 | publications within a single subscription. This method of data replication
|
31 | 33 | is sometimes referred to as transactional replication.
|
32 | 34 | </para>
|
|
159 | 161 |
|
160 | 162 | <para>
|
161 | 163 | Each subscription will receive changes via one replication slot (see
|
162 |
| - <xref linkend="streaming-replication-slots">). |
| 164 | + <xref linkend="streaming-replication-slots">). Additional temporary |
| 165 | + replication slots may be required for the initial data synchronization |
| 166 | + of pre-existing table data. |
163 | 167 | </para>
|
164 | 168 |
|
165 | 169 | <para>
|
|
264 | 268 | to <literal>replica</literal>, which produces the usual effects on triggers
|
265 | 269 | and constraints.
|
266 | 270 | </para>
|
| 271 | + |
| 272 | + <sect2 id="logical-replication-snapshot"> |
| 273 | + <title>Initial Snapshot</title> |
| 274 | + <para> |
| 275 | + The initial data in existing subscribed tables are snapshotted and |
| 276 | + copied in a parallel instance of a special kind of apply process. |
| 277 | + This process will create its own temporary replication slot and |
| 278 | + copy the existing data. Once existing data is copied, the worker |
| 279 | + enters synchronization mode, which ensures that the table is brought |
| 280 | + up to a synchronized state with the main apply process by streaming |
| 281 | + any changes that happened during the initial data copy using standard |
| 282 | + logical replication. Once the synchronization is done, the control |
| 283 | + of the replication of the table is given back to the main apply |
| 284 | + process where the replication continues as normal. |
| 285 | + </para> |
| 286 | + </sect2> |
267 | 287 | </sect1>
|
268 | 288 |
|
269 |
| - <sect1 id="logical-replication-monitoring"> |
| 289 | + <sect1 id="logical-replication-monitoring"> |
270 | 290 | <title>Monitoring</title>
|
271 | 291 |
|
272 | 292 | <para>
|
|
287 | 307 | <para>
|
288 | 308 | Normally, there is a single apply process running for an enabled
|
289 | 309 | subscription. A disabled subscription or a crashed subscription will have
|
290 |
| - zero rows in this view. |
| 310 | + zero rows in this view. If the initial data synchronization of any |
| 311 | + table is in progress, there will be additional workers for the tables |
| 312 | + being synchronized. |
291 | 313 | </para>
|
292 | 314 | </sect1>
|
293 | 315 |
|
|
337 | 359 | <para>
|
338 | 360 | On the publisher side, <varname>wal_level</varname> must be set to
|
339 | 361 | <literal>logical</literal>, and <varname>max_replication_slots</varname>
|
340 |
| - must be set to at least the number of subscriptions expected to connect. |
341 |
| - And <varname>max_wal_senders</varname> should be set to at least the same |
342 |
| - as <varname>max_replication_slots</varname> plus the number of physical replicas |
343 |
| - that are connected at the same time. |
| 362 | + must be set to at least the number of subscriptions expected to connect, |
| 363 | + plus some reserve for table synchronization. And |
| 364 | + <varname>max_wal_senders</varname> should be set to at least the same as |
| 365 | + <varname>max_replication_slots</varname> plus the number of physical |
| 366 | + replicas that are connected at the same time. |
344 | 367 | </para>
|
345 | 368 |
|
346 | 369 | <para>
|
347 | 370 | The subscriber also requires the <varname>max_replication_slots</varname>
|
348 | 371 | to be set. In this case it should be set to at least the number of
|
349 | 372 | subscriptions that will be added to the subscriber.
|
350 | 373 | <varname>max_logical_replication_workers</varname> must be set to at
|
351 |
| - least the number of subscriptions. Additionally the |
352 |
| - <varname>max_worker_processes</varname> may need to be adjusted to |
353 |
| - accommodate for replication workers, at least |
| 374 | + least the number of subscriptions, again plus some reserve for the table |
| 375 | + synchronization. Additionally the <varname>max_worker_processes</varname> |
| 376 | + may need to be adjusted to accommodate for replication workers, at least |
354 | 377 | (<varname>max_logical_replication_workers</varname>
|
355 | 378 | + <literal>1</literal>). Note that some extensions and parallel queries
|
356 | 379 | also take worker slots from <varname>max_worker_processes</varname>.
|
@@ -393,8 +416,10 @@ CREATE SUBSCRIPTION mysub CONNECTION 'dbname=foo host=bar user=repuser' PUBLICAT
|
393 | 416 | </para>
|
394 | 417 |
|
395 | 418 | <para>
|
396 |
| - The above will start the replication process of changes to |
397 |
| - <literal>users</literal> and <literal>departments</literal> tables. |
| 419 | + The above will start the replication process, which synchronizes the |
| 420 | + initial table contents of the tables <literal>users</literal> and |
| 421 | + <literal>departments</literal> and then starts replicating |
| 422 | + incremental changes to those tables. |
398 | 423 | </para>
|
399 | 424 | </sect1>
|
400 | 425 | </chapter>
|
0 commit comments