146 lines
5.1 KiB
Transact-SQL
146 lines
5.1 KiB
Transact-SQL
USE [HCITools]
|
|
GO
|
|
|
|
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[mon_Transfert_Stats_Index]') AND type in (N'P', N'PC'))
|
|
DROP PROCEDURE [dbo].[mon_Transfert_Stats_Index]
|
|
GO
|
|
|
|
USE [HCITools]
|
|
GO
|
|
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
|
|
|
|
|
|
CREATE PROCEDURE [dbo].[mon_Transfert_Stats_Index]
|
|
@in_debug tinyint = 0
|
|
AS
|
|
/*=============================================================================
|
|
|
|
Explication du traitement realise par la SP
|
|
-------------------------------------------
|
|
La SP va transferer l'ensemble des statistiques des index contenues dans la table HCITools.dbo.Stats_index vers la table HCITools.dbo.All_Stats_Index de la centrale
|
|
|
|
Contexte d'utilisation
|
|
----------------------
|
|
Appelé depuis le job D92070 - Transfert Stats Index
|
|
|
|
Parametres
|
|
----------
|
|
@in_debug : non utilisé
|
|
|
|
Creation : 27.10.16 / FLA
|
|
|
|
Modifications : 28.10.2016 / FLA : Standardisation de la gestion des erreurs
|
|
04.10.2017 / FLA : Ajout de la gestion des environnements
|
|
24.09.2018 / FLA : Remove references to undocumented system tables
|
|
20.12.2018 / SPE : #TFS49408# Migrate identification table [master].[cfg].[Identity]
|
|
04.08.2023 / TSC : Added a WHERE NOT EXISTS to avoid duplicate key errors during upload
|
|
|
|
=============================================================================*/
|
|
|
|
set nocount on;
|
|
|
|
|
|
/*------------------- Declaration des variables --------------------*/
|
|
|
|
declare @cvCurrentOrganizationalUnit int,
|
|
@CV_OUT_value varchar(8000),
|
|
@ou_code varchar(10),
|
|
@ServerName varchar(20),
|
|
@restartdate datetime,
|
|
@errno int,
|
|
@errmsg varchar(255),
|
|
@LnkSrv varchar(15),
|
|
@cmd varchar(8000),
|
|
@Entity varchar(4)
|
|
|
|
/*------------ Affectation des parametres aux variables ------------*/
|
|
|
|
select @cvCurrentOrganizationalUnit = null ;
|
|
|
|
/*-------------------------- Traitement ---------------------------*/
|
|
|
|
|
|
IF EXISTS (SELECT type FROM master.cfg.InstanceContext WHERE type = 'PROD')
|
|
BEGIN
|
|
|
|
BEGIN TRY
|
|
|
|
exec arizona.dbo.sp_bmc_Bmc_Applic_Default
|
|
@in_job_type = 3,
|
|
@in_param_int_1 = null,
|
|
@in_param_int_2 = null,
|
|
@in_param_varchar_1 = 'cvCurrentOrganizationalUnit',
|
|
@out_default_value = @CV_out_value output,
|
|
@out_param_int_1 = null;
|
|
select @cvCurrentOrganizationalUnit = convert(int,@CV_out_value)
|
|
|
|
select @ou_code = ou.ou_code
|
|
from arizona.dbo.Organizational_unit ou (nolock)
|
|
where ou.Organizational_unit_ID = @cvCurrentOrganizationalUnit
|
|
|
|
SELECT @Entity = [Customer] FROM [master].[cfg].[Identity]
|
|
|
|
IF @Entity = 'RUEG'
|
|
BEGIN
|
|
SET @Entity = 'AAI'
|
|
END
|
|
|
|
SET @ServerName = @Entity+isnull(@ou_code,'')+'APS'
|
|
|
|
select @RestartDate = MIN(login_time)
|
|
from sys.dm_exec_sessions
|
|
|
|
IF @Entity = 'AAI'
|
|
SET @LnkSrv = 'CENTRALEDATA'
|
|
ELSE
|
|
SET @LnkSrv = 'ARIZONACASH'
|
|
|
|
SET @cmd = 'INSERT INTO '+@LnkSrv+'.HCITools.dbo.All_Stats_Index
|
|
SELECT TOP 50000 '''+@ServerName+''',[Stats_index_ID]
|
|
,[SI_schemaname]
|
|
,[SI_databasename]
|
|
,[SI_tablename]
|
|
,[SI_indexname]
|
|
,[SI_indextype]
|
|
,[SI_user_seeks]
|
|
,[SI_user_scans]
|
|
,[SI_user_lookups]
|
|
,[SI_user_updates]
|
|
,[SI_last_user_seek]
|
|
,[SI_last_user_scan]
|
|
,[SI_last_user_lookup]
|
|
,[SI_last_user_update]
|
|
,[SI_updatedate]
|
|
,[SI_restartdate]
|
|
,NULL
|
|
FROM [HCITools].[dbo].[Stats_index] si WITH (NOLOCK)
|
|
WHERE SI_updatedate < CAST('''+CONVERT(nvarchar(30),@RestartDate,126)+''' as datetime)
|
|
AND NOT EXISTS(
|
|
SELECT 1
|
|
FROM '+@LnkSrv+'.HCITools.dbo.All_Stats_Index t
|
|
WHERE t.[SI_ServerName] = '''+@ServerName+'''
|
|
AND t.[Stats_index_ID] = si.[Stats_index_ID]
|
|
)
|
|
'
|
|
|
|
EXEC (@cmd)
|
|
|
|
/*---------------------- Traitement des erreurs ----------------------*/
|
|
END TRY
|
|
BEGIN CATCH
|
|
|
|
/* Traitement des erreurs (avec RaiseError) */
|
|
EXEC dbo.get_Error_Info @in_RaiseError = 1
|
|
|
|
END CATCH
|
|
|
|
END
|
|
|
|
GO
|