Fix performance regression from session statistics.
authorAndres Freund <[email protected]>
Thu, 16 Sep 2021 09:02:40 +0000 (02:02 -0700)
committerAndres Freund <[email protected]>
Thu, 16 Sep 2021 09:05:50 +0000 (02:05 -0700)
commit37a9aa659111c454386b7055dcd3809e45bc17de
tree3a5dd7b5b6d4f288f1eef499435823762254f939
parentdc899146dbf0e1d23fb24155a5155826ddce34c9
Fix performance regression from session statistics.

Session statistics, as introduced by 960869da08, had several shortcomings:

- an additional GetCurrentTimestamp() call that also impaired the accuracy of
  the data collected

  This can be avoided by passing the current timestamp we already have in
  pgstat_report_stat().

- an additional statistics UDP packet sent every 500ms

  This is solved by adding the new statistics to PgStat_MsgTabstat.
  This is conceptually ugly, because session statistics are not
  table statistics.  But the struct already contains data unrelated
  to tables, so there is not much damage done.

  Connection and disconnection are reported in separate messages, which
  reduces the number of additional messages to two messages per session and a
  slight increase in PgStat_MsgTabstat size (but the same number of table
  stats fit).

- Session time computation could overflow on systems where long is 32 bit.

Reported-By: Andres Freund <[email protected]>
Author: Andres Freund <[email protected]>
Author: Laurenz Albe <[email protected]>
Discussion: https://postgr.es/m/20210801205501.nyxzxoelqoo4x2qc%40alap3.anarazel.de
Backpatch: 14-, where the feature was introduced.
src/backend/postmaster/pgstat.c
src/backend/tcop/postgres.c
src/backend/utils/activity/backend_status.c
src/include/pgstat.h
src/tools/pgindent/typedefs.list