Suggestion to add --continue-client-on-abort option to pgbench

Rintaro Ikeda <ikedarintarof@oss.nttdata.com>

From: ikedarintarof <ikedarintarof@oss.nttdata.com>
To: pgsql-hackers@postgresql.org
Date: 2025-05-10T13:45:31Z
Lists: pgsql-hackers

Attachments

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.

```
% bin/pgbench -d postgres -f ../insert_to_unique_column.sql -T 10 
--failures-detailed --continue-client-on-error
transaction type: ../custom_script_insert.sql
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
maximum number of tries: 1
duration: 10 s
number of transactions actually processed: 33552
number of failed transactions: 21901 (39.495%)
number of serialization failures: 0 (0.000%)
number of deadlock failures: 0 (0.000%)
number of other failures: 21901 (39.495%)
latency average = 0.180 ms (including failures)
initial connection time = 2.857 ms
tps = 3356.092385 (without initial connection time)
```

I have attached the patch. I would appreciate your feedback.

Best regards,

Rintaro Ikeda
NTT DATA Corporation Japan

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. pgbench: Fix assertion failure with multiple \syncpipeline in pipeline mode.

  2. pgbench: Add --continue-on-error option.

  3. Fix "inconsistent DLL linkage" warning on Windows MSVC

  4. pgbench: Fix error reporting in readCommandResponse().

  5. pgbench: Fix assertion failure with retriable errors in pipeline mode.

  6. Allow pgbench to retry in some cases.