June 24, 2017

In case you were wondering why silo.pub were down for ages, the database had finally filled up the disk. I eventually willed myself out of entropy and wrote a cron job to delete entries older than a year (or more than 2000th in their feed, from e.g. twitter-atom)

DELETE FROM entry

DELETE FROM entry
USING (
  SELECT
    id,
    ROW_NUMBER() OVER (PARTITION BY feed_id ORDER BY retrieved DESC) AS row
  FROM entry
) AS numbered
WHERE entry.id = numbered.id
  AND (row > 2000 OR retrieved < CURRENT_DATE - INTERVAL '365 days');

12:08pm PDT

Leave a comment

Your email address will not be published.