|
320 | 320 | </sect2>
|
321 | 321 |
|
322 | 322 | <sect2 id="logical-replication-subscription-examples">
|
323 |
| - <title>Examples</title> |
| 323 | + <title>Examples - Setup Logical Replication</title> |
324 | 324 |
|
325 | 325 | <para>
|
326 | 326 | Create some test tables on the publisher.
|
@@ -512,6 +512,163 @@ test_sub=# SELECT * FROM t3;
|
512 | 512 | </programlisting></para>
|
513 | 513 | </sect2>
|
514 | 514 |
|
| 515 | + <sect2 id="logical-replication-subscription-examples-deferred-slot"> |
| 516 | + <title>Examples - Deferred Replication Slot Creation</title> |
| 517 | + |
| 518 | + <para> |
| 519 | + There are some cases (e.g. |
| 520 | + <xref linkend="logical-replication-subscription-slot"/>) where, if the |
| 521 | + remote replication slot was not created automatically, the user must create |
| 522 | + it manually before the subscription can be activated. The steps to create |
| 523 | + the slot and activate the subscription are shown in the following examples. |
| 524 | + These examples specify the standard logical decoding plugin |
| 525 | + (<literal>pgoutput</literal>), which is what the built-in logical |
| 526 | + replication uses. |
| 527 | + </para> |
| 528 | + <para> |
| 529 | + First, create a publication for the examples to use. |
| 530 | +<programlisting> |
| 531 | +test_pub=# CREATE PUBLICATION pub1 FOR ALL TABLES; |
| 532 | +CREATE PUBLICATION |
| 533 | +</programlisting></para> |
| 534 | + <para> |
| 535 | + Example 1: Where the subscription says <literal>connect = false</literal> |
| 536 | + </para> |
| 537 | + <para> |
| 538 | + <itemizedlist> |
| 539 | + <listitem> |
| 540 | + <para> |
| 541 | + Create the subscription. |
| 542 | +<programlisting> |
| 543 | +test_sub=# CREATE SUBSCRIPTION sub1 |
| 544 | +test_sub-# CONNECTION 'host=localhost dbname=test_pub' |
| 545 | +test_sub-# PUBLICATION pub1 |
| 546 | +test_sub-# WITH (connect=false); |
| 547 | +WARNING: subscription was created, but is not connected |
| 548 | +HINT: To initiate replication, you must manually create the replication slot, enable the subscription, and refresh the subscription. |
| 549 | +CREATE SUBSCRIPTION |
| 550 | +</programlisting></para> |
| 551 | + </listitem> |
| 552 | + <listitem> |
| 553 | + <para> |
| 554 | + On the publisher, manually create a slot. Because the name was not |
| 555 | + specified during <literal>CREATE SUBSCRIPTION</literal>, the name of the |
| 556 | + slot to create is same as the subscription name, e.g. "sub1". |
| 557 | +<programlisting> |
| 558 | +test_pub=# SELECT * FROM pg_create_logical_replication_slot('sub1', 'pgoutput'); |
| 559 | + slot_name | lsn |
| 560 | +-----------+----------- |
| 561 | + sub1 | 0/19404D0 |
| 562 | +(1 row) |
| 563 | +</programlisting></para> |
| 564 | + </listitem> |
| 565 | + <listitem> |
| 566 | + <para> |
| 567 | + On the subscriber, complete the activation of the subscription. After |
| 568 | + this the tables of <literal>pub1</literal> will start replicating. |
| 569 | +<programlisting> |
| 570 | +test_sub=# ALTER SUBSCRIPTION sub1 ENABLE; |
| 571 | +ALTER SUBSCRIPTION |
| 572 | +test_sub=# ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION; |
| 573 | +ALTER SUBSCRIPTION |
| 574 | +</programlisting></para> |
| 575 | + </listitem> |
| 576 | + </itemizedlist> |
| 577 | + </para> |
| 578 | + |
| 579 | + <para> |
| 580 | + Example 2: Where the subscription says <literal>connect = false</literal>, |
| 581 | + but also specifies the <literal>slot_name</literal> |
| 582 | + <itemizedlist> |
| 583 | + <listitem> |
| 584 | + <para> |
| 585 | + Create the subscription. |
| 586 | +<programlisting> |
| 587 | +test_sub=# CREATE SUBSCRIPTION sub1 |
| 588 | +test_sub-# CONNECTION 'host=localhost dbname=test_pub' |
| 589 | +test_sub-# PUBLICATION pub1 |
| 590 | +test_sub-# WITH (connect=false, slot_name='myslot'); |
| 591 | +WARNING: subscription was created, but is not connected |
| 592 | +HINT: To initiate replication, you must manually create the replication slot, enable the subscription, and refresh the subscription. |
| 593 | +CREATE SUBSCRIPTION |
| 594 | +</programlisting></para> |
| 595 | + </listitem> |
| 596 | + <listitem> |
| 597 | + <para> |
| 598 | + On the publisher, manually create a slot using the same name that was |
| 599 | + specified during <literal>CREATE SUBSCRIPTION</literal>, e.g. "myslot". |
| 600 | +<programlisting> |
| 601 | +test_pub=# SELECT * FROM pg_create_logical_replication_slot('myslot', 'pgoutput'); |
| 602 | + slot_name | lsn |
| 603 | +-----------+----------- |
| 604 | + myslot | 0/19059A0 |
| 605 | +(1 row) |
| 606 | +</programlisting></para> |
| 607 | + </listitem> |
| 608 | + <listitem> |
| 609 | + <para> |
| 610 | + On the subscriber, the remaining subscription activation steps are the |
| 611 | + same as before. |
| 612 | +<programlisting> |
| 613 | +test_sub=# ALTER SUBSCRIPTION sub1 ENABLE; |
| 614 | +ALTER SUBSCRIPTION |
| 615 | +test_sub=# ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION; |
| 616 | +ALTER SUBSCRIPTION |
| 617 | +</programlisting></para> |
| 618 | + </listitem> |
| 619 | + </itemizedlist> |
| 620 | + </para> |
| 621 | + |
| 622 | + <para> |
| 623 | + Example 3: Where the subscription specifies <literal>slot_name = NONE</literal> |
| 624 | + <itemizedlist> |
| 625 | + <listitem> |
| 626 | + <para> |
| 627 | + Create the subscription. When <literal>slot_name = NONE</literal> then |
| 628 | + <literal>enabled = false</literal>, and |
| 629 | + <literal>create_slot = false</literal> are also needed. |
| 630 | +<programlisting> |
| 631 | +test_sub=# CREATE SUBSCRIPTION sub1 |
| 632 | +test_sub-# CONNECTION 'host=localhost dbname=test_pub' |
| 633 | +test_sub-# PUBLICATION pub1 |
| 634 | +test_sub-# WITH (slot_name=NONE, enabled=false, create_slot=false); |
| 635 | +CREATE SUBSCRIPTION |
| 636 | +</programlisting></para> |
| 637 | + </listitem> |
| 638 | + <listitem> |
| 639 | + <para> |
| 640 | + On the publisher, manually create a slot using any name, e.g. "myslot". |
| 641 | +<programlisting> |
| 642 | +test_pub=# SELECT * FROM pg_create_logical_replication_slot('myslot', 'pgoutput'); |
| 643 | + slot_name | lsn |
| 644 | +-----------+----------- |
| 645 | + myslot | 0/1905930 |
| 646 | +(1 row) |
| 647 | +</programlisting></para> |
| 648 | + </listitem> |
| 649 | + <listitem> |
| 650 | + <para> |
| 651 | + On the subscriber, associate the subscription with the slot name just |
| 652 | + created. |
| 653 | +<programlisting> |
| 654 | +test_sub=# ALTER SUBSCRIPTION sub1 SET (slot_name='myslot'); |
| 655 | +ALTER SUBSCRIPTION |
| 656 | +</programlisting></para> |
| 657 | + </listitem> |
| 658 | + <listitem> |
| 659 | + <para> |
| 660 | + The remaining subscription activation steps are same as before. |
| 661 | +<programlisting> |
| 662 | +test_sub=# ALTER SUBSCRIPTION sub1 ENABLE; |
| 663 | +ALTER SUBSCRIPTION |
| 664 | +test_sub=# ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION; |
| 665 | +ALTER SUBSCRIPTION |
| 666 | +</programlisting></para> |
| 667 | + </listitem> |
| 668 | + </itemizedlist> |
| 669 | + </para> |
| 670 | + </sect2> |
| 671 | + |
515 | 672 | </sect1>
|
516 | 673 |
|
517 | 674 | <sect1 id="logical-replication-row-filter">
|
|
0 commit comments