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 1nMsYs-0003qW-DW for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Feb 2022 14:24:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nMsYr-0003vS-8w for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Feb 2022 14:24:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nMsYq-0003v2-Q8 for pgsql-hackers@lists.postgresql.org; Wed, 23 Feb 2022 14:24:08 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nMsYo-0001Xf-8S for pgsql-hackers@lists.postgresql.org; Wed, 23 Feb 2022 14:24:07 +0000 Received: by mail-ej1-x633.google.com with SMTP id hw13so52490833ejc.9 for ; Wed, 23 Feb 2022 06:24:06 -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=M6mI57TWs2BbM4IEQSYgO/xolqMuU05lKeF44G0pkyE=; b=CPKqHDSsAhJq8+ywFsYlflHDRNFj4JQlBmjOCrEJs1x+w/yTC9nwOIU3prtzs4tp60 Ml023gY5WR0ckgFFxeDNWn43hA8i2qhpAxDi+jQ2PbIzq3P2sR9pkMZaHozayXtm7GTu dibYZYbg/qbBXZoN1YQRagOqGwdJ4wrOAG0kP4bmUbToTRAd965dOipsIC8Vqgley/Lq u5XjG8Tvl+hlAFVYl5RjYjKH0+46x6FdUdbb4pQiznfnA4wuW1CW4P4ZTMgwJkZpVZ4z i1UmDGO7moHMiss8clSogI5KwwTTe2MjO+AUV1TCVF9hPPEAHoxKFlJhQpI3Cs0FkJsY HG1g== 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=M6mI57TWs2BbM4IEQSYgO/xolqMuU05lKeF44G0pkyE=; b=o6O9NwSDMzXPTHYW8CFiCPHoIlBWSbOSUmCK6ysFvc2bSH9pD5Zk5fTWmWDHHfZtHi DzZL4HF+E9Szgznx1LqX261H2VgTHJHFJceEve0SpmhshiPFTUYXE7yJnWjeTXXwTwZo FV1fNqPSjDop7gVGGfKqe9LFkZHBUoDv7pt4Yc0vT5EgqKvumnIfD+XSApBjqzPEe4mm uJvzmZ1zzbUGLMMNAB/E9XV54F90YWSKrTxyyWyAXMsW2tJ5QOmtdtSWfB4FAp9MVq9i l/r4lpstoY3vWjOFKApo2jTtykqIq6diZVwUeuJEGV9BNHDtj4QAzQZvBYZeI3scsaBB FbGA== X-Gm-Message-State: AOAM530LWKubI3ZQr+AtAiQQJrWEFTGkU7eVaDp2X5/k/P0axG9z8+VM NcKaapHU43M9wyVCsG/IfCFEH3wTOVr3qaeqxXU= X-Google-Smtp-Source: ABdhPJyG5JuddCn1dlWEJEIpUZocxZmo+3rmifnK/6wgQaGYTnI7nFpRs3T2RNqZdIMig+ECOS8InBaBXhOIACo9JWs= X-Received: by 2002:a17:906:1615:b0:6bb:150f:adf8 with SMTP id m21-20020a170906161500b006bb150fadf8mr6632ejd.272.1645626244848; Wed, 23 Feb 2022 06:24:04 -0800 (PST) MIME-Version: 1.0 References: <20220217110515.zssjnez4lq2lmrdq@jrouhaud> <20220217172724.uhs2v3mgio7y6ga5@jrouhaud> <20220218074351.wgfosjt5lql2vjbr@jrouhaud> <20220219053215.r4wqatln5awklecf@jrouhaud> In-Reply-To: From: Nitin Jadhav Date: Wed, 23 Feb 2022 19:53:28 +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: Julien Rouhaud , 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 > At least for pg_stat_progress_checkpoint, storing only a timestamp in > the pg_stat storage (instead of repeatedly updating the field as a > duration) seems to provide much more precise measures of 'time > elapsed' for other sessions if one step of the checkpoint is taking a > long time. I am storing the checkpoint start timestamp in the st_progress_param[] and this gets set only once during the checkpoint (at the start of the checkpoint). I have added function pg_stat_get_progress_checkpoint_elapsed() which calculates the elapsed time and returns a string. This function gets called whenever pg_stat_progress_checkpoint view is queried. Kindly refer v2 patch and share your thoughts. > I understand the want to integrate the log-based reporting in the same > API, but I don't think that is necessarily the right approach: > pg_stat_progress_* has low-overhead infrastructure specifically to > ensure that most tasks will not run much slower while reporting, never > waiting for locks. Logging, however, needs to take locks (if only to > prevent concurrent writes to the output file at a kernel level) and > thus has a not insignificant overhead and thus is not very useful for > precise and very frequent statistics updates. I understand that the log based reporting is very costly and very frequent updates are not advisable. I am planning to use the existing infrastructure of 'log_startup_progress_interval' which provides an option for the user to configure the interval between each progress update. Hence it avoids frequent updates to server logs. This approach is used only during shutdown and end-of-recovery cases because we cannot access pg_stat_progress_checkpoint view during those scenarios. > So, although similar in nature, I don't think it is smart to use the > exact same infrastructure between pgstat_progress*-based reporting and > log-based progress reporting, especially if your logging-based > progress reporting is not intended to be a debugging-only > configuration option similar to log_min_messages=DEBUG[1..5]. Yes. I agree that we cannot use the same infrastructure for both. Progress views and servers logs have different APIs to report the progress information. But since both of this are required for the same purpose, I am planning to use a common function which increases the code readability than calling it separately in all the scenarios. I am planning to include log based reporting in the next patch. Even after that if using the same function is not recommended, I am happy to change. Thanks & Regards, Nitin Jadhav On Wed, Feb 23, 2022 at 12:13 AM Matthias van de Meent wrote: > > On Tue, 22 Feb 2022 at 07:39, Nitin Jadhav > wrote: > > > > > > 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. > > > > > > No need to use a string there; I think exposing the checkpoint start > > > time is good enough. The conversion of int64 to timestamp[tz] can be > > > done in SQL (although I'm not sure that exposing the internal bitwise > > > representation of Interval should be exposed to that extent) [0]. > > > Users can then extract the duration interval using now() - start_time, > > > which also allows the user to use their own preferred formatting. > > > > The reason for showing the elapsed time rather than exposing the > > timestamp directly is in case of checkpoint during shutdown and > > end-of-recovery, I am planning to log a message in server logs using > > 'log_startup_progress_interval' infrastructure which displays elapsed > > time. So just to match both of the behaviour I am displaying elapsed > > time here. I feel that elapsed time gives a quicker feel of the > > progress. Kindly let me know if you still feel just exposing the > > timestamp is better than showing the elapsed time. > > At least for pg_stat_progress_checkpoint, storing only a timestamp in > the pg_stat storage (instead of repeatedly updating the field as a > duration) seems to provide much more precise measures of 'time > elapsed' for other sessions if one step of the checkpoint is taking a > long time. > > I understand the want to integrate the log-based reporting in the same > API, but I don't think that is necessarily the right approach: > pg_stat_progress_* has low-overhead infrastructure specifically to > ensure that most tasks will not run much slower while reporting, never > waiting for locks. Logging, however, needs to take locks (if only to > prevent concurrent writes to the output file at a kernel level) and > thus has a not insignificant overhead and thus is not very useful for > precise and very frequent statistics updates. > > So, although similar in nature, I don't think it is smart to use the > exact same infrastructure between pgstat_progress*-based reporting and > log-based progress reporting, especially if your logging-based > progress reporting is not intended to be a debugging-only > configuration option similar to log_min_messages=DEBUG[1..5]. > > - Matthias