"Matthew Nuzum" <matt(dot)followers(at)gmail(dot)com> writes:
> Here is the query (BTW, there will be a corresponding "max" version of this
> query as well):
> INSERT INTO usage_sessions_min (accountid,atime,sessionid)
> select accountid, min(atime) as atime, sessionid from usage_access
> group by accountid,sessionid;
How many rows in usage_access? How many groups do you expect?
(Approximate answers are fine.) What PG version is this, and
what's your sort_mem setting?
regards, tom lane