Skip to content

Commit f0b191f

Browse files
committed
Add PostgreSQL auto-commit caveat to JdbcCursorItemReader docs
Fixes #5040 Signed-off-by: helloJosh <[email protected]>
1 parent c257b99 commit f0b191f

File tree

1 file changed

+23
-0
lines changed
  • spring-batch-docs/modules/ROOT/pages/readers-and-writers

1 file changed

+23
-0
lines changed

spring-batch-docs/modules/ROOT/pages/readers-and-writers/database.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,29 @@ step processing. To use this feature, you need a database that supports this and
211211
driver supporting JDBC 3.0 or later. Defaults to `false`.
212212
|===============
213213

214+
[CAUTION]
215+
====
216+
When using `JdbcCursorItemReader` with PostgreSQL, server-side cursors are
217+
only enabled when the connection's auto-commit mode is disabled. If
218+
`autoCommit=true` (the default in many connection pools), PostgreSQL will
219+
materialize the entire result set in memory, which can lead to excessive
220+
memory usage or `OutOfMemoryError` for large datasets.
221+
222+
To avoid this issue, configure your `DataSource` with `autoCommit=false`.
223+
224+
For example, with HikariCP:
225+
[source,java]
226+
----
227+
HikariDataSource dataSource = new HikariDataSource();
228+
dataSource.setJdbcUrl("jdbc:postgresql://localhost:5432/mydb");
229+
dataSource.setUsername("user");
230+
dataSource.setPassword("password");
231+
dataSource.setAutoCommit(false); // Required for PostgreSQL cursor streaming
232+
----
233+
234+
This ensures that the cursor can stream rows efficiently instead of loading the
235+
entire result set at once.
236+
====
214237

215238
[[StoredProcedureItemReader]]
216239
=== `StoredProcedureItemReader`

0 commit comments

Comments
 (0)