RE: speed up a logical replica setup

From: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: 'vignesh C' <vignesh21(at)gmail(dot)com>
Cc: Euler Taveira <euler(at)eulerto(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Michael Paquier <michael(at)paquier(dot)xyz>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>, Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
Subject: RE: speed up a logical replica setup
Date: 2024-02-22 15:45:02
Message-ID: TYCPR01MB12077CD333376B53F9CAE7AC0F5562@TYCPR01MB12077.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dear Vignesh,

Since no one updates, here are new patch set.
Note that comments from Peter E. was not addressed because
Euler seemed to have already fixed.

> 3) Error conditions is verbose mode has invalid error message like
> "out of memory" messages like in below:
> pg_createsubscriber: waiting the postmaster to reach the consistent state
> pg_createsubscriber: postmaster reached the consistent state
> pg_createsubscriber: dropping publication "pg_createsubscriber_5" on
> database "postgres"
> pg_createsubscriber: creating subscription
> "pg_createsubscriber_5_278343" on database "postgres"
> pg_createsubscriber: error: could not create subscription
> "pg_createsubscriber_5_278343" on database "postgres": out of memory

Descriptions were added.

> 4) In error cases we try to drop this publication again resulting in error:
> + /*
> + * Since the publication was created before the
> consistent LSN, it is
> + * available on the subscriber when the physical
> replica is promoted.
> + * Remove publications from the subscriber because it
> has no use.
> + */
> + drop_publication(conn, &dbinfo[i]);
>
> Which throws these errors(because of drop publication multiple times):
> pg_createsubscriber: dropping publication "pg_createsubscriber_5" on
> database "postgres"
> pg_createsubscriber: error: could not drop publication
> "pg_createsubscriber_5" on database "postgres": ERROR: publication
> "pg_createsubscriber_5" does not exist
> pg_createsubscriber: dropping publication "pg_createsubscriber_5" on
> database "postgres"
> pg_createsubscriber: dropping the replication slot
> "pg_createsubscriber_5_278343" on database "postgres"

Changed to ... IF EXISTS. I thought your another proposal looked not good
because if the flag was turned off, the publication on publisher node could
not be dropped.

> 5) In error cases, wait_for_end_recovery waits even though it has
> identified that the replication between primary and standby is
> stopped:
> +/*
> + * Is recovery still in progress?
> + * If the answer is yes, it returns 1, otherwise, returns 0. If an error occurs
> + * while executing the query, it returns -1.
> + */
> +static int
> +server_is_in_recovery(PGconn *conn)
> +{
> + PGresult *res;
> + int ret;
> +
> + res = PQexec(conn, "SELECT pg_catalog.pg_is_in_recovery()");
> +
> + if (PQresultStatus(res) != PGRES_TUPLES_OK)
> + {
> + PQclear(res);
> + pg_log_error("could not obtain recovery progress");
> + return -1;
> + }
> +
>
> You can simulate this by stopping the primary just before
> wait_for_end_recovery and you will see these error messages, but
> pg_createsubscriber will continue to wait:
> pg_createsubscriber: error: could not obtain recovery progress
> pg_createsubscriber: error: could not obtain recovery progress
> pg_createsubscriber: error: could not obtain recovery progress
> pg_createsubscriber: error: could not obtain recovery progress

Based on idea from Euler, I roughly implemented. Thought?

0001-0013 were not changed from the previous version.

V24-0014: addressed your comment in the replied e-mail.
V24-0015: Add disconnect_database() again, per [3]
V24-0016: addressed your comment in [4].
V24-0017: addressed your comment in [5].
V24-0018: addressed your comment in [6].

[1]: https://www.postgresql.org/message-id/3ee79f2c-e8b3-4342-857c-a31b87e1afda%40eisentraut.org
[2]: https://www.postgresql.org/message-id/CALDaNm1ocVQmWhUJqxJDmR8N%3DCTbrH5GCdFU72ywnVRV6dND2A%40mail.gmail.com
[3]: https://www.postgresql.org/message-id/202402201053.6jjvdrm7kahf%40alvherre.pgsql
[4]: https://www.postgresql.org/message-id/CALDaNm2qHuZZvh6ym6OM367RfozU7RaaRDSm%3DF8M3SNrcQG2pQ%40mail.gmail.com
[5]: https://www.postgresql.org/message-id/CALDaNm3Q5W%3DEvphDjHA1n8ii5fv2DvxVShSmQLNFgeiHsOUwPg%40mail.gmail.com
[6]: https://www.postgresql.org/message-id/CALDaNm1M73ds0GBxX-XZX56f1D%2BGPojeCCwo-DLTVnfu8DMAvw%40mail.gmail.com

Best Regards,
Hayato Kuroda
FUJITSU LIMITED
https://www.fujitsu.com/

Attachment Content-Type Size
v24-0001-Creates-a-new-logical-replica-from-a-standby-ser.patch application/octet-stream 81.8 KB
v24-0002-Update-documentation.patch application/octet-stream 12.2 KB
v24-0003-Add-version-check-for-standby-server.patch application/octet-stream 2.6 KB
v24-0004-Remove-S-option-to-force-unix-domain-connection.patch application/octet-stream 12.0 KB
v24-0005-Fix-some-trivial-issues.patch application/octet-stream 6.8 KB
v24-0006-Fix-cleanup-functions.patch application/octet-stream 4.1 KB
v24-0007-Fix-server_is_in_recovery.patch application/octet-stream 3.1 KB
v24-0008-Avoid-possible-null-report.patch application/octet-stream 981 bytes
v24-0009-prohibit-to-reuse-publications.patch application/octet-stream 2.5 KB
v24-0010-Make-the-ERROR-handling-more-consistent.patch application/octet-stream 4.0 KB
v24-0011-Update-test-codes.patch application/octet-stream 9.2 KB
v24-0012-Avoid-running-pg_createsubscriber-on-standby-whi.patch application/octet-stream 1.5 KB
v24-0013-Consider-temporary-slot-to-check-max_replication.patch application/octet-stream 1.7 KB
v24-0014-address-comments-from-Vignesh-1.patch application/octet-stream 2.8 KB
v24-0015-Call-disconnect_database-even-when-the-process-w.patch application/octet-stream 8.5 KB
v24-0016-Address-comments-From-Vignesh-2.patch application/octet-stream 3.3 KB
v24-0017-Address-comments-From-Vignesh-3.patch application/octet-stream 1.7 KB
v24-0018-Address-comments-From-Vignesh-4.patch application/octet-stream 5.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2024-02-22 15:45:26 RE: speed up a logical replica setup
Previous Message Matthias van de Meent 2024-02-22 15:42:40 Re: btree: downlink right separator/HIKEY optimization