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 1nKaih-0008TH-9X for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Feb 2022 06:56:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nKaif-0001Z6-Rm for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Feb 2022 06:56:49 +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 1nKaif-0001Yx-FT for pgsql-hackers@lists.postgresql.org; Thu, 17 Feb 2022 06:56:49 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nKaic-0008Ho-L9 for pgsql-hackers@lists.postgresql.org; Thu, 17 Feb 2022 06:56:49 +0000 Received: by mail-ej1-x635.google.com with SMTP id p15so4787476ejc.7 for ; Wed, 16 Feb 2022 22:56:46 -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=wa+xI2uXZRAEs8756wIIbLCUJqCc7DtcZyzo7bEriaQ=; b=kWaU5YjZMD8KJAMfS9eUnpV7NyXfeV05H/p05kYnv7TJVy9wFrU8nLgM7oHcxHB0rm nCrCPac2+JAKHJd/7hx5yp+wSy9SX/ey1pcEs4rSpXGicngnMDCKfGr7fy+MxeJPRtBk mzuXaaqDtnA9yGxlchZQtT4XD4z6GBvH4mEejsj+SC/KMt5lZZJIalucdg6U3WAkGx8S mwMMwJdZdXe6eTX+GuiJP4Z0uCGjTtLJTVx/jpICxTg/wD1MD8Xv99Wz6gxC3mfYXu9M K2psc4g+0IgwYzWezI6vOIXHflNXz7BhDzZPUP1C523/e8YqXx5556IUZrcihdtok44U MdWQ== 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=wa+xI2uXZRAEs8756wIIbLCUJqCc7DtcZyzo7bEriaQ=; b=EHGcYWuAsm7R2wyL+A/C7D40gOeZAapnVS71KQpHvE80H08U9hk2QXjOpsUNYHfd+t okEtBZ37tZwdznyM0/rE1cqGO0UGMU3bPBVZ7icDaaP8ve7oA2iD1Y5HybJrfJY+uVpE Dks+5CuBVQ2pknLtE5ztkFpDRHPc+32z8BICjBFIib0S12ev76XbvYd7iu6fy315+N1l aIPkw+R1SmzImoWw/kivJdCwuUnTn9ConFO1KNaMo3itK+gw0SfXFkaQFkJN0EGHpWse Qa17e9xt1RtupiDgNUg/nWEgmh7bapmwmLOpZFD3n0j/RzVmGnZciwGDaG8kXzjBiN9X Czsw== X-Gm-Message-State: AOAM532vBLeBGW7HEvTZiojSlpTPysqb4jlKWzMrAwDiMqUtXbvKzXcw 6bqP8iCyc80s1xGMH/5fcUlnHpXGK1InN/KVLeo= X-Google-Smtp-Source: ABdhPJwaRJ361QVXaa7ARlup+xy8aiCbWsHSjy8ich9r7aMafeApsgLzP94t+zt50AKIn2XwPdAcJaAVQmwgxzgUKmc= X-Received: by 2002:a17:906:1be1:b0:6ce:b0a8:17d with SMTP id t1-20020a1709061be100b006ceb0a8017dmr1178180ejg.413.1645081005279; Wed, 16 Feb 2022 22:56:45 -0800 (PST) MIME-Version: 1.0 References: <2031846.1640792459@sss.pgh.pa.us> In-Reply-To: From: Nitin Jadhav Date: Thu, 17 Feb 2022 12:26:07 +0530 Message-ID: Subject: Re: Report checkpoint progress with pg_stat_progress_checkpoint (was: Report checkpoint progress in server logs) To: Matthias van de Meent Cc: Bharath Rupireddy , 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 > > The progress reporting mechanism of postgres uses the > > 'st_progress_param' array of 'PgBackendStatus' structure to hold the > > information related to the progress. There is a function > > 'pgstat_progress_update_param()' which takes 'index' and 'val' as > > arguments and updates the 'val' to corresponding 'index' in the > > 'st_progress_param' array. This mechanism works fine when all the > > progress information is of type integer as the data type of > > 'st_progress_param' is of type integer. If the progress data is of > > different type than integer, then there is no easy way to do so. > > Progress parameters are int64, so all of the new 'checkpoint start > location' (lsn = uint64), 'triggering backend PID' (int), 'elapsed > time' (store as start time in stat_progress, timestamp fits in 64 > bits) and 'checkpoint or restartpoint?' (boolean) would each fit in a > current stat_progress parameter. Some processing would be required at > the view, but that's not impossible to overcome. Thank you for sharing the information. 'triggering backend PID' (int) - can be stored without any problem. 'checkpoint or restartpoint?' (boolean) - can be stored as a integer value like PROGRESS_CHECKPOINT_TYPE_CHECKPOINT(0) and PROGRESS_CHECKPOINT_TYPE_RESTARTPOINT(1). 'elapsed time' (store as start time in stat_progress, timestamp fits in 64 bits) - As Timestamptz is of type int64 internally, so we can store the timestamp value in the progres parameter and then expose a function like 'pg_stat_get_progress_checkpoint_elapsed' which takes int64 (not Timestamptz) as argument and then returns string representing the elapsed time. This function can be called in the view. Is it safe/advisable to use int64 type here rather than Timestamptz for this purpose? 'checkpoint start location' (lsn = uint64) - I feel we cannot use progress parameters for this case. As assigning uint64 to int64 type would be an issue for larger values and can lead to hidden bugs. Thoughts? Thanks & Regards, Nitin Jadhav On Thu, Feb 17, 2022 at 1:33 AM Matthias van de Meent wrote: > > On Thu, 10 Feb 2022 at 07:53, Nitin Jadhav > wrote: > > > > > > We need at least a trace of the number of buffers to sync (num_to_scan) before the checkpoint start, instead of just emitting the stats at the end. > > > > > > > > Bharat, it would be good to show the buffers synced counter and the total buffers to sync, checkpointer pid, substep it is running, whether it is on target for completion, checkpoint_Reason > > > > (manual/times/forced). BufferSync has several variables tracking the sync progress locally, and we may need some refactoring here. > > > > > > I agree to provide above mentioned information as part of showing the > > > progress of current checkpoint operation. I am currently looking into > > > the code to know if any other information can be added. > > > > Here is the initial patch to show the progress of checkpoint through > > pg_stat_progress_checkpoint view. Please find the attachment. > > > > The information added to this view are pid - process ID of a > > CHECKPOINTER process, kind - kind of checkpoint indicates the reason > > for checkpoint (values can be wal, time or force), phase - indicates > > the current phase of checkpoint operation, total_buffer_writes - total > > number of buffers to be written, buffers_processed - number of buffers > > processed, buffers_written - number of buffers written, > > total_file_syncs - total number of files to be synced, files_synced - > > number of files synced. > > > > There are many operations happen as part of checkpoint. For each of > > the operation I am updating the phase field of > > pg_stat_progress_checkpoint view. The values supported for this field > > are initializing, checkpointing replication slots, checkpointing > > snapshots, checkpointing logical rewrite mappings, checkpointing CLOG > > pages, checkpointing CommitTs pages, checkpointing SUBTRANS pages, > > checkpointing MULTIXACT pages, checkpointing SLRU pages, checkpointing > > buffers, performing sync requests, performing two phase checkpoint, > > recycling old XLOG files and Finalizing. In case of checkpointing > > buffers phase, the fields total_buffer_writes, buffers_processed and > > buffers_written shows the detailed progress of writing buffers. In > > case of performing sync requests phase, the fields total_file_syncs > > and files_synced shows the detailed progress of syncing files. In > > other phases, only the phase field is getting updated and it is > > difficult to show the progress because we do not get the total number > > of files count without traversing the directory. It is not worth to > > calculate that as it affects the performance of the checkpoint. I also > > gave a thought to just mention the number of files processed, but this > > wont give a meaningful progress information (It can be treated as > > statistics). Hence just updating the phase field in those scenarios. > > > > Apart from above fields, I am planning to add few more fields to the > > view in the next patch. That is, process ID of the backend process > > which triggered a CHECKPOINT command, checkpoint start location, filed > > to indicate whether it is a checkpoint or restartpoint and elapsed > > time of the checkpoint operation. Please share your thoughts. I would > > be happy to add any other information that contributes to showing the > > progress of checkpoint. > > > > As per the discussion in this thread, there should be some mechanism > > to show the progress of checkpoint during shutdown and end-of-recovery > > cases as we cannot access pg_stat_progress_checkpoint in those cases. > > I am working on this to use log_startup_progress_interval mechanism to > > log the progress in the server logs. > > > > Kindly review the patch and share your thoughts. > > Interesting idea, and overall a nice addition to the > pg_stat_progress_* reporting infrastructure. > > Could you add your patch to the current commitfest at > https://commitfest.postgresql.org/37/? > > See below for some comments on the patch: > > > xlog.c @ checkpoint_progress_start, checkpoint_progress_update_param, checkpoint_progress_end > > + /* In bootstrap mode, we don't actually record anything. */ > > + if (IsBootstrapProcessingMode()) > > + return; > > Why do you check against the state of the system? > pgstat_progress_update_* already provides protections against updating > the progress tables if the progress infrastructure is not loaded; and > otherwise (in the happy path) the cost of updating the progress fields > will be quite a bit higher than normal. Updating stat_progress isn't > very expensive (quite cheap, really), so I don't quite get why you > guard against reporting stats when you expect no other client to be > listening. > > I think you can simplify this a lot by directly using > pgstat_progress_update_param() instead. > > > xlog.c @ checkpoint_progress_start > > + pgstat_progress_start_command(PROGRESS_COMMAND_CHECKPOINT, InvalidOid); > > + checkpoint_progress_update_param(flags, PROGRESS_CHECKPOINT_PHASE, > > + PROGRESS_CHECKPOINT_PHASE_INIT); > > + if (flags & CHECKPOINT_CAUSE_XLOG) > > + checkpoint_progress_update_param(flags, PROGRESS_CHECKPOINT_KIND, > > + PROGRESS_CHECKPOINT_KIND_WAL); > > + else if (flags & CHECKPOINT_CAUSE_TIME) > > + checkpoint_progress_update_param(flags, PROGRESS_CHECKPOINT_KIND, > > + PROGRESS_CHECKPOINT_KIND_TIME); > > + [...] > > Could you assign the kind of checkpoint to a local variable, and then > update the "phase" and "kind" parameters at the same time through > pgstat_progress_update_multi_param(2, ...)? See > BuildRelationExtStatistics in extended_stats.c for an example usage. > Note that regardless of whether checkpoint_progress_update* will > remain, the checks done in that function already have been checked in > this function as well, so you can use the pgstat_* functions directly. > > > monitoring.sgml > > + pg_stat_progress_checkpoint view will contain a > > + single row indicating the progress of checkpoint operation. > > ... add "if a checkpoint is currently active". > > > + total_buffer_writes bigint > > + total_file_syncs bigint > > The other progress tables use [type]_total as column names for counter > targets (e.g. backup_total for backup_streamed, heap_blks_total for > heap_blks_scanned, etc.). I think that `buffers_total` and > `files_total` would be better column names. > > > + The checkpoint operation is requested due to XLOG filling. > > + The checkpoint was started because >max_wal_size< of WAL was written. > > > + The checkpoint operation is requested due to timeout. > > + The checkpoint was started due to the expiration of a > >checkpoint_timeout< interval > > > + The checkpoint operation is forced even if no XLOG activity has occurred > > + since the last one. > > + Some operation forced a checkpoint. > > > + checkpointing CommitTs pages > > CommitTs -> Commit time stamp > > Thanks for working on this. > > Kind regards, > > Matthias van de Meent