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 1kSTD8-00030s-4M for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Oct 2020 22:56:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSTD6-0003SS-RG for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Oct 2020 22:56:00 +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 1kSTD6-0003SK-HE for pgsql-hackers@lists.postgresql.org; Tue, 13 Oct 2020 22:56:00 +0000 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kSTCz-0001Mu-AJ for pgsql-hackers@lists.postgresql.org; Tue, 13 Oct 2020 22:55:59 +0000 Received: by mail-io1-xd36.google.com with SMTP id n6so2412900ioc.12 for ; Tue, 13 Oct 2020 15:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Zx/M9MkKAJoqYeHOzssEVvj/8lyQPlU4WEtZNh/Z2iQ=; b=IOhijtDDiThEZ4W48u0miErUQcDWf6Shuco0A2FCWmo4N96eylz2SwzveVNBcE31vU +XJQJBR9kUAm5g1HmTyNL+59+XU01+XlyVCCV0N0K+Obnr/ifxzXX5FszVB052WyYoDp YAbJX129Azb/ZHopp6lSXmSyyAngQ5h4Y6kcFSgoJ5GQf+w2EJpikc3rJ6ZAuCIh1jtu +RzpnBePMejUz24qcz8QeHp2KQhGbByQhK+N236n/sbxBuEm/Iuv6es8U4m8z4XfYZCW nV1IBWwrkhzu0BstDuqTy95d038uKa9UDZMVJWitSc/LPW7thKiJ7kPIcZqs11CZqseF AToQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Zx/M9MkKAJoqYeHOzssEVvj/8lyQPlU4WEtZNh/Z2iQ=; b=Lb7hwQRs2UeDEPoh2LpwwMA0ZdtgsEikoS70dRre8prAotWfgqdqsP/j6aYHJduWaP 918NWSdUReTt1eBpYPS/lAXpBlTuaq6pm1u4WR8Yt6oV7op+SaMB+uT73tebU/JpoaV3 1jfkuQMBBKbKODcsYpdTjAyW9k30fCMBNnyIvBbpNA5iebOimafrVEz5EwH3vg55NjsJ qQF1IN9hoqxMp6OW+3nRWb0jnN7bivTU7wiBDQidMWgxJjzLlkwU8Eu9z3DTejAsAD8D MOGsvDFgo4e/yi9QzUAh6XpzPeA9Jdf41y2XJc2QGb63nyv/8V+x6jaA6Ty0/CJy+soy Z0mw== X-Gm-Message-State: AOAM531fyNCvhEiZBPGn24TNOKQU6yGGPgsCFqUTVJgSLJ+Ixa+kfYKk jL7TnvwRgR5ZluET+xgBo5oMQA== X-Google-Smtp-Source: ABdhPJxr8od6/tIVJ/wO1BLCht4/B79JeTw6oWjda6WIMUOrpZO8zXl6qjMN2l03jBQkX6/w2Qnqlw== X-Received: by 2002:a05:6638:622:: with SMTP id h2mr914993jar.86.1602629750748; Tue, 13 Oct 2020 15:55:50 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id w23sm1019447iod.45.2020.10.13.15.55.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Oct 2020 15:55:50 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 0C38B800559; Tue, 13 Oct 2020 17:55:48 -0500 (CDT) Date: Tue, 13 Oct 2020 17:55:48 -0500 From: Justin Pryzby To: Laurenz Albe Cc: Soumyadeep Chakraborty , Ahsan Hadi , ikedamsh@oss.nttdata.com, pgsql-hackers@lists.postgresql.org Subject: Re: Add session statistics to pg_stat_database Message-ID: <20201013225548.GQ9241@telsasoft.com> References: <68050bc3d927050061d0b106905d69b3bb39fed2.camel@cybertec.at> <70a90a9b4a7e1df47ede3b01774608246bd929ee.camel@cybertec.at> <95a4c49710cdf8be220bc8267872b171c2e3f182.camel@cybertec.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Oct 13, 2020 at 01:44:41PM +0200, Laurenz Albe wrote: > Attached is v3 with improvements. + + Time spent in database sessions in this database, in milliseconds. + Should say "Total time spent *by* DB sessions..." ? I think these counters are only accurate as of the last state change, right? So a session which has been idle for 1hr, that 1hr is not included. I think the documentation should explain that, or (ideally) the implementation would be more precise. Maybe the timestamps should only be updated after a session terminates (and the docs should say so). + + connections bigint + + + Number of connections established to this database. *Total* number of connections established, otherwise it sounds like it might mean "the number of sessions [currently] established". + Number of database sessions to this database that did not end + with a regular client disconnection. Does that mean "sessions which ended irregularly" ? Or does it also include "sessions which have not ended" ? + msg.m_aborted = (!disconnect || pgStatSessionDisconnected) ? 0 : 1; I think this can be just: msg.m_aborted = (bool) (disconnect && !pgStatSessionDisconnected); + if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) + result = 0; + else + result = ((double) dbentry->n_session_time) / 1000.0; I think these can say: |double result = 0; |if ((dbentry=..) != NULL) | result = (double) ..; That not only uses fewer LOC, but also the assignment to zero is (known to be) done at compile time (BSS) rather than runtime.