Search code examples
postgresql

Postgresql delete old rows on a rolling basis?


I want to delete rows on one my tables that are more than 7 days old. What is the best way to do this? to make a cron job that runs every night or does PostgreSQL have built in features for doing something like this?


Solution

  • delete from the_table
    where the_timestamp < now() - interval '7 days'