0

I have a huge log table which is very busy in saving the user logs. My task is to schedule a job which keeps the last 3 days log or last 50k rows (whichever is greater) and deletes the rest. Shall this can be done through TABLE PARTITION.? I can't do this through DELETE statement which is very time expensive and stopping rows to be inserted. The table contains log_time as VARCHAR.

Thanks.

Felix Pamittan
  • 31,544
  • 7
  • 41
  • 67

2 Answers2

1

I can suggest you this simple solution:

  1. create every 3 days table named like log-2015-01-28 and write all logs between 2015-01-28 - 2015-01-30 to this table
  2. after 2015-01-30 create new table log-2015-01-28-31 and write all new rows to it
  3. DROP table log-2015-01-28 after 2 days

I think it must work very fast

stepozer
  • 1,143
  • 1
  • 10
  • 22
0

create trigger on insert

while trigger check the spaceused of the table .

if > 50k then delete the 'oldest row'

Dudi Konfino
  • 1,126
  • 2
  • 13
  • 24