これは、データベースのパフォーマンス低下や障害を防ぐために重要です。そのために、次のことが推奨されます。
SQL サーバーのメンテナンスソリューションを使用する
SQL サーバーのメンテナンスソリューションは、バージョン 2005 以降のすべてのバージョンの Microsoft SQL サーバーについてバックアップ、完全性チェック、インデックス、統計のメンテナンスを行います。詳細については、この GitHub プロジェクトをご覧ください。
データベースをバックアップする
SQL サーバーのデータベースは、週 1 回の完全バックアップや毎日の差分バックアップなど、定期的にバックアップすることを推奨します。
Additionally, we recommend using the DatabaseBackup stored procedure that is created using the script at this location.
古いデータを定期的に削除する
共有されるスイート機能
削除する項目をあらかじめ保存しておくデータベースを別に作成しておきます。そうすることで、そのデータベースは監査などのために保存しておく必要がある項目のアーカイブとして機能します。
- たとえば、
UiPathArchives
という新しいデータベースを作成します。
create database UiPathArchives
- 次のバックアップ表を作成します。
2.1.AuditEvent
テーブルと同じ構造のArchiveAuditEvent
SELECT * INTO [UiPathArchives].[dbo].[ArchiveAuditEvent] from [accountmanagementdb].[adt].[AuditEvent] where 1 = 2
- データをアーカイブします。
3.1. 監査記録をアーカイブする
DECLARE @NumberOfDaysToKeep INT
DECLARE @CurrentDate DATETIME
-- Specify the number of days
SET @NumberOfDaysToKeep = 60
-- Archive the list of audit event records that you want to delete
SET @CurrentDate = GetDate()
BEGIN TRANSACTION
INSERT INTO [UiPathArchives].[dbo].[ArchiveAuditEvent]
SELECT
[Id],[CreatedOn],[Version],[OrganizationId],[Source],[Category],[Action],[IsUserEvent],
[UserId],[FullName],[Email],[DetailsVersion],[Details],[OperationId]
FROM [adt].[AuditEvent]
WHERE DateDiff(day, CreatedOn, @CurrentDate) > @NumberOfDaysToKeep
-- Delete the audit events
DELETE FROM [adt].[AuditEvent]
WHERE EXISTS (SELECT 1 FROM [UiPathArchives].[dbo].[ArchiveAuditEvent] WHERE Id = [adt].[AuditEvent].[Id])
COMMIT TRANSACTION
下記のクエリを使用すると、古いデータが削除される前にそれらのアーカイブにコピーされます。
- テーブルからデータを削除します。
重要
次のスクリプトを実行する前に、使用する環境に合わせて変更してください。
3.1. 監査イベント
declare @NumberOfDaysToKeep int
declare @CurrentDate datetime
-- Specify the number of days
SET @NumberOfDaysToKeep = 60
-- Create temporary table with the list of audit event records that you want to delete
SET @CurrentDate = GetDate()
SELECT
[Id],[CreatedOn],[Version],[OrganizationId],[Source],[Category],[Action],[IsUserEvent],
[UserId],[FullName],[Email],[DetailsVersion],[Details],[OperationId]
INTO #TempAuditRecordsToDelete
FROM [adt].[AuditEvent]
WHERE DateDiff(day, CreatedOn, @CurrentDate) > @NumberOfDaysToKeep
-- Review the audit event records to be deleted
SELECT * FROM #TempAuditRecordsToDelete
-- Delete the audit events
BEGIN TRANSACTION
DELETE FROM [adt].[AuditEvent]
WHERE EXISTS (SELECT 1 FROM #TempAuditRecordsToDelete WHERE Id = [adt].[AuditEvent].[Id])
DROP TABLE #TempAuditRecordsToDelete
COMMIT TRANSACTION
Identity Server
削除する項目をあらかじめ保存しておくデータベースを別に作成しておきます。そうすることで、そのデータベースは監査などのために保存しておく必要がある項目のアーカイブとして機能します。
- たとえば、
UiPathIdentityArchives
という新しいデータベースを作成します。
create database UiPathIdentityArchives
- 次のバックアップ表を作成します。
2.1.UserLoginAttempts
テーブルと同じ構造のArchiveLoginAttempts
select * into [UiPathIdentityArchives].[dbo].[ArchiveUserLoginAttempts] from [UiPath].[dbo].[UserLoginAttempts] where 1=2
下記のクエリを使用すると、古いデータが削除される前にそれらのアーカイブにコピーされます。
- テーブルからデータを削除します。
重要
次のスクリプトを実行する前に、使用する環境に合わせて変更してください。
3.1.ユーザー ログインの試行
60 日を経過したログイン試行を削除するには、以下のようなクエリを使用します。SQL サーバーのジョブで手動で実行するか、スケジュールに従って実行することができます。
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
if OBJECT_ID('[UiPathIdentityArchives].[dbo].[UserLoginAttemps]') = NULL
begin select * into [UiPathIdentityArchives].[dbo].[UserLoginAttemps] from [identity].UserLoginAttempts where 1=2 end
begin transaction
set identity_insert [UiPathIdentityArchives].[dbo].[UserLoginAttemps] on
insert into [UiPathIdentityArchives].[dbo].[UserLoginAttemps] ([Id],[PartitionId],[UserId],[UserNameOrEmailAddress],[ClientIpAddress],[ClientName],[BrowserInfo],[Result],[CreationTime],[AuthenticationProvider],[PartitionName])
select [Id],[PartitionId],[UserId],[UserNameOrEmailAddress],[ClientIpAddress],[ClientName],[BrowserInfo],[Result],[CreationTime],[AuthenticationProvider],[PartitionName]
from [identity].UserLoginAttempts where DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep
delete from [identity].UserLoginAttempts where DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep
commit transaction
Orchestrator
削除する項目をあらかじめ保存しておくデータベースを別に作成しておきます。そうすることで、そのデータベースは監査などのために保存しておく必要がある項目のアーカイブとして機能します。
- たとえば、
UiPathOrchestratorArchives
という新しいデータベースを作成します。
create database UiPathOrchestratorArchives
- 次のバックアップ表を作成します。
2.1.Logs
テーブルと同じ構造のArchiveLogs
select * into [UiPathOrchestratorArchives].[dbo].[ArchiveLogs] from [UiPath].[dbo].[Logs] where 1=2
2.2. QueueItems
、QueueItemsEvents
、および QueueItemsComments
テーブルと同じ構造の ArchiveQueueItems
、ArchiveQueueItemEvents
、および ArchiveQueueItemComments
select * into [UiPathOrchestratorArchives].[dbo].[ArchiveQueueItems] from
[UiPath].[dbo].[QueueItems] where 1=2
select * into [UiPathOrchestratorArchives].[dbo].[ArchiveQueueItemEvents] from [UiPath].[dbo].[QueueItemEvents] where 1=2
select * into [UiPathOrchestratorArchives].[dbo].[ArchiveQueueItemComments] from [UiPath].[dbo].[QueueItemComments] where
1=2
2.3. RobotLogs
テーブルと同じ構造の ArchiveRobotLogs
select * into [UiPathOrchestratorArchives].[dbo].[ArchiveRobotLicenseLogs] from [UiPath].[dbo].[RobotLicenseLogs] where 1=2
2.4. TenantNotifications
および UserNotifications
テーブルと同じ構造の TenantNotificationsArchive
および UserNotificationsArchive
select * into [UiPathOrchestratorArchives].[dbo].[ArchiveTenantNotifications] from
[UiPath].[dbo].[TenantNotifications] where 1=2
select * into [UiPathOrchestratorArchives].[dbo].[ArchiveUserNotifications] from [UiPath].[dbo].[UserNotifications] where 1=2
2.5. Jobs
テーブルと同じ構造の ArchiveJobs
select * into [UiPathOrchestratorArchives].[dbo].[ArchiveJobs] from [UiPath].[dbo].[Jobs] where 1=2
2.5. AuditLog
および AuditLogEntities
テーブルと同じ構造の ArchiveAuditLogs
および ArchiveAuditLogEntities
select * into [UiPathOrchestratorArchives].[dbo].[ArchiveAuditLogs] from
[UiPath].[dbo].[AuditLogs] where 1=2
select * into [UiPathOrchestratorArchives].[dbo].[ArchiveAuditLogEntities] from [UiPath].[dbo].[AuditLogEntities] where 1=2
2.6 Tasks
テーブルと同じ構造の ArchiveTasks
select * into [UiPathOrchestratorArchives].[dbo].[ArchiveTasks] from [UiPath].[dbo].[Tasks] where 1=2
下記のクエリーを使用すると、古いデータが削除される前にこれらのアーカイブにコピーされます。
- テーブルからデータを削除します。
重要
次のスクリプトを実行する前に、使用する環境に合わせたスクリプトにしてください。
3.1.キュー アイテム
60 日を経過した、正常に処理されたキュー アイテムおよび関連するイベントならびにコメント (status = 3
) を削除するには、たとえば以下のクエリを使用します。任意で、where
句を TenantId
に含めることができます。
SQL サーバーのジョブで手動で実行するか、スケジュールで実行することができます。
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 [UiPathOrchestratorArchives].[dbo].[ArchiveQueueItemEvents] on
insert into [UiPathOrchestratorArchives].[dbo].[ArchiveQueueItemEvents]
([Id],[TenantId],[OrganizationUnitId],[QueueItemId],[TimeStamp],[IsDeleted],[DeleterUserId],[DeletionTime],[Action],[UserId],[Status],[ReviewStatus],[ReviewerUserId],[CreationTime],[CreatorUserId])
select
[Id],[TenantId],[OrganizationUnitId],[QueueItemId],[TimeStamp],[IsDeleted],[DeleterUserId],[DeletionTime],[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 [UiPathOrchestratorArchives].[dbo].[ArchiveQueueItemEvents] off
-------------------- QueueItemComments
set identity_insert [UiPathOrchestratorArchives].[dbo].[ArchiveQueueItemComments] on
insert into [UiPathOrchestratorArchives].[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 [UiPathOrchestratorArchives].[dbo].[ArchiveQueueItemComments] off
-------------------- QueueItems
set identity_insert [UiPathOrchestratorArchives].[dbo].[ArchiveQueueItems] on
insert into [UiPathOrchestratorArchives].[dbo].[ArchiveQueueItems]
([Id],[Priority],[QueueDefinitionId],[Key],[Status],[IsDeleted],[DeleterUserId],[DeletionTime],[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],[AnalyticsData],[RiskSlaDate]
)
select
[Id],[Priority],[QueueDefinitionId],[Key],[Status],[IsDeleted],[DeleterUserId],[DeletionTime],[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],[AnalyticsData],[RiskSlaDate]
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 [UiPathOrchestratorArchives].[dbo].[ArchiveQueueItems] off
drop table #TempDeletedIds
commit transaction
3.2. ログメッセージ
60 日を経過したログ メッセージは、削除することを推奨します。下のクエリ例は、60 日を経過した Info レベルの古いメッセージを削除します。クエリをニーズに合わせて調整し、@NumberOfDaysToKeep
パラメーターを変更するか、Level
および TenantId
に where
句を追加します。
注:
削除されるログをアーカイブしたくない場合は、copy 句を削除してください。
insert into [ArchiveLogs] select from [Logs]
です。
SQL サーバーのジョブで手動で実行するか、スケジュールで実行することができます。
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
begin transaction
set identity_insert [UiPathOrchestratorArchives].[dbo].[ArchiveLogs] on
insert into [UiPathOrchestratorArchives].[dbo].[ArchiveLogs]
([Id],[OrganizationUnitId],[TenantId],[TimeStamp],[Level],[WindowsIdentity]
,[ProcessName],[JobKey],[RobotName],[Message],[RawMessage],[MachineId],[UserKey],[HostMachineName])
select
[Id],[OrganizationUnitId],[TenantId],[TimeStamp],[Level],[WindowsIdentity]
,[ProcessName],[JobKey],[RobotName],[Message],[RawMessage],[MachineId],[UserKey],[HostMachineName]
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 [UiPathOrchestratorArchives].[dbo].[ArchiveLogs] off
commit transaction
3.3. RobotLicenseLogs のクリーンアップ
RobotLicenseLogs
テーブル内の 60 日を経過した項目は、削除することを推奨します。下のクエリ例は、60 日を経過した古い項目を削除します。クエリをニーズに合わせて調整し、@NumberOfDaysToKeep
パラメーターを変更するか、TenantId
に where
句を追加します。
注:
削除されるログをアーカイブしたくない場合は、copy 句を削除してください。
insert into [ArchiveRobotLicenseLogs] select from [RobotLicenseLogs]
です。
SQL サーバーのジョブで手動で実行するか、スケジュールで実行することができます。
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
begin transaction
set identity_insert [UiPathOrchestratorArchives].[dbo].[ArchiveRobotLicenseLogs] on
insert into [UiPathOrchestratorArchives].[dbo].[ArchiveRobotLicenseLogs]
([Id],[RobotId],[StartDate],[EndDate],[RobotType],[TenantId],[Scope],[Key],[Slots],
[LicenseKey],[Properties],[ErrorCode],[JobKey])
select
[Id],[RobotId],[StartDate],[EndDate],[RobotType],[TenantId],[Scope],[Key],[Slots],
[LicenseKey],[Properties],[ErrorCode],[JobKey]
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 [UiPathOrchestratorArchives].[dbo].[ArchiveRobotLicenseLogs] off
commit transaction
3.4. TenantNotifications および UserNotifications のクリーンアップ
TenantNotifications
および UserNotifications
テーブル内の 60 日を経過した項目は、削除することを推奨します。下のクエリ例は、60 日を経過した古い項目を削除します。クエリをニーズに合わせて調整し、@NumberOfDaysToKeep
パラメーターを変更するか、TenantId
に where
句を追加します。
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 [UiPathOrchestratorArchives].[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 [UiPathOrchestratorArchives].[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
3.5.Jobs のクリーンアップ
Jobs
テーブル内の 60 日を経過した項目は、削除することを推奨します。下のクエリ例は、60 日を経過した古い項目を削除します。クエリをニーズに合わせて調整し、@NumberOfDaysToKeep
パラメーターを変更するか、TenantId
に where
句を追加します。
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
begin transaction
set identity_insert [UiPathOrchestratorArchives].[dbo].[ArchiveJobs] on
insert into [UiPathOrchestratorArchives].[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],[HostMachineName],[PersistenceId],[ResumeVersion],[SuspendBlobType],[PersistenceLocationVersion],[StopStrategy],[ReleaseVersionId],[EntryPointPath],[JobPriority],[RuntimeType],[MachineId],[RequiresUserInteraction],[ServiceUserName],[ResumeTime],[Reference])
select
[Id],[TenantId],[Key],[StartTime],[EndTime],[State],[RobotId],[ReleaseId]
,[Source],[BatchExecutionKey],[Info],[IsDeleted],[DeleterUserId],[DeletionTime]
,[LastModificationTime],[LastModifierUserId],[CreationTime],[CreatorUserId]
,[OrganizationUnitId],[StartingScheduleId],[Type],[InputArguments],[OutputArguments],[HostMachineName],[PersistenceId],[ResumeVersion],[SuspendBlobType],[PersistenceLocationVersion],[StopStrategy],[ReleaseVersionId],[EntryPointPath],[JobPriority],[RuntimeType],[MachineId],[RequiresUserInteraction],[ServiceUserName],[ResumeTime],[Reference]
from [UiPath].[dbo].[Jobs]
where 1=1
-- and State = 5
/*
0 = Pending, 1 = Running, 2 = Stopping, 3 = Terminating, 4 = Faulted,
5 = Successful, 6 = Stopped, 7 = Suspended, 8 = Resumed
*/
-- and TenantId = 1 -- default tenant
and DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep
delete from [UiPath].[dbo].[jobs]
where 1=1
-- and State = 5
/*
0 = Pending, 1 = Running, 2 = Stopping, 3 = Terminating, 4 = Faulted,
5 = Successful, 6 = Stopped, 7 = Suspended, 8 = Resumed
*/
-- and TenantId = 1 -- default tenant
and DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep
set identity_insert [UiPathOrchestratorArchives].[dbo].[Archivejobs] off
commit transaction
3.6.AuditLogs および AuditLogEntities のクリーンアップ
AuditLogs
および AuditLogEntities
テーブル内の 60 日を経過した項目は、削除することを推奨します。下のクエリ例は、60 日を経過した古い項目を削除します。クエリをニーズに合わせて調整し、@NumberOfDaysToKeep
パラメーターを変更するか、TenantId
に where
句を追加します。
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 [UiPathOrchestratorArchives].[dbo].[ArchiveAuditLogEntities] on
insert into [UiPathOrchestratorArchives].[dbo].[ArchiveAuditLogEntities]
([Id],[EntityName],[EntityId],[AuditLogId],[CustomData],[Action],[TenantId])
select
[Id],[EntityName],[EntityId],[AuditLogId],[CustomData],[Action],[TenantId]
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 [UiPathOrchestratorArchives].[dbo].[ArchiveAuditLogEntities] off
-------------------- AuditLogs
set identity_insert [UiPathOrchestratorArchives].[dbo].[ArchiveAuditLogs] on
insert into [UiPathOrchestratorArchives].[dbo].[ArchiveAuditLogs]
([Id],[TenantId],[UserId],[ServiceName],[MethodName],[Parameters],[ExecutionTime],[ExecutionDuration]
,[ClientIpAddress],[ClientName],[BrowserInfo],[Exception],[ImpersonatorUserId],[ImpersonatorTenantId]
,[CustomData],[Action],[Component],[DisplayName],[Version],[EntityId],[Discriminator],[ReturnValue],[IsGlobal])
select
[Id],[TenantId],[UserId],[ServiceName],[MethodName],[Parameters],[ExecutionTime],[ExecutionDuration]
,[ClientIpAddress],[ClientName],[BrowserInfo],[Exception],[ImpersonatorUserId],[ImpersonatorTenantId]
,[CustomData],[Action],[Component],[DisplayName],[Version],[EntityId],[Discriminator],[ReturnValue],[IsGlobal]
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 [UiPathOrchestratorArchives].[dbo].[ArchiveAuditLogs] off
drop table #TempDeletedIds
commit transaction
3.7. Actions のクリーンアップ
Tasks
テーブル内の 60 日を経過した、完了したアクションと論理削除したアクションは、削除することを推奨します。
Actions are stored in the Tasks table.
Deletion through UI marks the items as soft-deleted in the Tasks
table.
下のクエリ例では、60 日を経過した、完了したアイテム (Status = 2
) と論理削除されたアイテム (IsDeleted = 1
) を削除します。
クエリをニーズに合わせて調整し、@NumberOfDaysToKeep
パラメーターを変更するか、TenantId
または OrganizationUnitId
に where
句を追加します。
注:
削除されるタスクをアーカイブしたくない場合は、
insert into [ArchiveTasks] select from [Tasks]
のステートメントを削除してください。
declare @NumberOfDaysToKeep int
set @NumberOfDaysToKeep = 60
begin transaction
set identity_insert [UiPathOrchestratorArchives].[dbo].[ArchiveTasks] on
insert into [UiPathOrchestratorArchives].[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 ((IsDeleted = 1 and DateDiff(day, DeletionTime, GetDate()) > @NumberOfDaysToKeep)
or (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 ((IsDeleted = 1 and DateDiff(day, DeletionTime, GetDate()) > @NumberOfDaysToKeep)
or (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))
set identity_insert [UiPathOrchestratorArchives].[dbo].[ArchiveTasks] off
commit transaction
3.8. Ledger のクリーンアップ
Ledger
テーブルおよび LedgerDeliveries
テーブル内の 7 日を経過した項目は、削除することをお勧めします。下のクエリ例は、7 日を経過した古い項目を削除し、バッチ サイズ 1,000 エントリを適用しています。
SQL サーバーのジョブで手動で実行するか、スケジュールで実行することができます。
-- Ledger table cleanup
PRINT 'Starting maintenance on [Ledger] table.'
DECLARE @daysToKeep INT
DECLARE @batchSize INT
SET @daysToKeep = 7
SET @batchSize = 1000
DECLARE @currentDate DATETIME
SET @currentDate = GETDATE()
DECLARE @rowsToDelete INT
SET @rowsToDelete =
(SELECT COUNT(*)
FROM [dbo].[Ledger]
WHERE [CreationTime] < @currentDate-@daysToKeep)
DECLARE @rowsToKeep INT
SET @rowsToKeep =
(SELECT COUNT(*)
FROM [dbo].[Ledger]
WHERE [CreationTime] >= @currentDate-@daysToKeep)
PRINT 'Rows to delete:' + CAST(@rowsToDelete AS VARCHAR)
PRINT 'Rows to keep:'+ CAST(@rowsToKeep AS VARCHAR)
DECLARE @rowsDeleted INT
SET @rowsDeleted = 1
WHILE (@rowsDeleted > 0)
BEGIN
DELETE TOP(@batchSize) [dbo].[Ledger] WHERE [CreationTime] < @currentDate-@daysToKeep
OPTION (MAXDOP 1)
SET @rowsDeleted = @@ROWCOUNT
SET @rowsToDelete = IIF (@rowsToDelete > @batchSize, @rowsToDelete - @batchSize, 0)
PRINT 'Deleted ' + CAST(@rowsDeleted AS VARCHAR)+' rows. Remaining to delete:' + CAST(@rowsToDelete AS VARCHAR)
END
--LedgerDeliveries table cleanup
PRINT 'Starting maintenance on [LedgerDeliveries] table.'
SET @rowsToDelete =
(SELECT COUNT(*)
FROM [dbo].[LedgerDeliveries]
WHERE [LastUpdatedTime] < @currentDate-@daysToKeep)
SET @rowsToKeep =
(SELECT COUNT(*)
FROM [dbo].[LedgerDeliveries]
WHERE [LastUpdatedTime] >= @currentDate-@daysToKeep)
PRINT 'Rows to delete:' + CAST(@rowsToDelete AS VARCHAR)
PRINT 'Rows to keep:'+ CAST(@rowsToKeep AS VARCHAR)
SET @rowsDeleted = 1
WHILE (@rowsDeleted > 0)
BEGIN
DELETE TOP(@batchSize) [dbo].[LedgerDeliveries] WHERE [LastUpdatedTime] < @currentDate-@daysToKeep
OPTION (MAXDOP 1)
SET @rowsDeleted = @@ROWCOUNT
SET @rowsToDelete = IIF (@rowsToDelete > @batchSize, @rowsToDelete - @batchSize, 0)
PRINT 'Deleted ' + CAST(@rowsDeleted AS VARCHAR)+' rows. Remaining to delete:' + CAST(@rowsToDelete AS VARCHAR)
END
注:
@daysToKeep
変数と@batchSize
変数の値を変更することで、クリーンアップの間隔や削除するエントリの数をカスタマイズできます。
3.9. Elasticsearch
Orchestrator は、毎月各テナントについて 1 つのインデックスを保存します。Elasticsearch で古いインデックスを保存すると、検索やレポートで使用されていなくても、パフォーマンスに影響 (メモリ破損) を与える 場合があります。このため、古いインデックスは削除することを推奨します。
3.10 セッション
Sessions
テーブル内で放置されたまま [ReportingTime]
が 60 日を経過したセッションは、削除することをお勧めします。以下のクエリの例では、60 日を経過した古い項目が削除されます。@daysToKeep
パラメーターを変更したり、TenantId
に where
句を追加したりして、クエリを必要に応じて調整します。
SQL サーバーのジョブで手動で実行するか、スケジュールで実行することができます。
DECLARE @daysToKeep INT = 60
BEGIN TRANSACTION
SELECT s.[Id]
INTO #tempTable
FROM [dbo].[Sessions] s
LEFT JOIN [dbo].[RobotLicenses] rl ON rl.[SessionId] = s.[Id] AND rl.[Scope] > 1
LEFT JOIN [dbo].[ProcessScheduleMachineRobots] p ON p.[SessionId] = s.[Id]
WHERE s.[ReportingTime] < GETUTCDATE()-@daysToKeep
AND s.[RobotId] IS NULL
AND rl.[Id] IS NULL
AND p.[Id] IS NULL
-- AND s.[TenantId] = 1 -- default tenant
ORDER BY s.[Id] asc
DELETE rl
FROM [dbo].[RobotLicenses] rl
INNER JOIN #tempTable t ON t.[Id] = rl.[SessionId]
DELETE s
FROM [dbo].[Sessions] s
INNER JOIN #tempTable t ON t.[Id] = s.[Id]
DROP TABLE #tempTable
COMMIT TRANSACTION
7 か月前に更新