原因:org.postgresql.util.PSQLException:发送到后端时发生I / O错误

问题描述 投票:0回答:1

我正在使用mybatis将数据插入到PostgreSQL数据库中。我要插入19629条记录。我正在尝试一次插入所有记录。但是,如果我将超过6k的记录传递给查询,则会得到原因:org.postgresql.util.PSQLException:发送至后端时发生I / O错误。

因此,一次在PostgreSQL中插入记录的数量是否有限制?

Mybatis代码。

{ @Insert({ "<script>","insert into temp_overdrive_csv_dtls (lpat_library_card_number,day_of_use,sessions,minutes_read,hours_read,sys_created_by)","values ", "<foreach  collection='recordList' item='record' separator=','>","(#{record.lpatLibraryCardNumber},#{record.dayofUse}, #{record.sessions}, #{record.minutesRead}, #{record.hoursRead}, #{record.sysCreatedBy})","</foreach>", "</script>" })public Integer insert(@Param("recordList") List<CsvRecord> recordList); 

错误。

Error updating database.  Cause: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.

错误可能涉及com.apds.mybatis.mapper.overdrive.OverdriveTotMapper.insert-Inline

设置参数时发生错误SQL:插入temp_overdrive_csv_dtls(lpat_library_card_number,day_of_use,sessions,minutes_read,hours_read,sys_created_by)值(?,?,?,?,?,?,?),(?,?,?,?,?,?,?),(?, ?,?,?,?,?),(?,?,?,?,?,?),,(?,?,?,?,?,?,?)

原因:org.postgresql.util.PSQLException:发送到后端时发生I / O错误。

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:150)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:46)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
at com.sun.proxy.$Proxy79.insert(Unknown Source)
at com.apds.overdrive.service.OverdriveService.processRequest(OverdriveService.java:105)
at com.apds.overdrive.PartnerOverdriveApplication.main(PartnerOverdriveApplication.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)Caused by: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:336)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:446)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:370)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:149)
at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:138)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:41)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:66)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:45)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:100)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:148)
... 11 more

Caused by: java.io.IOException: Tried to send an out-of-range integer as a 2-byte value: 36000
at org.postgresql.core.PGStream.sendInteger2(PGStream.java:252)
at org.postgresql.core.v3.QueryExecutorImpl.sendParse(QueryExecutorImpl.java:1470)
at org.postgresql.core.v3.QueryExecutorImpl.sendOneQuery(QueryExecutorImpl.java:1793)
at org.postgresql.core.v3.QueryExecutorImpl.sendQuery(QueryExecutorImpl.java:1356)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:301)
... 21 more
postgresql mybatis psql ioexception spring-mybatis
1个回答
0
投票

不是行数,而是占位符数。大多数驱动程序对PreparedStatement的占位符数量有限制(我认为pgjdbc为32767)。这是在插入或更新大量行时不建议多行插入的原因之一(另一个原因是性能)。

您应该切换到批量插入。请参见此answer以获取示例代码。

© www.soinside.com 2019 - 2024. All rights reserved.