|
Navigation: Additional Tips and Resources > Database Tips > Purging Records |
|
|
The event log consolidation and process tracking tables might grow too large after a while. You can configure your system to periodically purge records that are no longer relevant, e.g. after 3 months. This chapter shows:
Microsoft SQL Server
Apply a descriptive name to this step, set the type to "Transact-SQL Script", select the correct database and paste the following SQL command into the "Command" window:
set QUOTED_IDENTIFIER on; delete from ESEventlogMain where DATEDIFF(day, eventtime, GETDATE()) > 90
where "EventSentry" is the name of the table and "90" are the number of days you want to keep records in the table. This script will remove all records from the table that are older than 90 days. Click OK to save this step.
Hint: To purge records from other tables as well simply repeat (5) and add another step, adapting the SQL script to reflect the new table name and field containing the time stamp. For the Process/Logon/Print Tracking, disk space, environment, service and application history tables the script would look like this:
set QUOTED_IDENTIFIER on; delete from ESPSTracking where DATEDIFF(day, start_datetime, GETDATE()) > 90 delete from ESLogonTracking where DATEDIFF(day, start_datetime, GETDATE()) > 90 delete from ESPrintTracking where DATEDIFF(day, start_datetime, GETDATE()) > 90
delete from ESAppHistory where DATEDIFF(day, recorddate, GETDATE()) > 180 delete from ESServiceHistory where DATEDIFF(day, recorddate, GETDATE()) > 180 delete from ESHeartbeatHistory where DATEDIFF(day, recorddate, GETDATE()) > 180
delete from ESPerformance where DATEDIFF(day, recorddate, GETDATE()) > 120 delete from ESDiskspace where DATEDIFF(day, recorddate, GETDATE()) > 90 delete from ESEnvironment where DATEDIFF(day, recorddate, GETDATE()) > 90
delete from ESFileMain where DATEDIFF(day, recorddate, GETDATE()) > 90 delete from ESFileMainDelim where DATEDIFF(day, recorddate, GETDATE()) > 90
delete from ESFilemonHistory where DATEDIFF(day, recorddate, GETDATE()) > 90
MySQL
MySQL does not currently ship with an equivalent of a SQL Server Agent where you would be able to schedule SQL commands. In order to run SQL commands on MySQL you can use a scripting language such as Perl for example, and you can then schedule your scripts using Windows' "Scheduled Tasks". Future versions of EventSentry will ship with an executable that will run SQL commands against a MySQL database.
In the meantime you can use the following SQL statements to purge records that are older than 90 or 180 days:
delete from ESEventlogMain where DATE_SUB(CURDATE(),INTERVAL 90 DAY) > eventtime
delete from ESPSTracking where DATE_SUB(CURDATE(),INTERVAL 90 DAY) > start_datetime delete from ESLogonTracking where DATE_SUB(CURDATE(),INTERVAL 90 DAY) > start_datetime delete from ESPrintTracking where DATE_SUB(CURDATE(),INTERVAL 90 DAY) > start_datetime
delete from ESAppHistory where DATE_SUB(CURDATE(),INTERVAL 180 DAY) > recorddate delete from ESServiceHistory where DATE_SUB(CURDATE(),INTERVAL 180 DAY) > recorddate delete from ESHeartbeatHistory where DATE_SUB(CURDATE(),INTERVAL 180 DAY) > recorddate
delete from ESPerformance where DATE_SUB(CURDATE(),INTERVAL 120 DAY) > recorddate delete from ESDiskspace where DATE_SUB(CURDATE(),INTERVAL 90 DAY) > recorddate delete from ESEnvironment where DATE_SUB(CURDATE(),INTERVAL 90 DAY) > recorddate
delete from ESFileMain where DATE_SUB(CURDATE(),INTERVAL 90 DAY) > recorddate delete from ESFileMainDelim where DATE_SUB(CURDATE(),INTERVAL 90 DAY) > recorddate
delete from ESFilemonHistory where DATE_SUB(CURDATE(),INTERVAL 90 DAY) > recorddate
Oracle
Oracle does not currently ship with an equivalent of a SQL Server Agent where you would be able to schedule SQL commands. In order to run SQL commands on Oracle you can use a scripting language such as Perl for example, and you can then schedule your scripts using Windows' "Scheduled Tasks". Future versions of EventSentry will ship with an executable that will run SQL commands against a Oracle database.
delete from ESEventlogMain where trunc(sysdate,'DAY') - eventtime + 1 > 90;
delete from ESPSTracking where trunc(sysdate,'DAY') - start_datetime + 1 > 90; delete from ESLogonTracking where trunc(sysdate,'DAY') - start_datetime + 1 > 90; delete from ESPrintTracking where trunc(sysdate,'DAY') - start_datetime + 1 > 90;
delete from ESAppHistory where trunc(sysdate,'DAY') - recorddate + 1 > 180; delete from ESServiceHistory where trunc(sysdate,'DAY') - recorddate + 1 > 180; delete from ESHeartbeatHistory where trunc(sysdate,'DAY') - recorddate + 1 > 180;
delete from ESPerformance where trunc(sysdate,'DAY') - recorddate + 1 > 120; delete from ESDiskspace where trunc(sysdate,'DAY') - recorddate + 1 > 90; delete from ESEnvironment where trunc(sysdate,'DAY') - recorddate + 1 > 90;
delete from ESFileMain where trunc(sysdate,'DAY') - recorddate + 1 > 90; delete from ESFileMainDelim where trunc(sysdate,'DAY') - recorddate + 1 > 90;
delete from ESFilemonHistory where trunc(sysdate,'DAY') - recorddate + 1 > 90; |