Answer the question
In order to leave comments, you need to log in
How to speed up update in postgresql?
CREATE SEQUENCE ds_citizens_citizen_id_seq START WITH 1;
CREATE TABLE "ds_citizens" (
"citizen_id" bigint NOT NULL default nextval('ds_citizens_citizen_id_seq'),
"amount" decimal(30) NOT NULL DEFAULT '0'
);
ALTER SEQUENCE ds_citizens_citizen_id_seq owned by ds_citizens.citizen_id;
ALTER TABLE ONLY "ds_citizens" ADD CONSTRAINT ds_citizens_pkey PRIMARY KEY(citizen_id);
I insert 100k rows ~ 50 seconds.
In the loop I do
UPDATE ds_citizens SET amount=$1 WHERE citizen_id=$2
56 seconds
Proc takes 12-15% of all 4 cores a little bit, the disk almost does not touch, there is a lot of memory, the swap does not use.
OS: Ubuntu 64bit, postgresql 9.
full_page_writes = off Tell me
, please, how can I speed up the update?
udp
If after tr-ii, then 20 sec.
Same thing in sqlite3 - 1 sec :)
Answer the question
In order to leave comments, you need to log in
Specify a fillfactor for the table of about 70 (or less).
Do update in batches in transactions.
And make an index by citizen_id (as I understand it should be the primary key)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question