Parallel table update using python multiprocessing (PostGIS/PostgreSQL)

£可爱£侵袭症+ 提交于 2019-12-13 06:08:05

问题


Hi I have been using the multiprocessing approach for updating a huge postgis table from here and it works quite well, but my table doesn't seem to get updated unless I add a commit; statement at the end of

procQuery = 'UPDATE city SET gid_fkey = gid FROM country  WHERE ST_within((SELECT the_geom FROM city WHERE city_id = %s), country.the_geom) AND city_id = %s' % (self.a, self.a)

like

procQuery = 'UPDATE city SET gid_fkey = gid FROM country  WHERE ST_within((SELECT the_geom FROM city WHERE city_id = %s), country.the_geom) AND city_id = %s;commit;' % (self.a, self.a)

what could be the problem here?


回答1:


ok, I solved by setting the connection to autommit = True

class Consumer(multiprocessing.Process):

def __init__(self, task_queue, result_queue):

    multiprocessing.Process.__init__(self)
    self.task_queue = task_queue
    self.result_queue = result_queue
    self.pyConn = psycopg2.connect(**connstring)
    self.pyConn.autocommit = True


def run(self):
    proc_name = self.name
    while True:
        next_task = self.task_queue.get()
        if next_task is None:
            print 'Tasks Complete'
            self.task_queue.task_done()
            break            
        answer = next_task(connection=self.pyConn)
        self.task_queue.task_done()
        self.result_queue.put(answer)
    return


来源:https://stackoverflow.com/questions/30707826/parallel-table-update-using-python-multiprocessing-postgis-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!