Although the specifics are probably not worth it now, as you've already moved to a different database, you should _always_ look into tuning your database if you have queries that seem like they're running a bit long.
I don't know enough about your database, so I don't know exactly what might've been going wrong, but I'd probably look at the following:
In reply to Re^3: PostgreSQL cursors with Perl.
by jhourcle
in thread PostgreSQL cursors with Perl.
by atemerev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |