Hello Laurenz, Thanks for submitting this! Please find my feedback below.
* Are we trying to capture ONLY client initiated disconnects in m_aborted (we are not handling other disconnects by not accounting for EOF..like if psql was killed)? If yes, why? * pgstat_send_connstats(): How about renaming the "force" argument to "disconnected"? * > static TimestampTz pgStatActiveStart = DT_NOBEGIN; > static PgStat_Counter pgStatActiveTime = 0; > static TimestampTz pgStatTransactionIdleStart = DT_NOBEGIN; > static PgStat_Counter pgStatTransactionIdleTime = 0; > static bool pgStatSessionReported = false; > bool pgStatSessionDisconnected = false; I think we can house all of these globals inside PgBackendStatus and can follow the protocol for reading/writing fields in PgBackendStatus. Refer: PGSTAT_{BEGIN|END}_WRITE_ACTIVITY Also, some of these fields are not required: I don't think we need pgStatActiveStart and pgStatTransactionIdleStart - instead of these two we could use PgBackendStatus.st_state_start_timestamp which marks the beginning TS of the backend's current state (st_state). We can look at that field along with the current and to-be-transitioned-to states inside pgstat_report_activity() when there is a transition away from STATE_RUNNING, STATE_IDLEINTRANSACTION or STATE_IDLEINTRANSACTION_ABORTED, in order to update pgStatActiveTime and pgStatTransactionIdleTime. We would also need to update those counters on disconnect/PGSTAT_STAT_INTERVAL timeout if the backend's current state was STATE_RUNNING, STATE_IDLEINTRANSACTION or STATE_IDLEINTRANSACTION_ABORTED (in pgstat_send_connstats()) pgStatSessionDisconnected is not required as it can be determined if a session has been disconnected by looking at the force argument to pgstat_report_stat() [unless we would want to distinguish between client-initiated disconnects, which I am not sure why, as I have brought up above]. pgStatSessionReported is not required. We can glean this information by checking if the function local static last_report in pgstat_report_stat() is 0 and passing this on as another param "first_report" to pgstat_send_connstats(). * PGSTAT_FILE_FORMAT_ID needs to be updated when a stats collector data structure changes and we had a change in PgStat_StatDBEntry. * We can directly use PgBackendStatus.st_proc_start_timestamp for calculating m_session_time. We can also choose to report session uptime even when the report is for the not-disconnect case (PGSTAT_STAT_INTERVAL elapsed). No reason why not. Then we would need to pass in the value of last_report to pgstat_send_connstats() -> calculate m_session_time to be number of time units from PgBackendStatus.st_proc_start_timestamp for the first report and then number of time units from the last_report for all subsequent reports. * We would need to bump the catalog version since we have made changes to system views. Refer: #define CATALOG_VERSION_NO Regards, Soumyadeep (VMware)