【发布时间】:2018-12-13 09:51:54
【问题描述】:
在向表中运行插入查询时,我在 psql (10.4) 中收到此错误。
ERROR: invalid memory alloc request size 1212052384
我尝试插入的数据是地理点数据,我猜测(因为文件大小为 303MB)大约有 2-3 百万个点,即单个记录。这对于一次性插入来说太大了吗? sql查询如下;它从文本文件复制 JSON 数据并插入数据库。尝试将单个形状存储为记录而不是点会更好,即更少的内存?
delete from shapes;
create temporary table temp_json (values text);
copy temp_json from '/Users/me/model/json/shapes_routes.json';
insert into shapes
select values->>'shape_id' as shape_id,
(CAST(values->>'shape_pt_lat' as real)) as shape_pt_lat,
(CAST(values->>'shape_pt_lon' as real)) as shape_pt_lon,
(CAST(values->>'shape_pt_sequence' as integer)) as shape_pt_sequence,
(CAST(values->>'shape_dist_traveled' as real)) as shape_dist_traveled,
values->>'route_id' as route_id
from (
select json_array_elements(replace(values,'\','\\')::json) as values
from temp_json
) a;
drop table temp_json;
【问题讨论】:
-
Postgres 有任何单个值(例如临时表元组中的字符串)不能超过 1 GB 的内部限制。是否有可能某些字符串 concat 操作会在 RAM 中生成超过 1 GB 的字符串?
标签: json postgresql psql