This issue recently came up on the mod_perl list. I brought the issue to the PostgreSQL irc channel and apparently libpq doesn't return rows individually as you might expect, instead loading the data into memory and then returning them one by one on a fetch basis IIRC. See
for a summary of the issue and a suggested solution using cursors in conjunction with DBI to handle retrievals of many rows from a PostgreSQL database.