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 1nFGuM-0007fl-A1 for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Feb 2022 14:46:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nFGuK-0007DR-LB for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Feb 2022 14:46:52 +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 1nFGuK-0007DI-AO for pgsql-hackers@lists.postgresql.org; Wed, 02 Feb 2022 14:46:52 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nFGuI-0007pl-4d for pgsql-hackers@lists.postgresql.org; Wed, 02 Feb 2022 14:46:51 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d1so18440336plh.10 for ; Wed, 02 Feb 2022 06:46:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=aeSG78Cj24p50NGpozDzdhqxhvczn0U3eaYZhq+UNKc=; b=CMI4WDD8PEiyuYIGr+KjvRhQ7BXwlVNG3+eoVlGbK1jggKHytC/vOe6Nk8YONuyzOZ suSheagzFH44hpjR9z7w/iF9x3ZwE5lzYtStGpiZYzrdcC9te4pyI9h/F2zW3zxfluKQ pPiwaFqg3OwiHDUes1JsRz2wTe+rx2w7MuRJHqGb/fcWwr1Ry9qyeQ45rlHA3KCgAmZj tyLOtUXS1/nqCSRETHC3guj6bGrYetMZZjzaWd8I1ruhRfbqrxjQqZZKj8FzErblJh/K rrB16XbSDRQitLgFkL9bAnG6HzpRKB0dkdeq/8s+artk2orC+aVRS4gclSNrP9BdrwWS fZQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=aeSG78Cj24p50NGpozDzdhqxhvczn0U3eaYZhq+UNKc=; b=28CCfxORdNjDImlB4HpbW5PKCeOA0xI3UJXmKeS8kze7c+aek4gQHXbEVluUqANlYf Z2NtAJ7DPq6ULdWqkUc3HSPfPfzhk7IngnvpnXv8xMBovkXCGKYcIxksnC/Fs0Dxn1lk SA069XDlSYlyPe/ZMB91yIDdwhhQoNaE+51avwWaB3U5vsnlmtyDzSrM3PYo268xyqqE AyXHUS7tAdCbGAR5/Lb82h6SloRsUhMvbZ3Nt5NViuDm30MsiNmbnLlpqwXsa95OKcVe VIPe5Xfb4gwxEKITsgL5JkbVS7ybiCPx1DT+shjfGV2BlBVhZHYH3RYrc9gwM5JTtrze PmwA== X-Gm-Message-State: AOAM532jPb6ffwMRbR//cOC7VJvFUpM3pXWY0OEENbeDJCp6Eg32xts6 K7wT8QbIr95J5IEPNq5ysrfPRneDqPQdkagnWJo= X-Google-Smtp-Source: ABdhPJwmp9xTXQ1x2Yut+F5UQwH7zX6S93lafEmW390nYf8sgdQO+jCHUN/aIbcBPVPL9tyvQXhOEujxAcx00MxhE3Y= X-Received: by 2002:a17:90a:c682:: with SMTP id n2mr8536028pjt.177.1643813206943; Wed, 02 Feb 2022 06:46:46 -0800 (PST) MIME-Version: 1.0 References: <20220201.152756.1157327790387186473.horikyota.ntt@gmail.com> In-Reply-To: From: Bharath Rupireddy Date: Wed, 2 Feb 2022 20:16:35 +0530 Message-ID: Subject: Re: Add checkpoint and redo LSN to LogCheckpointEnd log message To: Fujii Masao Cc: Kyotaro Horiguchi , Nathan Bossart , Stephen Frost , "Bossart, Nathan" , Julien Rouhaud , Michael Paquier , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Feb 1, 2022 at 9:39 PM Fujii Masao wr= ote: > I found that CreateRestartPoint() already reported the redo lsn as follow= s 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.re= do)), > xtime ? errdetail("Last completed transaction wa= s 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 di= fferent, for example, when the current DB state is not DB_IN_ARCHIVE_RECOVE= RY. In this case, which lsn should we report as redo lsn? Do we ever reach CreateRestartPoint when ControlFile->stat !=3D DB_IN_ARCHIVE_RECOVERY? Assert(ControlFile->state =3D=3D DB_IN_ARCHIVE_RECOVERY); in CreateRestartPoint doesn't fail any regression tests. Here's what can happen: lastCheckPoint.redo is 100 and ControlFile->checkPointCopy.redo is 105, so, "skipping restartpoint, already performed at %X/%X" LogCheckpointEnd isn't reached lastCheckPoint.redo is 105 and ControlFile->checkPointCopy.redo is 100 and ControlFile->state =3D=3D DB_IN_ARCHIVE_RECOVERY, then the control file gets updated and LogCheckpointEnd prints the right redo lsn. lastCheckPoint.redo is 105 and ControlFile->checkPointCopy.redo is 100 and ControlFile->state !=3D DB_IN_ARCHIVE_RECOVERY, the the control file doesn't get updated and LogCheckpointEnd just prints the control redo lsn. Looks like this case is rare given Assert(ControlFile->state =3D=3D DB_IN_ARCHIVE_RECOVERY); doesn't fail any tests. I think we should just let LogCheckpointEnd print the redo lsn from the control file. We can just remove the above errmsg("recovery restart point at %X/%X" message altogether or just print it only in the rare scenario, something like below: if (ControlFile->state !=3D DB_IN_ARCHIVE_RECOVERY) { ereport((log_checkpoints ? LOG : DEBUG2), (errmsg("performed recovery restart point at %X/%X while the database state is %s", LSN_FORMAT_ARGS(lastCheckPoint.redo)), getDBState(ControlFile->state))); } And the last commit/abort records's timestamp will always get logged even before we reach here in the main redo loop (errmsg("last completed transaction was at log time %s"). Or another way is to just pass the redo lsn to LogCheckpointEnd and pass the lastCheckPoint.redo in if (ControlFile->state !=3D DB_IN_ARCHIVE_RECOVERY) cases or when control file isn't updated but restart point happened. Thoughts? Regards, Bharath Rupireddy.