How to delete the oldest X number of rows? - Mailing list pgsql-novice

From John Roberts
Subject How to delete the oldest X number of rows?
Date
Msg-id BAY106-F2568E2920C04BCD4FC60ACBE460@phx.gbl
Whole thread Raw
Responses Re: How to delete the oldest X number of rows?
Re: How to delete the oldest X number of rows?
List pgsql-novice
Hi,

I have a table that logs the performance of a system. I get an entry in this
table each time the system does something.

I want to keep the last 50,000 rows in the table. I'd like to run a cron job
every 5 minutes that will delete all rows > 50,000, oldest first. What's the
most efficient way to do this query/delete?

DELETE FROM log WHERE timestamp < ????

I can come up with a way to do this using COUNT(*), but I'll bet there is a
smarter way.

THANKS for your help!

John



pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: transaction ID wrap limit is 2147484146 Start Postgresql with error in Logfile
Next
From: Mathieu Arnold
Date:
Subject: Re: How to delete the oldest X number of rows?