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 1nFUDC-0000kd-O1 for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Feb 2022 04:59:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nFUDB-0004Zx-Ln for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Feb 2022 04:59:13 +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 1nFUDB-0004ZE-CN for pgsql-hackers@lists.postgresql.org; Thu, 03 Feb 2022 04:59:13 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nFUD8-0006Bp-3a for pgsql-hackers@lists.postgresql.org; Thu, 03 Feb 2022 04:59:13 +0000 Received: from [192.168.11.9] (p2019072-ipbf2307funabasi.chiba.ocn.ne.jp [122.30.130.72]) by oss.nttdata.com (Postfix) with ESMTPSA id 1B2E26094C; Thu, 3 Feb 2022 13:59:04 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.5 at oss.nttdata.com Message-ID: <7bfad665-db9c-0c2a-2604-9f54763c5f9e@oss.nttdata.com> Date: Thu, 3 Feb 2022 13:59:03 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: Add checkpoint and redo LSN to LogCheckpointEnd log message Content-Language: en-US To: Bharath Rupireddy Cc: Kyotaro Horiguchi , Nathan Bossart , Stephen Frost , "Bossart, Nathan" , Julien Rouhaud , Michael Paquier , PostgreSQL Hackers References: <20220201.152756.1157327790387186473.horikyota.ntt@gmail.com> From: Fujii Masao In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2022/02/02 23:46, Bharath Rupireddy wrote: > On Tue, Feb 1, 2022 at 9:39 PM Fujii Masao wrote: >> I found that CreateRestartPoint() already reported the redo lsn as follows after emitting the restartpoint log message. To avoid duplicated logging of the same information, we should update this code? >> >> ereport((log_checkpoints ? LOG : DEBUG2), >> (errmsg("recovery restart point at %X/%X", >> LSN_FORMAT_ARGS(lastCheckPoint.redo)), >> xtime ? errdetail("Last completed transaction was at log time %s.", >> timestamptz_to_str(xtime)) : 0)); >> >> This code reports lastCheckPoint.redo as redo lsn. OTOH, with the patch, LogCheckpointEnd() reports ControlFile->checkPointCopy.redo. They may be different, for example, when the current DB state is not DB_IN_ARCHIVE_RECOVERY. In this case, which lsn should we report as redo lsn? > > Do we ever reach CreateRestartPoint when ControlFile->stat != > DB_IN_ARCHIVE_RECOVERY? Assert(ControlFile->state == > DB_IN_ARCHIVE_RECOVERY); in CreateRestartPoint doesn't fail any > regression tests. ISTM that CreateRestartPoint() can reach the condition ControlFile->state != DB_IN_ARCHIVE_RECOVERY. Please imagine the case where CreateRestartPoint() has already started and calls CheckPointGuts(). If the standby server is promoted while CreateRestartPoint() is flushing the data to disk at CheckPointGuts(), the state would be updated to DB_IN_PRODUCTION and CreateRestartPoint() can see the state != DB_IN_ARCHIVE_RECOVERY later. As far as I read the code, this case seems to be able to make the server unrecoverable. If this case happens, since pg_control is not updated, pg_control still indicates the REDO LSN of last valid restartpoint. But CreateRestartPoint() seems to delete old WAL files based on its "current" REDO LSN not pg_control's REDO LSN. That is, WAL files required for the crash recovery starting from pg_control's REDO LSN would be removed. If this understanding is right, to address this issue, probably we need to make CreateRestartPoint() do nothing (return immediately) when the state != DB_IN_ARCHIVE_RECOVERY? Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION