http://www.perlmonks.org?node_id=1081261


in reply to Help on selecting and deleting many records in a DB.

Perl will simply run SQL, via DBI; it will not be faster than running the SQL directly (it will even be (a very little) slower). And you can run cursors in straight SQL too (well, in plpgsql); cursors have nothing especially to do with perl.

Perhaps perl gives you some more flexibility.

Which version of postgresql?

How large is the table (in GB and in rowcount)? And how large the part to be deleted?

One approach to data removal is to setup the data as a partitioned table (partitioned by date/timestamptz) which then lets you regularly drop the oldest table. See the fine manual (on that page, read also the partition caveats; mainly: don't use more than a few hundred partitions).