我的postgres数据库(9.2.4和postgis 2.1.0SVN)中有一个全局数据集,行数约为11亿。我的目标是使用多边形提取相关的行。查询正在跟随并运行一天。
UPDATE table SET geom = ST_SetSRID(ST_MakePoint(long,lat),4326) where lat !=666 ;
666是缺失值的占位符。 column lat有btree索引。
free -m给出了我对ram的以下统计数据
total used free shared buffers cached
Mem: 24104 23829 275 0 5 22738
-/+ buffers/cache: 1084 23020
Swap: 24574 309 24265
htop显示我几乎没有CPU负载,内存为9%。
由于缺少ram,查询是否已经运行或有点搁置?
任何评论或提示赞赏。
如果可能,永远不要将更新用作批量操作。为此目的,更好的是CTAS以及删除和重命名表。首先,将表创建为select(CTAS)
Create table "new_table" as
select column_1, column_2.... column_n, ST_SetSRID(ST_MakePoint(long,lat),4326) geom
where lat !=666;
如有必要,请检查结果。
现在删除旧表并重命名新表。
drop table "old_table";
Alter table "new_table" rename "old_table".
为重命名的表创建所有需要的索引,外键等。
如果old_table上只有外键和其他约束
alter table old_table disable trigger all;