My coworkers and I studied the EXPLAIN and EXPLAIN ANALYZE output for this query and determined that the query planner seemed to be causing problems with this query. By calling "set enable_nestloop = off" before executing our query we were able to get the execution time down to under 2 minutes, which is acceptable for our purposes.
Tampering with the enable_xxx settings is NOT recommended for production systems. You might be better off posting the EXPLAIN ANALYSE details to the performance list.
-- Richard Huxton Archonet Ltd
---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives?
http://archives.postgresql.org