What would you say is the most efficient way to delete old records from a Postgres database in a Rails app?
I want to delete records that are a year old, would it be better to:
- run a script every night to delete records that are exactly one year old
- or run a script once a week (or once a month) to delete all records that are at least a year old
I guess I’ll need an index on the created_at field to speed up look-up, but which of the two options is the most sensible and efficient way to go about it?
(Or are there other options I haven’t considered?)
You’ll want to go with
That way, if it doesn’t get run one night, you can play catch up the 2nd night, or whenever it does start running again.