I am running a PostgreSQL 9.1 server on a Amazon EC2 medium instance (with an EBS storage). I am trying to run a simple UPDATE statement on about 3 millions row. It seems to take forever.
This is the update statement:
UPDATE "ab_device" SET "last_seen" = "ab_device"."registered_at";
The table:
Table "public.ab_device"
Column | Type | Modifiers
---------------+--------------------------+--------------------------------------------------------
id | integer | not null default nextval('ab_device_id_seq'::regclass)
uuid | character varying(255) | not null
registered_at | timestamp with time zone | not null
app_id | integer | not null
last_seen | timestamp with time zone | not null
Indexes:
"ab_tempdevice_pkey" PRIMARY KEY, btree (id)
"ab_device_app_id_56238bcbd52372f_uniq" UNIQUE CONSTRAINT, btree (app_id, uuid)
"ab_device_uuid" btree (uuid)
"ab_tempdevice_app_id" btree (app_id)
Foreign-key constraints:
"app_id_refs_id_9cb306ef" FOREIGN KEY (app_id) REFERENCES ab_app(id) DEFERRABLE INITIALLY DEFERRED
Referenced by:
TABLE "ab_trial" CONSTRAINT "device_id_refs_id_050eed1f" FOREIGN KEY (device_id) REFERENCES ab_device(id) DEFERRABLE INITIALLY DEFERRED
The "explain" of the request:
QUERY PLAN
--------------------------------------------------------------------------
Update on ab_device (cost=0.00..78210.65 rows=2761865 width=59)
-> Seq Scan on ab_device (cost=0.00..78210.65 rows=2761865 width=59)
(2 rows)
The CPU iowait is high when I run the request. Is it normal that the request takes a lot of time? Is it because of the I/O of the machine are poor?
Thank you for your insight.