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 1nOY0g-0006yJ-1a for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Feb 2022 04:51:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nOY0d-0001SR-3t for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Feb 2022 04:51:43 +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 1nOY0c-0001SI-OT for pgsql-hackers@lists.postgresql.org; Mon, 28 Feb 2022 04:51:42 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nOY0X-000074-Kq for pgsql-hackers@lists.postgresql.org; Mon, 28 Feb 2022 04:51:42 +0000 Received: by mail-pl1-x632.google.com with SMTP id ay5so6862444plb.1 for ; Sun, 27 Feb 2022 20:51:37 -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; bh=bhPuKPpu/6+wOuhLHe4+DBkDC6BGSO4GDloBcpTAWNk=; b=mpSQZUnfs57fBxbx5+mkqCGvmkSTq9QgjuKDKZI7t/SLk4dJIejcnpXHK1shDcQ8iw JVd/tHIC+ifwOkMiL05HecpwNiU/ZVoHY7uTfScRFjVHXjuoM9FXkSoRhnrI6Ij9OH4L +KhqGBT9Eg3706o+PqagwH7HElwajy/3p/9uCPFOuolvPg4NOQ49mFlbvdKn08H5XNga i1MkXUkpBN1WkHp1omSilA0JhyT4mldX+plQZFQi3fBpYf2O7jiZlZ4qoO0oxHPWgw0j Px37RBrdptP0P2Tyo6+nVP6cPmzcF44xET+QkOnukODZzYrf6m67AH9PvqnwKbKuZqF4 C4+A== 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; bh=bhPuKPpu/6+wOuhLHe4+DBkDC6BGSO4GDloBcpTAWNk=; b=6Ud2408KlJUpjHQ3Djtitw3cAce7ukwSXwEqRw3J9M4HfQc/zPa/xWXwqwyUSucGTo ieHrNqIFgabnWNhWQp4+cEypaLEx2bzPG23o83ZSg4Q5qktwG3th7vZgJAoGgAN/N43O fTo/3jRt/Hrooiuvh8yPwzsFF5ALUtqdpi8j2NHpVS1yT2xCnr2WkD1tlzK1GCH7dtNb Traof/jw0Z5uEh25dXPJFek7+1KtfbIXQetgpYVM0n8VAbiqLGSDd+IFTc3inO1Yq8tu zDHTHvPLCFkI/n1/fxgLDuTESxbBWZGncI4UZr9TXrSLjQIPlFhuS7TEtQNknzhAZ3DE EPsA== X-Gm-Message-State: AOAM530Vy/TxOx1eq6VIn0Fm4Ejv8ugSev3b2WPILFNOzNlODW4rFrd2 8JiujZkmPg2OZY5B6LjfBMNNlYdpUABUP15Jt1U= X-Google-Smtp-Source: ABdhPJwMgQj51zY60y7t96iWTH+oQaeikcHKdZXKDhbX5XOunFhwoeJ7Cjej5x9rsAl29zKX7aHkx1wt2J/xHz6TCDk= X-Received: by 2002:a17:90a:86ca:b0:1bc:af5a:5bcb with SMTP id y10-20020a17090a86ca00b001bcaf5a5bcbmr14843023pjv.25.1646023894576; Sun, 27 Feb 2022 20:51:34 -0800 (PST) MIME-Version: 1.0 References: <20220217110515.zssjnez4lq2lmrdq@jrouhaud> <20220217172724.uhs2v3mgio7y6ga5@jrouhaud> <20220218074351.wgfosjt5lql2vjbr@jrouhaud> <20220219053215.r4wqatln5awklecf@jrouhaud> In-Reply-To: From: Bharath Rupireddy Date: Mon, 28 Feb 2022 10:21:23 +0530 Message-ID: Subject: Re: Report checkpoint progress with pg_stat_progress_checkpoint (was: Report checkpoint progress in server logs) To: Nitin Jadhav Cc: Ashutosh Sharma , Julien Rouhaud , Matthias van de Meent , Bruce Momjian , Tom Lane , Magnus Hagander , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Feb 27, 2022 at 8:44 PM Bharath Rupireddy wrote: > > On Fri, Feb 25, 2022 at 8:38 PM Nitin Jadhav > wrote: > > Had a quick look over the v3 patch. I'm not sure if it's the best way > to have pg_stat_get_progress_checkpoint_type, > pg_stat_get_progress_checkpoint_kind and > pg_stat_get_progress_checkpoint_start_time just for printing info in > readable format in pg_stat_progress_checkpoint. I don't think these > functions will ever be useful for the users. > > 1) Can't we use pg_is_in_recovery to determine if it's a restartpoint > or checkpoint instead of having a new function > pg_stat_get_progress_checkpoint_type? > > 2) Can't we just have these checks inside CASE-WHEN-THEN-ELSE blocks > directly instead of new function pg_stat_get_progress_checkpoint_kind? > + snprintf(ckpt_kind, MAXPGPATH, "%s%s%s%s%s%s%s%s%s", > + (flags == 0) ? "unknown" : "", > + (flags & CHECKPOINT_IS_SHUTDOWN) ? "shutdown " : "", > + (flags & CHECKPOINT_END_OF_RECOVERY) ? "end-of-recovery " : "", > + (flags & CHECKPOINT_IMMEDIATE) ? "immediate " : "", > + (flags & CHECKPOINT_FORCE) ? "force " : "", > + (flags & CHECKPOINT_WAIT) ? "wait " : "", > + (flags & CHECKPOINT_CAUSE_XLOG) ? "wal " : "", > + (flags & CHECKPOINT_CAUSE_TIME) ? "time " : "", > + (flags & CHECKPOINT_FLUSH_ALL) ? "flush-all" : ""); > > 3) Why do we need this extra calculation for start_lsn? Do you ever > see a negative LSN or something here? > + ('0/0'::pg_lsn + ( > + CASE > + WHEN (s.param3 < 0) THEN pow((2)::numeric, (64)::numeric) > + ELSE (0)::numeric > + END + (s.param3)::numeric)) AS start_lsn, > > 4) Can't you use timestamptz_in(to_char(s.param4)) instead of > pg_stat_get_progress_checkpoint_start_time? I don't quite understand > the reasoning for having this function and it's named as *checkpoint* > when it doesn't do anything specific to the checkpoint at all? > > Having 3 unnecessary functions that aren't useful to the users at all > in proc.dat will simply eatup the function oids IMO. Hence, I suggest > let's try to do without extra functions. Another thought for my review comment: > 1) Can't we use pg_is_in_recovery to determine if it's a restartpoint > or checkpoint instead of having a new function > pg_stat_get_progress_checkpoint_type? I don't think using pg_is_in_recovery work here as it is taken after the checkpoint has started. So, I think the right way here is to send 1 in CreateCheckPoint and 2 in CreateRestartPoint and use CASE-WHEN-ELSE-END to show "1": "checkpoint" "2":"restartpoint". Continuing my review: 5) Do we need a special phase for this checkpoint operation? I'm not sure in which cases it will take a long time, but it looks like there's a wait loop here. vxids = GetVirtualXIDsDelayingChkpt(&nvxids); if (nvxids > 0) { do { pg_usleep(10000L); /* wait for 10 msec */ } while (HaveVirtualXIDsDelayingChkpt(vxids, nvxids)); } Also, how about special phases for SyncPostCheckpoint(), SyncPreCheckpoint(), InvalidateObsoleteReplicationSlots(), PreallocXlogFiles() (it currently pre-allocates only 1 WAL file, but it might be increase in future (?)), TruncateSUBTRANS()? 6) SLRU (Simple LRU) isn't a phase here, you can just say PROGRESS_CHECKPOINT_PHASE_PREDICATE_LOCK_PAGES. + + pgstat_progress_update_param(PROGRESS_CHECKPOINT_PHASE, + PROGRESS_CHECKPOINT_PHASE_SLRU_PAGES); CheckPointPredicate(); And :s/checkpointing SLRU pages/checkpointing predicate lock pages + WHEN 9 THEN 'checkpointing SLRU pages' 7) :s/PROGRESS_CHECKPOINT_PHASE_FILE_SYNC/PROGRESS_CHECKPOINT_PHASE_PROCESS_FILE_SYNC_REQUESTS And :s/WHEN 11 THEN 'performing sync requests'/WHEN 11 THEN 'processing file sync requests' 8) :s/Finalizing/finalizing + WHEN 14 THEN 'Finalizing' 9) :s/checkpointing snapshots/checkpointing logical replication snapshot files + WHEN 3 THEN 'checkpointing snapshots' :s/checkpointing logical rewrite mappings/checkpointing logical replication rewrite mapping files + WHEN 4 THEN 'checkpointing logical rewrite mappings' 10) I'm not sure if it's discussed, how about adding the number of snapshot/mapping files so far the checkpoint has processed in file processing while loops of CheckPointSnapBuild/CheckPointLogicalRewriteHeap? Sometimes, there can be many logical snapshot or mapping files and users may be interested in knowing the so-far-processed-file-count. 11) I think it's discussed, are we going to add the pid of the checkpoint requestor? Regards, Bharath Rupireddy.