A db:select (or any query operation) against PostgreSQL does not stream its results as expected. Even though the Database Connector documents that query results are streamed automatically, the PostgreSQL JDBC driver fetches the entire result set in a single round trip instead of paging through it with a server-side cursor. For large result sets this defeats streaming — the full result set is retrieved from the database before the flow starts processing rows.
Typical signals:
fetchSize on the operation has no effect — the driver fetches every row regardless.This is a PostgreSQL JDBC (pgjdbc) behavior, not a connector defect. On PostgreSQL a server-side cursor — the thing that lets the driver fetch rows in batches instead of materializing them all — only exists inside a transaction. pgjdbc therefore only honors fetchSize (only streams) when the connection has autoCommit = false.
When autoCommit = true, pgjdbc ignores fetchSize and retrieves the entire result set in a single round trip instead of fetching it in batches through a cursor.
How this interacts with the Database Connector:
fetchSize to the JDBC Statement.autoCommit = false when a Mule transaction is started.transactionalAction="NOT_SUPPORTED") keeps autoCommit = true. So pgjdbc never opens a cursor and fetches the whole result set at once instead of streaming it.There is no simple property to flip this:
autoCommit connection/URL property — it cannot be set on the JDBC URL.db:generic-connection and the pooling profile do not expose an autoCommit setting.autoCommit=false connections.So the only two levers are: be inside a transaction, or supply a connection that already has autoCommit=false. That gives the two workarounds below.
Note on other databases: databases whose JDBC drivers stream without a transaction (for example, where the fetch size alone is enough) are not affected. This limitation is specific to drivers — PostgreSQL among them — that bind the cursor to a transaction.
Put the query inside a <try> scope with transactionalAction="ALWAYS_BEGIN". The transaction sets autoCommit = false, so pgjdbc opens a server-side cursor and streams.
Critical: the transaction must span the consumption of the result, not just the Select. If the scope commits/exits before the stream is read, the cursor and ResultSet are closed and you get:
org.postgresql.util.PSQLException: This ResultSet is closed.
Notes:
transactionalAction="NOT_SUPPORTED" so they don't try to join the source transaction. They commit independently.Instead of relying on a Mule transaction, hand the connector a javax.sql.DataSource that already hands out connections with autoCommit = false, and reference it with db:data-source-connection.
When a DataSource is supplied this way, the connector uses it directly and does not build its internal c3p0 pool. Because autoCommit is off at the connection level (not via a Mule transaction), the cursor streams and the connection is held for the whole message — so the stream survives the Select returning from a sub-flow, with no transaction scope anywhere in the flow. Only the source db:config changes.
Back the DataSource with a connection pool so connections are pooled/reused and the read transaction is rolled back on return (no "idle in transaction" leak). The example below uses HikariCP; Apache DBCP2 (defaultAutoCommit=false) works equally well. HikariCP is convenient because autoCommit=false is a single property and it rolls back dirty connections on return automatically.
pom.xml (so it's packaged with the app):<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>4.0.3</version>
</dependency>
db:config:<object name="pgStreamingDataSource" class="com.mycompany.util.PooledAutoCommitOffDataSource">
<property key="url" value="jdbc:postgresql://host:5432/sourcedb"/>
<property key="user" value="${source.user}"/>
<property key="password" value="${source.password}"/>
<property key="maxPoolSize" value="4"/>
</object>
<db:config name="Source_DB">
<db:data-source-connection dataSourceRef="pgStreamingDataSource"/>
</db:config>
The contents of this article are provided for informational purposes only, and the workarounds are intended to be used solely as references.
005460802

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.