Fix performance regression from session statistics

Enterprise / PostgreSQL - Andres Freund [anarazel.de] - 16 September 2021 09:05 UTC

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.

37a9aa6591 Fix performance regression from session statistics.
src/backend/postmaster/pgstat.c | 195 ++++++++++++++++++----------
src/backend/tcop/postgres.c | 2 +
src/backend/utils/activity/backend_status.c | 4 +-
src/include/pgstat.h | 34 +++--
src/tools/pgindent/typedefs.list | 3 +-
5 files changed, 158 insertions(+), 80 deletions(-)

Upstream: git.postgresql.org


  • Share