You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "davidzollo (via GitHub)" <gi...@apache.org> on 2026/02/04 13:37:25 UTC

Re: [PR] [Fix][Connector-V2] Fix ORA-01461 error when writing to Oracle CLOB columns in batch mode [seatunnel]

davidzollo commented on PR #10118:
URL: https://github.com/apache/seatunnel/pull/10118#issuecomment-3847511248

   The current implementation utilizes `connection.createClob()` and `connection.createBlob()` to generate temporary LOB objects for every row. According to Oracle JDBC documentation, temporary LOBs created via these factory methods generally persist for the duration of the session unless `free()` is explicitly called.
   
   In SeaTunnel's batch mode, a single database connection/session is often reused to process millions of records. Since the `RowConverter` interface does not provide a mechanism to track and explicitly `free()` these LOB objects after the `PreparedStatement` is executed, this implementation will likely cause the Oracle **Temporary Tablespace** to fill up rapidly during large data syncs, leading to `ORA-01652: unable to extend temp segment` errors.
   
   **Suggestion**:
   I strongly recommend using the JDBC **Stream API** instead of creating explicit LOB objects. The Stream API is the standard, resource-safe way to handle large data without manual LOB lifecycle management. It is also generally effective in bypassing the `ORA-01461` error by treating the data as a stream rather than a direct string bind.
   
   **Recommended Changes**:
   
   ```java
   // ... inside setValueToStatementByDataType ...
   
   if (seaTunnelDataType.getSqlType().equals(SqlType.BYTES)) {
       if (ORACLE_BLOB.equals(sourceType)) {
           // Use setBinaryStream to handle large data and avoid ORA-01461
           // This avoids creating a temporary BLOB that needs manual freeing
           byte[] bytes = (byte[]) value;
           statement.setBinaryStream(statementIndex, new ByteArrayInputStream(bytes), bytes.length);
       } else {
           statement.setBytes(statementIndex, (byte[]) value);
       }
   } else if (seaTunnelDataType.getSqlType().equals(SqlType.STRING)) {
       if (ORACLE_CLOB.equals(sourceType) || ORACLE_NCLOB.equals(sourceType)) {
           // Use setCharacterStream for CLOB/NCLOB to avoid ORA-01461 and resource leaks
           String strValue = (String) value;
           statement.setCharacterStream(statementIndex, new StringReader(strValue), strValue.length());
       } else {
           statement.setString(statementIndex, (String) value);
       }
   }
   // ...
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org