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 1nDJwA-00088C-6v for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jan 2022 05:36:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nDJw8-0005Jm-NM for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jan 2022 05:36:40 +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 1nDJw8-0005JQ-Cg for pgsql-hackers@lists.postgresql.org; Fri, 28 Jan 2022 05:36:40 +0000 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nDJw4-0007up-Jl for pgsql-hackers@lists.postgresql.org; Fri, 28 Jan 2022 05:36:40 +0000 Received: by mail-pg1-x52a.google.com with SMTP id e16so4299154pgn.4 for ; Thu, 27 Jan 2022 21:36:36 -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=fzODr4z/ehVsnzF8VSU8uExhuBVO0bsdLFUBjP7z150=; b=D7b7geJahn1ii7Un7/4B5/1Zr5nukGeRx2Jqc30TZPXMqyM1CyLcZGduEOo61OgDGv e1cuX7Ye5UlNwjTIp6svqQFBcJ/UowT/DKZ2gU1KVSrU2jRrvINT5yaeEbAL0T1vNOy3 oPPGBCX6HlW86BY49gtn/GYfbT0wtM/gf5Dblvt+go21WNPbVudDtrNpJ68J0laquAEK AKGCD7TG9VauCoVar5P4J2Pf73G29WFccHAuB8GveRviQQGMFke5AOIxLWRPRAVwqqYz 5XlLrjf2Gb/lfQrRdACYNpTNPXWsfDlRl/EboZKcWrEq14vLZFHSEjrT6Ps8a1AGMh9o jL3Q== 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=fzODr4z/ehVsnzF8VSU8uExhuBVO0bsdLFUBjP7z150=; b=qpOSYIxrZa8YxRebn8uf0lPkwFkPQdc9glvmN5zt+fKEJvrhsBzC/youQizL2iwN6T 9aCjhsNuAuboxC+3eyhFNer1e6IwpYrVACoZiVjIRAg6uIFibyCTbGt7nn7tF1YspJwv P2JVD7QgTkh2OiWy3MnX6MKdHyya9KRTf/fPDbNob2RnEBBcw+NLhH+hREhmatxTEeL9 VB8FEem/IMzaBsJ8zfTNeuAwqR8J66xQ1g/td9XxO3KHBobtT3c8uVZO2OF1S9hoHZFg bmB5GpXX3Q6JX2McSnTKlQ+noDUySpYPztByERHDxBUjUrKhJ5EKcI98bxmPFa8mbNe4 iC9Q== X-Gm-Message-State: AOAM5321egScJEFku4yWnQikupcBpVgGAuCCsCkoglCyf5l9SxsbY0Cx +6tT827eY+pkeFyOpGF7LPE= X-Google-Smtp-Source: ABdhPJzPg0taXrLbj9VLFxttSzCLr3W4Y63FEBcBhrfHxGGNahiYo7tbemQlCm1cAss2awvpHFGmvg== X-Received: by 2002:a05:6a00:c92:: with SMTP id a18mr4230162pfv.37.1643348194375; Thu, 27 Jan 2022 21:36:34 -0800 (PST) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id q13sm7852611pfj.63.2022.01.27.21.36.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jan 2022 21:36:33 -0800 (PST) Date: Fri, 28 Jan 2022 14:36:31 +0900 (JST) Message-Id: <20220128.143631.654438319295147801.horikyota.ntt@gmail.com> To: rjuju123@gmail.com Cc: sergey.dudoladov@gmail.com, pgsql-hackers@lists.postgresql.org, kuntalghosh.2007@gmail.com, rafia.pghackers@gmail.com Subject: Re: Add connection active, idle time to pg_stat_activity From: Kyotaro Horiguchi In-Reply-To: <20220127123656.etovnhimr5sgp37f@jrouhaud> References: <20220125142245.w5ezlmpxeg47xz66@jrouhaud> <20220127123656.etovnhimr5sgp37f@jrouhaud> 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 Hi. At Thu, 27 Jan 2022 20:36:56 +0800, Julien Rouhaud wrote in > On Thu, Jan 27, 2022 at 11:43:26AM +0100, Sergey Dudoladov wrote: > > > > Per agreement with Rafia I have reworked the patch in the past days. > > The new version 6 is now ready for review. > > Great, thanks a lot Sergey! > > The cfbot is happy with this new version: > https://cirrus-ci.com/github/postgresql-cfbot/postgresql/commitfest/36/3405 I think we can easily add the duration of the current state to the two in pg_stat_get_activity and it would offer better information. if (beentry->st_state == STATE_RUNNING || beentry->st_state == STATE_FASTPATH) - pgstat_count_conn_active_time((PgStat_Counter) secs * 1000000 + usecs); + { + pgstat_count_conn_active_time((PgStat_Counter) usecs_diff); + beentry->st_total_active_time += usecs_diff; + } The two lines operates exactly the same way on variables with slightly different behavior. pgStatActiveTime is reported at transaction end and reset at every tabstat reporting. st_total_active_time is reported immediately and reset at session end. Since we do the latter, the first can be omitted by remembering the last values for the local variables at every reporting. This needs additional two exporting function in pgstatfuncs like pgstat_get_my_queryid so others might think differently. The write operation to beentry needs to be enclosed by PGSTAT_BEGIN/END_WRITE_ACTIVITY(). In that perspective, it would be better to move that writes to the PGSTAT_WRITE_ACTIVITY section just below. regards. -- Kyotaro Horiguchi NTT Open Source Software Center