| From: | "Pavlo Golub" <pavlo(dot)golub(at)cybertec(dot)at> |
|---|---|
| To: | "Sami Imseih" <samimseih(at)gmail(dot)com>, "Peter Eisentraut" <peter(at)eisentraut(dot)org> |
| Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | [PATCH v5] pg_stat_statements: Add last_execution_start column |
| Date: | 2026-06-10 17:36:24 |
| Message-ID: | emb8fcc6a9-d9a1-4d4c-a4e6-8d39d4c3c455@cybertec.at |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Thank you all for the thorough review in person and on the list. I hope
that v5 addresses all feedback.
Rebased on current master (e18b0cb7344).
Changes from v4:
The locking was inconsistent. The read is now inside the spinlock
together with the other counters, and the comment no longer hardcodes a
field count. Thanks to Zsolt Parragi for catching this.
The `es_exec_start` field is now set unconditionally in
`pgss_ExecutorStart`, not just when `pgss_enabled()`. Thanks to Sami
Imseih for pointing this out.
The planner hook no longer passes a timestamp to `pgss_store`.
`pgss_store` now skips the update when exec_start is zero.
`INT64CONST(0)` in the `pgss_ExecutorStart` was replaced with a plain 0
iconst. No idea why this was introduced in the first place.
The deferred-ExecutorEnd regression test is rewritten. The previous
version used `pg_sleep` with `\bind \g` inside an implicit transaction.
The new test uses an explicit `BEGIN/END` with `\bind \gset`. Thanks to
Anthonin Bonnefoy for the correct pattern and to Sami Imseih for
confirming it.
A DDL test is added to cover utility-statement paths. Not sure how it is
different from a DML statement though.
The redundant "test filtering" count query and the confusing
`stats_since` are removed from the basic update test. Extra comments
are also removed.
The documentation now includes a sample monitoring query, as it appeared
in
the original v1 submission.
Regarding Peter Eisentraut's concern (raised at pgconf.dev) about
top-level vs nested statement timestamps: for `toplevel = false` rows,
`last_execution_start` reflects the
start time of the enclosing top-level statement, not the nested one.
This is a consequence of how `GetCurrentStatementStartTimestamp()` works
and is documented. It means the field is not useful for timing
individual nested calls, but it is still useful for the stated purpose
of answering "when was this statement last active".
All pg_stat_statements regression tests that pass on master also pass
with this patch.
Magic number `PGSS_FILE_HEADER` is bumped to `0x20260610`.
v5 patch attached.
Best regards,
Pavlo Golub
| Attachment | Content-Type | Size |
|---|---|---|
| v5-0001-pg_stat_statements-Add-last_execution_start-colum.patch | application/octet-stream | 23.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Sehrope Sarkuni | 2026-06-10 17:45:55 | Assorted Win32 error handling fixes (CreateThread, pgwin32_select, pg_usleep) |
| Previous Message | Bertrand Drouvot | 2026-06-10 17:28:00 | Re: t/035_standby_logical_decoding.pl might fail on attempt to read wrong timeline |