Purge log records–excluding audit level logging

Some time back, I wrote blog to delete log records older than 15 days from Genesys log database (here) From our support team, we had request to delete log records older than 15 days but want to retain audit level logging for 90 days.

To achieve this, add category filter in the purge query as below

— To delete attribute records which doesn’t have parent record

delete from G_LOG_ATTRS where LRID not in (select G_LOG_MESSAGES.ID from G_LOG_MESSAGES)

— To delete log attribute records older than 90 days excluding audit level logging

delete from G_LOG_ATTRS where LRID in (select G_LOG_MESSAGES.ID from G_LOG_MESSAGES where TIMEGENERATED < DATEADD(DAY, -90, GETDATE())and CATEGORY = 0)

— To delete log records older than 90 days excluding 90 days

delete from G_LOG_MESSAGES where TIMEGENERATED < DATEADD(DAY, -90, GETDATE()) and CATEGORY = 0