Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kLrz7-0000ce-Pu for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2020 17:58:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kLrz6-0005RY-D4 for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2020 17:58:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kLrz6-0005PP-36 for pgsql-hackers@lists.postgresql.org; Fri, 25 Sep 2020 17:58:16 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kLryy-0002GX-RE for pgsql-hackers@lists.postgresql.org; Fri, 25 Sep 2020 17:58:15 +0000 Received: from [192.168.1.6] (109-252-84-199.nat.spd-mgts.ru [109.252.84.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 8966321C37B1; Fri, 25 Sep 2020 20:58:07 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1601056687; bh=l/Plo0hThJHELT9D/zi8sj1BvkKrjGEfXrctMk+BLbQ=; h=Subject:To:References:From:Date:In-Reply-To; b=CGTzDF/ukHhRfRjJ0oQMdc4Bo+8XAEjEATI25GpGEnVeMfKqTW1wN1T3xWM/irQXS GnSDf+mu8PXgvWvmp+PSw5BPpdQUnWAjq8igOsck6wiFBmZe+rpKp9Hmk28pf122OV 9qn94+0Vcq0yLqaVvGWMOWNTAOoMJnzmqFEFmBJM= Subject: Re: history file on replica and double switchover To: Fujii Masao , David Zhang , Anastasia Lubennikova , Postgres hackers References: <54b059d4-2b48-13a4-6f43-95a087c92367@postgrespro.ru> <4f7379a6-b196-70fe-708d-84a2672b3c22@oss.nttdata.com> <2823800f-897e-0799-a89a-75aa43f44e5d@oss.nttdata.com> <1c1a7d07-272b-7ced-1a1c-9a16aff33d54@highgo.ca> <7ef22f86-1232-2516-afaa-f31441d25504@oss.nttdata.com> From: Grigory Smolkin Message-ID: Date: Fri, 25 Sep 2020 20:58:07 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Fujii Masao, David Zhang, Anastasia Lubennikova, many thanks to you for efforts with this patch! Can I mark it as ready for committer? On 9/25/20 10:07 AM, Fujii Masao wrote: > > > On 2020/09/25 13:00, David Zhang wrote: >> On 2020-09-24 5:00 p.m., Fujii Masao wrote: >>> >>> >>> On 2020/09/25 8:15, David Zhang wrote: >>>> Hi, >>>> >>>> My understanding is that the "archiver" won't even start if >>>> "archive_mode = on" has been set on a "replica". Therefore, either >>>> (XLogArchiveMode == ARCHIVE_MODE_ALWAYS) or (XLogArchiveMode != >>>> ARCHIVE_MODE_OFF) will produce the same result. >>> >>> Yes, the archiver isn't invoked in the standby when archive_mode=on. >>> But, with the original patch, walreceiver creates .ready archive >>> status file >>> even when archive_mode=on and no archiver is running. This causes >>> the history file to be archived after the standby is promoted and >>> the archiver is invoked. >>> >>> With my patch, walreceiver creates .ready archive status for the >>> history file >>> only when archive_mode=always, like it does for the streamed WAL files. >>> This is the difference between those two patches. To prevent the >>> streamed >>> timeline history file from being archived, IMO we should use the >>> condition >>> archive_mode==always in the walreceiver. >> +1 >>> >>> >>>> >>>> Please see how the "archiver" is started in >>>> src/backend/postmaster/postmaster.c >>>> >>>> 5227                 /* >>>> 5228                  * Start the archiver if we're responsible for >>>> (re-)archiving received >>>> 5229                  * files. >>>> 5230                  */ >>>> 5231                 Assert(PgArchPID == 0); >>>> 5232                 if (XLogArchivingAlways()) >>>> 5233                         PgArchPID = pgarch_start(); >>>> >>>> I did run the nice script "double_switchover.sh" using either >>>> "always" or "on" on patch v1 and v2. They all generate the same >>>> results below. In other words, whether history file >>>> (00000003.history) is archived or not depends on "archive_mode" >>>> settings. >>>> >>>> echo "archive_mode = always" >> ${PGDATA_NODE2}/postgresql.auto.conf >>>> >>>> $ ls -l archive >>>> -rw------- 1 david david 16777216 Sep 24 14:40 >>>> 000000010000000000000002 >>>> ... ... >>>> -rw------- 1 david david 16777216 Sep 24 14:40 >>>> 00000002000000000000000A >>>> -rw------- 1 david david       41 Sep 24 14:40 00000002.history >>>> -rw------- 1 david david       83 Sep 24 14:40 00000003.history >>>> >>>> echo "archive_mode = on" >> ${PGDATA_NODE2}/postgresql.auto.conf >>>> >>>> $ ls -l archive >>>> -rw------- 1 david david 16777216 Sep 24 14:47 >>>> 000000010000000000000002 >>>> ... ... >>>> -rw------- 1 david david 16777216 Sep 24 14:47 >>>> 00000002000000000000000A >>>> -rw------- 1 david david       41 Sep 24 14:47 00000002.history >>>> >>>> >>>> Personally, I prefer patch v2 since it allies to the statement >>>> here, >>>> https://www.postgresql.org/docs/13/warm-standby.html#CONTINUOUS-ARCHIVING-IN-STANDBY >>>> >>>> "If archive_mode is set to on, the archiver is not enabled during >>>> recovery or standby mode. If the standby server is promoted, it >>>> will start archiving after the promotion, but will not archive any >>>> WAL it did not generate itself." >>>> >>>> By the way, I think the last part of the sentence should be changed >>>> to something like below: >>>> >>>> "but will not archive any WAL, which was not generated by itself." >>> >>> I'm not sure if this change is an improvement or not. But if we apply >>> the patch I proposed, maybe we should mention also history file here. >>> For example, "but will not archive any WAL or timeline history files >>> that it did not generate itself". >> make sense for me > > So I included this change in the patch. Patch attached. > > Regards, > -- Grigory Smolkin Postgres Professional: http://www.postgrespro.com The Russian Postgres Company