pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: leandrokemp (@leandrokemp) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: [pgjdbc/pgjdbc] issue #3811: PreparedStatement batch performance issue in a loop on v42.7.6 or later
Date: Thu, 18 Sep 2025 21:28:15 +0000
Message-ID: <[email protected]> (raw)

**Describe the issue**
The app I work on run a loop of inserts and add those inserts to a PreparedStatement batch.
There are more than 100 thousand inserts, which are added to the batch in the loop.
On postgresql 42.7.5 and earlier versions the loop takes a few seconds to add all inserts to the ps batch.
From version 42.7.6, the loop hangs and never finishes. I've tested it for more than 30 minutes and it didn't finish. Nothing has changed in my app, except the postgresql library upgrade.

**Driver Version?**
42.7.6 

**Java Version?**
21

**OS Version?**
MacOS 26 and AWS Lambda container

**PostgreSQL Version?**
15

**To Reproduce**
```
import java.sql.*;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class TestBatchLoop {
    public static void main(String []args) throws Exception {

        String url = "jdbc:postgresql://localhost:5432/test";

        Properties props = new Properties();
        props.setProperty("user", "test");
        props.setProperty("password", "test");

        // generate a list with 100 thousand values
        List<String> values = IntStream.rangeClosed(1, 100_000)
                .mapToObj(i -> "value" + i)
                .collect(Collectors.toList());

        try ( Connection conn = DriverManager.getConnection(url, props) ){
            try ( PreparedStatement ps = conn.prepareStatement("insert into table(column) values(?)") ) {
                // on version 42.7.5 and earlier this finishes in a few seconds 
                // on version 42.7.6 and later this didn't finish until I stopped it after about 30 minutes
                for(String value : values) {
                    ps.setString(1, value);
                    String stm = ps.toString();
                    ps.addBatch();
                }
                ps.executeBatch();
                conn.commit();
            }
        }
    }
}
```

**Expected behaviour**
It should complete the loop in a few seconds

**Logs**
There are no logs. It just hangs in the loop


view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] issue #3811: PreparedStatement batch performance issue in a loop on v42.7.6 or later
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox