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 1nFVxP-0003qq-0K for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Feb 2022 06:51:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nFVxN-0005VU-Rx for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Feb 2022 06:51:01 +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 1nFVxN-0005VC-H6 for pgsql-hackers@lists.postgresql.org; Thu, 03 Feb 2022 06:51:01 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nFVxL-00078s-9W for pgsql-hackers@lists.postgresql.org; Thu, 03 Feb 2022 06:51:01 +0000 Received: by mail-pf1-x436.google.com with SMTP id v74so1451088pfc.1 for ; Wed, 02 Feb 2022 22:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=mkekfM0MUZ8yMA52dwQJLYFYcOlYMw2HDq1z7ai8/BI=; b=odKYevxG6v1VQE2juSbHk91l9mhMUAvT4q343tE31cE2z9DvZb4EPoQNRF2zBmVmPR Al2Bisgpc/wFxBxneegffVOrG0b5CBm+d+zEe4UjO1ZzGTm6RP1GWFd/+9EdEJFRPlHe aMa8Sd+yUjNn+FFHtCsaKofUy+Aigd1Q6Tz+olzrNg/UZ5tcgfyDWUuceNXBUc+l1ODy AtyNXGOsV9M3KTcnREAwYbiii9bU7YVjIOF4THZ+pJRVJy5rIfyuoZ6wRLIH+fJuQkvS 1x33J8mdLB7oqar7Coxbtljyazv5T1gfsHbGTpyvG5stHlE6UslzLODJUCgYM4SxG/Pm 9GRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=mkekfM0MUZ8yMA52dwQJLYFYcOlYMw2HDq1z7ai8/BI=; b=0lGZH/6tm2EagHOj+Y8ZHN6/IcLLneJD4rEOWEHhnQSl8nQHP9VQpQ+8KKpi1qtNRG iHZqFwLtao3UBONMlCt8tSurm/x/fdwHHsE8Aeo51EYQ3wqKlJDUsgM1cxKsRxoUgfbb VSMf7sniHu8oUxXxnuBCrmP3zWq5M3+uNYNTQ4q6fLZ+9g2qlFstWY+YYvXxB11vW+IU OVr4Te5h9cOl/1t/N/HZoDW8rH3GLHZ4wAGvdEnAqy/VHBaHvG+AxBqqM/WrdNNmfZDA wF2yQElC2dvLW1yQSmuaArobT9brFNl5T2ei1cF5LHuGmfAsL86fKjYp//t3F1C8P5TL 6bUA== X-Gm-Message-State: AOAM530Alxpz5RU4KTqP3zSSwU1DvY5OgqBpgsVQ4G1QTY4wZnqbw9Mn ka0tB4pTXwUzVxkxjd3qino= X-Google-Smtp-Source: ABdhPJwEyweFGUaLeI9XoIJmDERw1QvEQ75pspKQzUGPgiiASpuPWMS4vwa96DBCVPTcnzeAKB5gZg== X-Received: by 2002:a05:6a00:23c3:: with SMTP id g3mr32887265pfc.51.1643871057060; Wed, 02 Feb 2022 22:50:57 -0800 (PST) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id u13sm6588847pfg.151.2022.02.02.22.50.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 02 Feb 2022 22:50:56 -0800 (PST) Date: Thu, 03 Feb 2022 15:50:53 +0900 (JST) Message-Id: <20220203.155053.170368585238406731.horikyota.ntt@gmail.com> To: masao.fujii@oss.nttdata.com Cc: bharath.rupireddyforpostgres@gmail.com, nathandbossart@gmail.com, sfrost@snowman.net, bossartn@amazon.com, rjuju123@gmail.com, michael@paquier.xyz, pgsql-hackers@lists.postgresql.org Subject: Re: Add checkpoint and redo LSN to LogCheckpointEnd log message From: Kyotaro Horiguchi In-Reply-To: <7bfad665-db9c-0c2a-2604-9f54763c5f9e@oss.nttdata.com> References: <7bfad665-db9c-0c2a-2604-9f54763c5f9e@oss.nttdata.com> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk At Thu, 3 Feb 2022 13:59:03 +0900, Fujii Masao wrote in > > > 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. By the way a comment there: > * this is a quick hack to make sure nothing really bad happens if somehow > * we get here after the end-of-recovery checkpoint. now looks a bit wrong since now it's normal that a restartpoint ends after promotion. > 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. Seems right. (I didn't confirm the behavior, though ) > 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? On way to take. In that case should we log something like "Restartpoint canceled" or something? By the way, restart point should start only while recoverying, and at the timeof the start both checkpoint.redo and checkpoint LSN are already past. We shouldn't update minRecovery point after promotion, but is there any reason for not updating the checkPoint and checkPointCopy? If we update them after promotion, the which-LSN-to-show problem would be gone. regards. -- Kyotaro Horiguchi NTT Open Source Software Center