今天在测试 postgresql 批量插入性能时候 竟然出现异常了:
PreparedStatement can have at most 65,535 parameters. Please consider using arrays, or splitting the query in several ones, or using COPY. Given query has xxxxxx parameters
翻译大致是说:
在SQL使用的参数数量超过了PostgreSQL允许的最大值65,535个参数。你当前的查询尝试使用了1,400,000个参数,远远超出了限制。
先提供下我的 代码
看异常是说我的参数超过了 65535 个
SQL: INSERT INTO design_voyage (ship_name,captain,ship_width,initial_draft,tail_draft,drainage_volume,speed,call_sign,depth,lbp,mmsi,maritime_satellite,dead_weight,goods_information,start_port,end_port,start_port_lat,start_port_lon,end_port_lat,end_port_lon,consult_library,search_voyage,voyage_correction,draw_the_route,track_calculation,create_time,update_time,is_delete)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) , (?,?,<...>,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) , (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) , (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ,
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) , (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ,
-
一个问号就是一个参数, 这么算的话就是
-
实体类 字段个数 * 50000条数据 确实是超出了
不知道为什么Postgresql会有这个限制 mysql就没有
不清楚这个限制能不能修改(懒得查了) 只能调整代码了
- 调整后如下
这个2000可不是随便写的 (这边要尽可能的接近postgresql的限制个数 65535) 来提高插入的个数
计算公式: 65535 / 实体类字段个数
65535 / 29 ≈ 2000
或者 万能的网友能不能告诉我 能不能修改postgresql的配置