111 lines
2.9 KiB
Transact-SQL
111 lines
2.9 KiB
Transact-SQL
|
|
USE [HCITools]
|
|
GO
|
|
|
|
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Purge_Monitoring_History]') AND type in (N'P', N'PC'))
|
|
DROP PROCEDURE [dbo].[Purge_Monitoring_History]
|
|
GO
|
|
|
|
USE [HCITools]
|
|
GO
|
|
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
|
|
|
|
CREATE PROCEDURE [dbo].[Purge_Monitoring_History]
|
|
@in_debug int = null
|
|
AS
|
|
/*=============================================================================
|
|
|
|
Explication du traitement realise par la SP
|
|
-------------------------------------------
|
|
Cette SP sert à purger l'historique des enregistrements de monitoring
|
|
|
|
Contexte d'utilisation
|
|
----------------------
|
|
Cette SP est appelée par le job W93040 - Clean-up monitoring history
|
|
|
|
Parametres
|
|
----------
|
|
@in_debug :
|
|
|
|
Creation : 05.11.21 / RTC 66785 Standardize and extend job W93040 - Clean-up monitoring history
|
|
|
|
=============================================================================*/
|
|
|
|
SET NOCOUNT ON;
|
|
|
|
/*-------------------------- Traitement ---------------------------*/
|
|
BEGIN TRY
|
|
|
|
/* Purge tables related to performance monitoring : retention 6 months */
|
|
IF EXISTS (SELECT *
|
|
FROM [HCITools].sys.objects o WITH (NOLOCK)
|
|
WHERE o.name = 'Monitoring_history'
|
|
AND o.type IN (N'U'))
|
|
BEGIN
|
|
DELETE
|
|
FROM HCITools.dbo.Monitoring_history
|
|
WHERE MH_datetime < DATEADD(MM,-6,getdate())
|
|
END
|
|
|
|
IF EXISTS (SELECT *
|
|
FROM [HCITools].sys.objects o WITH (NOLOCK)
|
|
WHERE o.name = 'Monitor_wait_stats'
|
|
AND o.type IN (N'U'))
|
|
BEGIN
|
|
DELETE
|
|
FROM HCITools.dbo.Monitor_wait_stats
|
|
WHERE MWS_value_date < DATEADD(MM,-6,getdate())
|
|
END
|
|
|
|
IF EXISTS (SELECT *
|
|
FROM [HCITools].sys.objects o WITH (NOLOCK)
|
|
WHERE o.name = 'Monitor_disk_latency'
|
|
AND o.type IN (N'U'))
|
|
BEGIN
|
|
DELETE
|
|
FROM HCITools.dbo.Monitor_disk_latency
|
|
WHERE collection_date < DATEADD(MM,-6,getdate())
|
|
END
|
|
|
|
/* Purge tables related to blocking session : retention 1 month */
|
|
IF EXISTS (SELECT *
|
|
FROM [HCITools].sys.objects o WITH (NOLOCK)
|
|
WHERE o.name = 'BlockingSessionInfo'
|
|
AND o.type IN (N'U'))
|
|
BEGIN
|
|
DELETE
|
|
FROM HCITools.dbo.BlockingSessionInfo
|
|
WHERE AlertTime < DATEADD(MM,-1,getdate())
|
|
END
|
|
|
|
/*Purge tables related to monitoring alerts : retention 1 month*/
|
|
IF EXISTS (SELECT 1
|
|
FROM sys.objects o WITH (NOLOCK)
|
|
JOIN sys.schemas s WITH (NOLOCK) ON o.schema_id = s.schema_id
|
|
WHERE o.name = 'DBA_monitoring_alerts_history'
|
|
AND o.type IN (N'U')
|
|
AND s.name = 'mon')
|
|
BEGIN
|
|
DELETE
|
|
FROM HCITools.mon.DBA_monitoring_alerts_history
|
|
WHERE DBAMAH_event_date < DATEADD(MM,-1,getdate())
|
|
END
|
|
|
|
/*---------------------- Traitement des erreurs ----------------------*/
|
|
END TRY
|
|
BEGIN CATCH
|
|
|
|
/* Traitement des erreurs (avec RaiseError) */
|
|
EXEC dbo.get_Error_Info @in_RaiseError = 1
|
|
|
|
END CATCH
|
|
|
|
GO
|
|
|