It is important to keep your Orchestrator database free from clutter. To do this, we recommend:
- Using SQL Server Maintenance Solution
- Creating a separate database to save data before deleting it
- Deleting old data periodically
- Backing up the database
Using SQL Server Maintenance Solution
SQL Server Maintenance Solution is a set of scripts that enable you to run backups, integrity checks, and index and statistics maintenance on all editions of Microsoft SQL Server, starting with the 2005 version. Please see this GitHub project for more information.
Creating an Archive Database
It is recommended that you create a separate database in which to save items before you delete them. As a result, this database acts as an archive for the items that you may need to store for certain reasons, such as audits.
- Create a new database called, for example,
UiPathArchives:
create database UiPathArchives
- Create the following backup tables:
2.1.ArchiveLogswith the same structure as theLogstable:
select * into [UiPathArchives].[dbo].[ArchiveLogs] from [UiPath].[dbo].[Logs] where 1=2
2.2. ArchiveQueueItems, ArchiveQueueItemEvents, and ArchiveQueueItemComments with the same structure as the QueueItems, QueueItemsEvents , and QueueItemsComments tables:
select * into [UiPathArchives].[dbo].[ArchiveQueueItems] from
[UiPath].[dbo].[QueueItems] where 1=2
select * into [UiPathArchives].[dbo].[ArchiveQueueItemEvents] from [UiPath].[dbo].[QueueItemEvents] where 1=2
select * into [UiPathArchives].[dbo].[ArchiveQueueItemComments] from [UiPath].[dbo].[QueueItemComments] where
1=2
2.3. ArchiveRobotLogs with the same structure as the RobotLogs table:
select * into [UiPathArchives].[dbo].[ArchiveRobotLicenseLogs] from [UiPath].[dbo].[RobotLicenseLogs] where 1=2
2.4. TenantNotificationsArchive and UserNotificationsArchive with the same structure as the TenantNotifications and UserNotifications tables:
select * into [UiPathArchives].[dbo].[ArchiveTenantNotifications] from
[UiPath].[dbo].[TenantNotifications] where 1=2
select * into [UiPathArchives].[dbo].[ArchiveUserNotifications] from [UiPath].[dbo].[UserNotifications] where 1=2
2.5. ArchiveJobs with the same structure as the Jobs table:
select * into [UiPathArchives].[dbo].[ArchiveJobs] from [UiPath].[dbo].[Jobs] where 1=2
2.5. ArchiveAuditLogs and ArchiveAuditLogEntities with the same structure as the AuditLog and AuditLogEntities tables:
select * into [UiPathArchives].[dbo].[ArchiveAuditLogs] from
[UiPath].[dbo].[AuditLogs] where 1=2
select * into [UiPathArchives].[dbo].[ArchiveAuditLogEntities] from [UiPath].[dbo].[AuditLogEntities] where 1=2
2.6 ArchiveTasks with the same structure as the Tasks table:
select * into [UiPathArchives].[dbo].[ArchiveTasks] from [UiPath].[dbo].[Tasks] where 1=2
Old data is copied to these archives prior to being deleted when using the queries below.
Deleting Old Data Periodically
Queue Items
To delete successfully processed queue items, and related events and comments, of (status = 3) older than 60 days, for example, use the query below. Optionally, you can include a where clause for TenantId.
It can be executed manually or scheduled in an SQL Server Job.
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
begin transaction
-- create temp table with list of IDs that we want to delete
select ID as IdToDelete into #TempDeletedIds from QueueItems
where status=3
-- and TenantId = 1
-- and ReviewStatus != 0
and DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep
-------------------- QueueItemEvents
set identity_insert [UiPathArchives].[dbo].[ArchiveQueueItemEvents] on
insert into [UiPathArchives].[dbo].[ArchiveQueueItemEvents]
([Id],[TenantId],[OrganizationUnitId],[QueueItemId],[TimeStamp],[Action],[UserId],[Status],[ReviewStatus],[ReviewerUserId],[CreationTime],[CreatorUserId])
select
[Id],[TenantId],[OrganizationUnitId],[QueueItemId],[TimeStamp],[Action],[UserId],[Status],[ReviewStatus],[ReviewerUserId],[CreationTime],[CreatorUserId]
from [UiPath].[dbo].[QueueItemEvents]
where Exists (select 1 from #TempDeletedIds where IdToDelete = QueueItemId)
delete from [UiPath].[dbo].[QueueItemEvents]
where Exists (select 1 from #TempDeletedIds where IdToDelete = QueueItemId)
set identity_insert [UiPathArchives].[dbo].[ArchiveQueueItemEvents] off
-------------------- QueueItemComments
set identity_insert [UiPathArchives].[dbo].[ArchiveQueueItemComments] on
insert into [UiPathArchives].[dbo].[ArchiveQueueItemComments]
([Id],[TenantId],[OrganizationUnitId],[QueueItemId],[Text],[IsDeleted],[DeleterUserId],[DeletionTime],[LastModificationTime],[LastModifierUserId],[CreationTime],[CreatorUserId])
select
[Id],[TenantId],[OrganizationUnitId],[QueueItemId],[Text],[IsDeleted],[DeleterUserId],[DeletionTime],[LastModificationTime],[LastModifierUserId],[CreationTime],[CreatorUserId]
from [UiPath].[dbo].[QueueItemComments]
where Exists (select 1 from #TempDeletedIds where IdToDelete = QueueItemId)
delete from [UiPath].[dbo].[QueueItemComments]
where Exists (select 1 from #TempDeletedIds where IdToDelete = QueueItemId)
set identity_insert [UiPathArchives].[dbo].[ArchiveQueueItemComments] off
-------------------- QueueItems
set identity_insert [UiPathArchives].[dbo].[ArchiveQueueItems] on
insert into [UiPathArchives].[dbo].[ArchiveQueueItems]
([Id],[Priority],[QueueDefinitionId],[Key],[Status],[ReviewStatus],[RobotId],[StartProcessing],[EndProcessing],[SecondsInPreviousAttempts],[AncestorId],[RetryNumber],[SpecificData],[TenantId],[LastModificationTime],[LastModifierUserId],[CreationTime],[CreatorUserId],[DeferDate],[DueDate],[Progress],[Output],[OrganizationUnitId],[RowVersion],[ProcessingExceptionType],[HasDueDate],[Reference],[ReviewerUserId],[ProcessingExceptionReason],[ProcessingExceptionDetails],[ProcessingExceptionAssociatedImageFilePath],[ProcessingExceptionCreationTime],[CreatorJobId],[ExecutorJobId]
)
select
[Id],[Priority],[QueueDefinitionId],[Key],[Status],[ReviewStatus],[RobotId],[StartProcessing],[EndProcessing],[SecondsInPreviousAttempts],[AncestorId],[RetryNumber],[SpecificData],[TenantId],[LastModificationTime],[LastModifierUserId],
[CreationTime],[CreatorUserId],[DeferDate],[DueDate],[Progress],[Output],[OrganizationUnitId],NULL,[ProcessingExceptionType],[HasDueDate],[Reference],[ReviewerUserId],[ProcessingExceptionReason],[ProcessingExceptionDetails],[ProcessingExceptionAssociatedImageFilePath],[ProcessingExceptionCreationTime],[CreatorJobId],[ExecutorJobId]
from [UiPath].[dbo].[QueueItems]
where Exists (select 1 from #TempDeletedIds where IdToDelete = [UiPath].[dbo].[QueueItems].[Id])
delete from [UiPath].[dbo].[QueueItems]
where Exists (select 1 from #TempDeletedIds where IdToDelete = [UiPath].[dbo].[QueueItems].[Id])
set identity_insert [UiPathArchives].[dbo].[ArchiveQueueItems] off
drop table #TempDeletedIds
commit transaction
Logged Messages
We recommend deleting log messages that are older than 60 days. The example query below deletes old messages with level Info, older than 60 days. Adapt the query to your needs, changing the @NumberOfDaysToKeep parameter or adding where clauses for Level and TenantId.
Note:
If you don’t want to archive the logs that are deleted, simple remove the copy clause:
insert into [ArchiveLogs] select from [Logs].
It can be executed manually or scheduled in an SQL Server Job.
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
begin transaction
set identity_insert [UiPathArchives].[dbo].[ArchiveLogs] on
insert into [UiPathArchives].[dbo].[ArchiveLogs]
([Id],[OrganizationUnitId],[TenantId],[TimeStamp],[Level],[WindowsIdentity]
,[ProcessName],[JobKey],[RobotName],[Message],[RawMessage],[MachineId])
select
[Id],[OrganizationUnitId],[TenantId],[TimeStamp],[Level],[WindowsIdentity]
,[ProcessName],[JobKey],[RobotName],[Message],[RawMessage],[MachineId]
from [UiPath].[dbo].[Logs]
where 1=1
-- and level = 2
/*
0 = Verbose, 1 = Trace, 2 = Info,
3 = Warn, 4 = Error, 5 = Fatal
*/
-- and TenantId = 1 -- default tenant
and DateDiff(day, TimeStamp, GetDate()) > @NumberOfDaysToKeep
delete from [UiPath].[dbo].[Logs]
where 1=1
-- and level = 2
/*
0 = Verbose, 1 = Trace, 2 = Info,
3 = Warn, 4 = Error, 5 = Fatal
*/
-- and TenantId = 1 -- default tenant
and DateDiff(day, TimeStamp, GetDate()) > @NumberOfDaysToKeep
set identity_insert [UiPathArchives].[dbo].[ArchiveLogs] off
commit transaction
RobotLicense Logs
We recommend deleting the items that are older than 60 days in your RobotLicenseLogs table. The example query below deletes items older than 60 days. Adapt the query to your needs, changing the @NumberOfDaysToKeep parameter or adding where clauses for TenantId.
Note:
If you don’t want to archive the logs that are deleted, simple remove the copy clause:
insert into [ArchiveRobotLicenseLogs] select from [RobotLicenseLogs].
It can be executed manually or scheduled in an SQL Server Job.
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
begin transaction
set identity_insert [UiPathArchives].[dbo].[ArchiveRobotLicenseLogs] on
insert into [UiPathArchives].[dbo].[ArchiveRobotLicenseLogs]
([Id],[RobotId],[StartDate],[EndDate],[RobotType],[TenantId],[Scope],[Key],[Slots],
[LicenseKey],[Properties],[ErrorCode])
select
[Id],[RobotId],[StartDate],[EndDate],[RobotType],[TenantId],[Scope],[Key],[Slots],
[LicenseKey],[Properties],[ErrorCode]
from [UiPath].[dbo].[RobotLicenseLogs]
where EndDate is not null
-- and TenantId = 1 -- default tenant
and DateDiff(day, EndDate, GetDate()) > @NumberOfDaysToKeep
delete from [UiPath].[dbo].[RobotLicenseLogs]
where EndDate is not null
-- and TenantId = 1 -- default tenant
and DateDiff(day, EndDate, GetDate()) > @NumberOfDaysToKeep
set identity_insert [UiPathArchives].[dbo].[ArchiveRobotLicenseLogs] off
commit transaction
TenantNotifications / UserNotifications Cleanup
We recommend deleting the items that are older than 60 days in your TenantNotifications and UserNotifications tablea. The example query below deletes items older than 60 days. Adapt the query to your needs, changing the @NumberOfDaysToKeep parameter or adding where clauses for TenantId.
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
begin transaction
-- create a temp table with list of IDs that we want to delete
select ID as IdToDelete into #TempDeletedIds from TenantNotifications
where 1=1
-- and TenantId = 1
and DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep
-------------------- UserNotifications
insert into [UiPathArchives].[dbo].[ArchiveUserNotifications]
([Id],[UserId],[TenantNotificationId],[State],[CreationTime],[TenantId])
select
[Id],[UserId],[TenantNotificationId],[State],[CreationTime],[TenantId]
from [UiPath].[dbo].[UserNotifications]
where Exists (select 1 from #TempDeletedIds where IdToDelete = TenantNotificationId)
delete from [UiPath].[dbo].[UserNotifications]
where Exists (select 1 from #TempDeletedIds where IdToDelete = TenantNotificationId)
-------------------- TenantNotifications
insert into [UiPathArchives].[dbo].[ArchiveTenantNotifications]
([Id],[TenantId],[NotificationName],[Data],[DataTypeName],[EntityTypeName],
[EntityTypeAssemblyQualifiedName],[EntityId],[Severity],[CreationTime],[CreatorUserId])
select
[Id],[TenantId],[NotificationName],[Data],[DataTypeName],[EntityTypeName]
,[EntityTypeAssemblyQualifiedName],[EntityId],[Severity],[CreationTime],[CreatorUserId]
from [UiPath].[dbo].[TenantNotifications]
where Exists (select 1 from #TempDeletedIds where IdToDelete = [UiPath].[dbo].[TenantNotifications].[Id])
delete from [UiPath].[dbo].[TenantNotifications]
where Exists (select 1 from #TempDeletedIds where IdToDelete = [UiPath].[dbo].[TenantNotifications].[Id])
drop table #TempDeletedIds
commit transaction
Jobs Cleanup
We recommend deleting the items that are older than 60 days in your RobotLicenseLogs table. The example query below deletes items older than 60 days. Adapt the query to your needs, changing the @NumberOfDaysToKeep parameter or adding where clauses for TenantId.
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
begin transaction
set identity_insert [UiPathArchives].[dbo].[Archivejobs] on
insert into [UiPathArchives].[dbo].[Archivejobs]
([Id],[TenantId],[Key],[StartTime],[EndTime],[State],[RobotId],[ReleaseId]
,[Source],[BatchExecutionKey],[Info],[IsDeleted],[DeleterUserId],[DeletionTime]
,[LastModificationTime],[LastModifierUserId],[CreationTime],[CreatorUserId]
,[OrganizationUnitId],[StartingScheduleId],[Type],[InputArguments],[OutputArguments])
select
[Id],[TenantId],[Key],[StartTime],[EndTime],[State],[RobotId],[ReleaseId]
,[Source],[BatchExecutionKey],[Info],[IsDeleted],[DeleterUserId],[DeletionTime]
,[LastModificationTime],[LastModifierUserId],[CreationTime],[CreatorUserId]
,[OrganizationUnitId],[StartingScheduleId],[Type],[InputArguments],[OutputArguments]
from [UiPath].[dbo].[jobs]
where 1=1
-- and State = 4
/*
0 = ?, 1 = ?, 2 = ?,
3 = ?, 4 = Completed, 5 = ?
*/
-- and TenantId = 1 -- default tenant
and DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep
delete from [UiPath].[dbo].[jobs]
where 1=1
-- and State = 4
/*
0 = ?, 1 = ?, 2 = ?,
3 = ?, 4 = Completed, 5 = ?
*/
-- and TenantId = 1 -- default tenant
and DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep
set identity_insert [UiPathArchives].[dbo].[Archivejobs] off
commit transaction
AuditLogs and AuditLogEntities Cleanup
We recommend deleting the items that are older than 60 days in your RobotLicenseLogs table. The example query below deletes items older than 60 days. Adapt the query to your needs, changing the @NumberOfDaysToKeep parameter or adding where clauses for TenantId.
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
begin transaction
-- create temp table with list of IDs that we want to delete
select ID as IdToDelete into #TempDeletedIds from AuditLogs
where 1=1
-- and TenantId = 1
and DateDiff(day, ExecutionTime, GetDate()) > @NumberOfDaysToKeep
-------------------- AuditLogEntities
set identity_insert [UiPathArchives].[dbo].[ArchiveAuditLogEntities] on
insert into [UiPathArchives].[dbo].[ArchiveAuditLogEntities]
([Id],[EntityName],[EntityId],[AuditLogId],[CustomData],[Action])
select
[Id],[EntityName],[EntityId],[AuditLogId],[CustomData],[Action]
from [UiPath].[dbo].[AuditLogEntities]
where Exists (select 1 from #TempDeletedIds where IdToDelete = AuditLogId)
delete from [UiPath].[dbo].[AuditLogEntities]
where Exists (select 1 from #TempDeletedIds where IdToDelete = AuditLogId)
set identity_insert [UiPathArchives].[dbo].[ArchiveAuditLogEntities] off
-------------------- AuditLogs
set identity_insert [UiPathArchives].[dbo].[ArchiveAuditLogs] on
insert into [UiPathArchives].[dbo].[ArchiveAuditLogs]
([Id],[TenantId],[UserId],[ServiceName],[MethodName],[Parameters],[ExecutionTime],[ExecutionDuration]
,[ClientIpAddress],[ClientName],[BrowserInfo],[Exception],[ImpersonatorUserId],[ImpersonatorTenantId]
,[CustomData],[Action],[Component],[DisplayName],[Version],[EntityId],[Discriminator])
select
[Id],[TenantId],[UserId],[ServiceName],[MethodName],[Parameters],[ExecutionTime],[ExecutionDuration]
,[ClientIpAddress],[ClientName],[BrowserInfo],[Exception],[ImpersonatorUserId],[ImpersonatorTenantId]
,[CustomData],[Action],[Component],[DisplayName],[Version],[EntityId],[Discriminator]
from [UiPath].[dbo].[AuditLogs]
where Exists (select 1 from #TempDeletedIds where IdToDelete = [UiPath].[dbo].[AuditLogs].[Id])
delete from [UiPath].[dbo].[AuditLogs]
where Exists (select 1 from #TempDeletedIds where IdToDelete = [UiPath].[dbo].[AuditLogs].[Id])
set identity_insert [UiPathArchives].[dbo].[ArchiveAuditLogs] off
drop table #TempDeletedIds
commit transaction
Actions Cleanup
We recommend deleting the competed items that are older than 60 days in your Tasks table.
Note: Actions are stored in the Tasks table.
The example query below deletes items older than 60 days. Adapt the query to your needs, changing the @NumberOfDaysToKeep parameter or adding where clauses for TenantId or OrganizationUnitId.
Note:
If you don’t want to archive the Tasks that are deleted, remove the
insert into [ArchiveTasks] select from [Tasks]statement.
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
begin transaction
set identity_insert [UiPathArchives].[dbo].[ArchiveTasks] on
insert into [UiPathArchives].[dbo].[ArchiveTasks] ([Id],[Title],[Priority],[Status],[AssignedToUserId],[FormLayout],[Data],[Action],[Type],[TenantId],[OrganizationUnitId],
[LastModificationTime],[LastModifierUserId],[CreationTime],[CreatorUserId],[IsDeleted],[DeleterUserId],[DeletionTime],[TaskCatalogId],[IsCompleted],[ExternalTag])
select
[Id],[Title],[Priority],[Status],[AssignedToUserId],[FormLayout],[Data],[Action],[Type],[TenantId],[OrganizationUnitId],
[LastModificationTime],[LastModifierUserId],[CreationTime],[CreatorUserId],[IsDeleted],[DeleterUserId],[DeletionTime],[TaskCatalogId],[IsCompleted],[ExternalTag]
from [UiPath].[dbo].[Tasks]
where 1=1
and Status = 2
/*
0 = Unassigned, 1 = Pending, 2 = Completed
*/
-- and TenantId = 1 -- default tenant
-- and OrganizationUnitId = 1 -- switch to the OrganizationUnit for which you want to delete
and DateDiff(day, LastModificationTime, GetDate()) > @NumberOfDaysToKeep
delete from [UiPath].[dbo].[Tasks]
where 1=1
and Status = 2
/*
0 = Unassigned, 1 = Pending, 2 = Completed
*/
-- and TenantId = 1 -- default tenant
and DateDiff(day, LastModificationTime, GetDate()) > @NumberOfDaysToKeep
set identity_insert [UiPathArchives].[dbo].[ArchiveTasks] off
commit transaction
Ledger Cleanup
We recommend deleting the items that are older than 45 days in your Ledger and LedgerDeliveries tables. The example query below deletes items older than 45 days.
It can be executed manually or scheduled in an SQL Server Job.
-- Ledger table cleanup
DELETE FROM [dbo].[Ledger] WHERE DateDiff(day, CreationTime, GetDate()) > 45
--LedgerDeliveries table cleanup
DELETE FROM [dbo].[LedgerDeliveries] WHERE DateDiff(day, LastUpdatedTime, GetDate()) > 45
Note:
If you want to modify how old the items to be deleted should be, replace the number 45 with the desired number of days, on the last line.
Elasticsearch
Orchestrator keeps one index for each tenant, for every month. Keeping old indices in Elasticsearch, even if they are not used in searches or reports, may affect its performance (memory consumption). As a result, it is recommended to delete old indices.
Backing Up the Database
We recommend you to implement regular backups of the SQL Server database, such as full weekly backups or daily incremental backups.
Additionally, we recommend you to use the DatabaseBackup stored procedure that is created using the script at this location.
Updated 2 years ago