Re: Suggestion to add --continue-client-on-abort option to pgbench
rintaro.ikeda@nttdata.com
From: <Rintaro.Ikeda@nttdata.com>
To: <ikedarintarof@oss.nttdata.com>, <slpmcf@gmail.com>,
<boekewurm+postgres@gmail.com>
Cc: <pgsql-hackers@postgresql.org>, <Nobuyuki12.Tanaka@nttdata.com>
Date: 2025-05-13T03:49:53Z
Lists: pgsql-hackers
Attachments
- 0001-add-continue-client-on-error-option-to-pgbench_ver2.patch (application/octet-stream) patch 0001
Hi Stepan and Matthias, Thank you both for your replies. I agree with Matthias's detailed explanation regarding the purpose of the patch. > Regarding the patch code, I noticed that there are duplicate case > entries in the command-line option handling (specifically for case 18 > or case ESTATUS_OTHER_SQL_ERROR, the continue-client-on-error option). > These duplicated cases can be merged to simplify the logic and reduce > redundancy. I also appreciate you for pointing out my mistakes in the previous version of the patch. I fixed the duplicated lines. I’ve attached the updated patch. Best regards, Rintaro Ikeda >> On Sat, May 10, 2025 at 8:45 PM ikedarintarof > <ikedarintarof@oss.nttdata.com> wrote: >>> >>> Hi hackers, >>> >>> I would like to suggest adding a new option to pgbench, which > enables >>> the client to continue processing transactions even if some errors > occur >>> during a transaction. >>> Currently, a client stops sending requests when its transaction is >>> aborted due to reasons other than serialization failures or > deadlocks. I >>> think in some cases, especially when using custom scripts, the > client >>> should be able to rollback the failed transaction and start a new > one. >>> >>> For example, my custom script (insert_to_unique_column.sql) > follows: >>> ``` >>> CREATE TABLE IF NOT EXISTS test (col1 serial, col2 int unique); >>> INSERT INTO test (col2) VALUES (random(0, 50000)); >>> ``` >>> Assume we need to continuously apply load to the server using 5 > clients >>> for a certain period of time. However, a client sometimes stops > when its >>> transaction in my custom script is aborted due to a check > constraint >>> violation. As a result, the load on the server is lower than > expected, >>> which is the problem I want to address. >>> >>> The proposed new option solves this problem. When >>> --continue-client-on-abort is set to true, the client rolls back > the >>> failed transaction and starts a new one. This allows all 5 clients > to >>> continuously apply load to the server, even if some transactions > fail. > > +1. I've had similar cases before too, where I'd wanted pgbench to > continue creating load on the server even if a transaction failed > server-side for any reason. Sometimes, I'd even want that type of > load. > > On Sat, 10 May 2025 at 17:02, Stepan Neretin <slpmcf@gmail.com> wrote: >> INSERT INTO test (col2) VALUES (random(0, 50000)); >> >> can be rewritten as: >> >> \setrandom val 0 50000 >> INSERT INTO test (col2) VALUES (:val) ON CONFLICT DO NOTHING; > > That won't test the same execution paths, so an option to explicitly > rollback or ignore failed transactions (rather than stopping the > benchmark) would be a nice feature. > With e.g. ON CONFLICT DO NOTHING you'll have much higher workload if > there are many conflicting entries, as that triggers and catches > per-row errors, rather than per-statement. E.g. INSERT INTO ... SELECT > ...multiple rows could conflict on multiple rows, but will fail on the > first conflict. DO NOTHING would cause full execution of the SELECT > statement, which has an inherently different performance profile. > >> This avoids transaction aborts entirely in the presence of > uniqueness violations and ensures the client continues to issue load > without interruption. In many real-world benchmarking scenarios, this > is the preferred and simplest approach. >> >> So from that angle, could you elaborate on specific cases where this > SQL-level workaround wouldn't be sufficient? Are there error types you > intend to handle that cannot be gracefully avoided or recovered from > using SQL constructs like ON CONFLICT, or SAVEPOINT/ROLLBACK TO? > > The issue isn't necessarily whether you can construct SQL scripts that > don't raise such errors (indeed, it's possible to do so for nearly any > command; you can run pl/pgsql procedures or DO blocks which catch and > ignore errors), but rather whether we can make pgbench function in a > way that can keep load on the server even when it notices an error. > > Kind regards, > > Matthias van de Meent > Neon (https://urldefense.com/v3/__https://neon.tech__;!!GCTRfqYYOYGmgK_z!92h3wOeDsDRQ1abfcL8-tRZqrAQ0w5RXwLNofOa_guIgDHdYknrizKqUGkvSn1_OU-xzMRv2halvtpUX7BFE8e3aPO_1-CZDhQ$ ) Hi Matthias, Thanks for your detailed explanation — it really helped clarify the usefulness of the patch. I agree that the feature is indeed valuable, and it's great to see it being pushed forward. Regarding the patch code, I noticed that there are duplicate case entries in the command-line option handling (specifically for case 18 or case ESTATUS_OTHER_SQL_ERROR, the continue-client-on-error option). These duplicated cases can be merged to simplify the logic and reduce redundancy. Best regards, Stepan Neretin
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
pgbench: Fix assertion failure with multiple \syncpipeline in pipeline mode.
- 5bc251b28839 17.8 landed
- 00e64e35c8bd 18.2 landed
- 4aa0ac05765e 19 (unreleased) landed
-
pgbench: Add --continue-on-error option.
- 0ab208fa505c 19 (unreleased) landed
-
Fix "inconsistent DLL linkage" warning on Windows MSVC
- a3ea5330fcf4 19 (unreleased) cited
-
pgbench: Fix error reporting in readCommandResponse().
- 7d7e81d1e6b8 13.23 landed
- cb21e1f92fb3 14.20 landed
- bdccb6302871 15.15 landed
- 36c4d30c8f24 16.11 landed
- a912118c6055 17.7 landed
- 29aabbc43269 18.1 landed
- 19d4f9ffc207 19 (unreleased) landed
-
pgbench: Fix assertion failure with retriable errors in pipeline mode.
- 704f517711b4 15.15 landed
- 8b2e290bde21 16.11 landed
- f39d9164b70a 17.7 landed
- c736808e03b7 18.1 landed
- 8bb174295e89 19 (unreleased) landed
-
Allow pgbench to retry in some cases.
- 4a39f87acd6e 15.0 cited