Print pgbench results on SIGINT
Hi hackers!
While working on [1]https://github.com/yandex/odyssey or [2]https://github.com/pg-sharding/spqr/ I sometimes use pgbench in short-run mode:
see if there is some performance improvements or degradation for 5-10 seconds,
press CTRL+C, make some code changes and repeat the measurements.
For now, pgbench prints nothing on CTRL+C, which hides the run statistics
from user. What if it printed the collected statistics anyway, along with the
existing 'Run was aborted; the above results are incomplete.' message?
Attached POC-patch does:
- on first SIGINT stops accepting new transactions, discards the in-flight ones
and print the summary as usual, exiting with status 130
- on second SIGINT fallbacks to standard handler immediately
- caps all wait at one second, so the SIGINT can interrupt the \sleep
For now I am not sure about exit code..
Any feedback would be appreciated :)
[1]: https://github.com/yandex/odyssey
[2]: https://github.com/pg-sharding/spqr/
--
Best regards,
Roman Khapov
On Mon, 26 Oct 2026 at 11:42, Roman Khapov <rkhapov@yandex-team.ru> wrote:
Hi hackers!
Hi
While working on [1] or [2] I sometimes use pgbench in short-run mode:
see if there is some performance improvements or degradation for 5-10 seconds,
press CTRL+C, make some code changes and repeat the measurements.For now, pgbench prints nothing on CTRL+C, which hides the run statistics
from user. What if it printed the collected statistics anyway, along with the
existing 'Run was aborted; the above results are incomplete.' message?Attached POC-patch does:
- on first SIGINT stops accepting new transactions, discards the in-flight ones
and print the summary as usual, exiting with status 130
- on second SIGINT fallbacks to standard handler immediately
- caps all wait at one second, so the SIGINT can interrupt the \sleep
I think this enhances UX for manual testing/measurements, so overall
im +1 on this. Double ctrl^C kills pgbench instantly which I think is
good decision.
There is however a small bug where workers can submit new commands
after the stop flag is set.
The flag is checked once at the top of the outer threadRun loop, but a
worker whose EINTR check was missed can go through a full iteration of
the state machine after the flag changes. This can make a few
transactions to reach the server. Maybe we should check
aborted_by_sigint in more places
For now I am not sure about exit code..
There was an earlier related thread "Make pgbench exit on SIGINT more
reliably" [0]/messages/by-id/CSSWBAX56CVY.291H6ZNNHK7EO@c3po which may contain useful context on Windows handling.
[0]: /messages/by-id/CSSWBAX56CVY.291H6ZNNHK7EO@c3po
--
Best regards,
Kirill Reshke
Thanks for review!
There is however a small bug where workers can submit new commands
after the stop flag is set.
The flag is checked once at the top of the outer threadRun loop, but a
worker whose EINTR check was missed can go through a full iteration of
the state machine after the flag changes. This can make a few
transactions to reach the server. Maybe we should check
aborted_by_sigint in more places
Hmm, yes, seems like check must be done before advanceConnectionState(), attached v2
with the fix
There was an earlier related thread "Make pgbench exit on SIGINT more
reliably" [0] which may contain useful context on Windows handling.
thanks for link, will take a look!
--
Best regards,
Roman Khapov