sql - How can I optimize this PostgreSQL query that updates every row? -
i wrote query update entire table. how can improve query take less time: update page_densities set density = round(density - 0.001, 2) query returned successfully: 628391 rows affected, 1754179 ms (29 minutes) execution time. edit: setting work memory.. set work_mem = '500mb'; update page_densities set density = round(density - 0.001, 2) query returned successfully: 628391 rows affected, 731711 ms (12 minutes) execution time. assuming density not index, may able improve performance different fillfactor. see question/answer or postgresql docs more info: http://www.postgresql.org/docs/9.4/static/sql-createtable.html slow simple update query on postgresql database 3 million rows although cannot modify table's fillfactor, can create new table different fill factor , copy data over. here sample code. --create new table different fill factor create table page_densities_new ( ...some fields here ) ( fillfactor=70 ); --copy of recor...