pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Justin Pryzby <pryzby@telsasoft.com>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: Soumyadeep Chakraborty <soumyadeep2007@gmail.com>
Cc: Ahsan Hadi <ahsan.hadi@gmail.com>
Cc: ikedamsh@oss.nttdata.com
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Add session statistics to pg_stat_database
Date: Tue, 13 Oct 2020 17:55:48 -0500
Message-ID: <20201013225548.GQ9241@telsasoft.com> (raw)
In-Reply-To: <f6849f80b02d2fa857687c67be4a6d5875500dd4.camel@cybertec.at>
References: <b07e1f9953701b90c66ed368656f2aef40cac4fb.camel@cybertec.at>
	<CA+9bhC+pGpp9xezwk-maOWmOCNg-0xm5OnPSSMmb2S=n7fTwMA@mail.gmail.com>
	<68050bc3d927050061d0b106905d69b3bb39fed2.camel@cybertec.at>
	<70a90a9b4a7e1df47ede3b01774608246bd929ee.camel@cybertec.at>
	<CAE-ML+_z17fYZ_R-EeusTNk_8ewYgn5WyeKnC5ctNFjvVw9xdw@mail.gmail.com>
	<95a4c49710cdf8be220bc8267872b171c2e3f182.camel@cybertec.at>
	<CAE-ML+_MGVnMdwbCjZP6ZxDbT1980J2Az-C6bshHhGwSrijRng@mail.gmail.com>
	<f6849f80b02d2fa857687c67be4a6d5875500dd4.camel@cybertec.at>

On Tue, Oct 13, 2020 at 01:44:41PM +0200, Laurenz Albe wrote:
> Attached is v3 with improvements.

+      <para>
+       Time spent in database sessions in this database, in milliseconds.
+      </para></entry>

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).

+      <entry role="catalog_table_entry"><para role="column_definition">
+       <structfield>connections</structfield> <type>bigint</type>
+      </para>
+      <para>
+       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.





view thread (34+ messages)  latest in thread

Message-ID: <20201013225548.GQ9241@telsasoft.com>
Permalink:  ../20201013225548.GQ9241@telsasoft.com/
Also on:    postgresql.org/message-id/20201013225548.GQ9241@telsasoft.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: pryzby@telsasoft.com, laurenz.albe@cybertec.at, soumyadeep2007@gmail.com, ahsan.hadi@gmail.com, ikedamsh@oss.nttdata.com
  Subject: Re: Add session statistics to pg_stat_database
  In-Reply-To: <20201013225548.GQ9241@telsasoft.com>
  References: <b07e1f9953701b90c66ed368656f2aef40cac4fb.camel@cybertec.at> <CA+9bhC+pGpp9xezwk-maOWmOCNg-0xm5OnPSSMmb2S=n7fTwMA@mail.gmail.com> <68050bc3d927050061d0b106905d69b3bb39fed2.camel@cybertec.at> <70a90a9b4a7e1df47ede3b01774608246bd929ee.camel@cybertec.at> <CAE-ML+_z17fYZ_R-EeusTNk_8ewYgn5WyeKnC5ctNFjvVw9xdw@mail.gmail.com> <95a4c49710cdf8be220bc8267872b171c2e3f182.camel@cybertec.at> <CAE-ML+_MGVnMdwbCjZP6ZxDbT1980J2Az-C6bshHhGwSrijRng@mail.gmail.com> <f6849f80b02d2fa857687c67be4a6d5875500dd4.camel@cybertec.at> <20201013225548.GQ9241@telsasoft.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox