【发布时间】:2013-11-22 09:58:55
【问题描述】:
我在 Amazon EC2 介质实例(带有 EBS 存储)上运行 PostgreSQL 9.1 服务器。我正在尝试在大约 300 万行上运行一个简单的 UPDATE 语句。似乎需要永远。
这是更新声明:
UPDATE "ab_device" SET "last_seen" = "ab_device"."registered_at";
桌子:
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
请求的“解释”:
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)
运行请求时 CPU iowait 很高。请求花费大量时间是否正常?是不是因为机器的I/O不好?
感谢您的洞察力。
【问题讨论】:
-
Amazon 上的 IO 性能通常很糟糕 - 主要用于较长的任务。
标签: sql postgresql amazon-web-services amazon-ec2