The DBD::Pg PostgreSQL bindings for Perl will always fetch the entire result set of your query. So if you are using a simple prepare execute to walk through a large table you will end up with the whole table in memory just by running $sth->execute(). Prepared statements and calls like fetch_row don't help.
The following will fail miserably if you are working with a BIG table.
use DBI;
my $dbh = DBI->connect("dbi:Pg:dbname=big_db","user","password",{
AutoCommit => 0,
ReadOnly => 1,
PrintError => 1,
RaiseError => 1,
});
my $sth = $dbh->prepare('SELECT * FROM big_table');
$sth->execute(); #prepare to run out of memory here
while (my $row = $sth->fetchrow_hashref('NAME_lc')){
# do something with the $row hash
}
$dbh->disconnect();