Database maintenance

Someone who has a postgresql script that clears the position history and leaves only the last 3 months?

I found one but it's from mysql and it's 3 years ago

SET foreign_key_checks = 0;
DELETE FROM positions WHERE serverTime < DATE_ADD(NOW(), INTERVAL -3 MONTH);
UPDATE devices SET positionId = NULL WHERE positionId NOT IN (SELECT id FROM positions);
SET foreign_key_checks = 1;