How to delete the oldest X number of rows?

Поиск
Список
Период
Сортировка
От John Roberts
Тема How to delete the oldest X number of rows?
Дата
Msg-id BAY106-F2568E2920C04BCD4FC60ACBE460@phx.gbl
обсуждение исходный текст
Ответы Re: How to delete the oldest X number of rows?  (Mathieu Arnold <mat@mat.cc>)
Re: How to delete the oldest X number of rows?  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: transaction ID wrap limit is 2147484146 Start Postgresql with error in Logfile
Следующее
От: Mathieu Arnold
Дата:
Сообщение: Re: How to delete the oldest X number of rows?