J'ai besoin de créer une application ou un service qui notifie quand le fichier journal augmente au-dessus d'une certaine taille. Soit un email ou autre chose.Alerte lorsque le fichier journal sql devient trop grand?
1
A
Répondre
1
Voici l'ensemble de la tâche d'agent scriptée avec la logique ci-dessus. Voir 3 variables à définir en haut. (Le nom de l'opérateur peut être null si vous souhaitez uniquement générer une erreur de journal de l'application Windows)
USE [msdb]
GO
Declare @AdminUserName varchar(255)
Declare @Operator varchar(255)
Declare @EmailNotify bit
Set @AdminUserName = N'YOUR SYSADMIN USER'
set @Operator = N'YOUR OPERATOR NAME'
Set @EmailNotify = 1
/****** Object: Job [Transaction Logfile Size Monitoring] Script Date: 08/02/2012 15:39:11 ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object: JobCategory [[Uncategorized (Local)]]] Script Date: 08/02/2012 15:39:11 ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
END
Declare @NotifyLevel int
If @EmailNotify = 1 Begin
set @NotifyLevel =2 end
else begin
set @NotifyLevel=0
set @Operator=null
end
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Transaction Logfile Size Monitoring',
@enabled=1,
@notify_level_eventlog=0,
@[email protected],
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'No description available.',
@category_name=N'[Uncategorized (Local)]',
@[email protected],
@[email protected], @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [Monitor Logfile Size] Script Date: 08/02/2012 15:39:11 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @[email protected], @step_name=N'Monitor Logfile Size',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'Declare @LogSize int;
Declare @LogName varchar(255);
Declare @LogFile varchar(2000);
select Top 1 @LogName=name,@LogFile=physical_name,@LogSize = convert(float,size) * 8192/(1024 * 1024) from sys.master_files
where type_desc = ''LOG'' Order by size desc
IF (@LogSize > 10240)
BEGIN
Declare @AlertString varchar(5000)
set @AlertString = @LogName + '' : '' + @LogFile + '' has reached a size of '' + Convert(varchar(20),@LogSize) + '' MB.''
RAISERROR(@AlertString, 18,1) with LOG
END
ELSE
BEGIN
RAISERROR(''Transaction Log monitoring complete'', 0, 1)
END',
@database_name=N'master',
@flags=4
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @jo[email protected], @name=N'Hourly Logfile Check',
@enabled=1,
@freq_type=4,
@freq_interval=1,
@freq_subday_type=8,
@freq_subday_interval=1,
@freq_relative_interval=0,
@freq_recurrence_factor=0,
@active_start_date=20120802,
@active_end_date=99991231,
@active_start_time=0,
@active_end_time=235959,
@schedule_uid=N'18435d90-4ca0-4c7a-a8a9-c81f347ba32c'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO
3
La vue sys.master_files contient la taille du fichier journal (s):
select size * 8192/(1024 * 1024) as [Size in MB]
from sys.master_files
where type_desc = 'LOG'
and database_id = db_id('NameOfYourDatabase')
Il énumère la taille en blocs 8KB.
Vous pouvez vérifier la taille d'une tâche planifiée Agent SQL et, si elle dépasse une certaine taille, envoyez un e-mail avec sp_send_dbmail.
Questions connexes
- 1. le fichier journal de SQL grandit trop grand
- 2. Mon fichier journal log4j est trop grand
- 3. App se bloque lorsque QList devient trop grand
- 4. SQL Server 2005 du journal des transactions trop grand
- 5. Fichier de trace TextWriterTraceListener trop grand
- 6. Hibernate session dans la conversation Seam devient trop grand
- 7. La requête Sql devient trop lente
- 8. Mon fichier journal est trop volumineux
- 9. Laravel routes.php devient grand
- 10. Le module Python devient trop gros
- 11. que faire lorsque votre feuille de sprite devient trop grande?
- 12. Divs pas flotter lorsque le contenu est trop grand
- 13. Divs Maj Lorsque le contenu est trop grand
- 14. CakePHP 2.4.5 access.log devient infiniment plus grand?
- 15. tête jqGrid devient grand lorsque vous utilisez flotteur
- 16. Div devient trop large lorsque 1 colonne est supprimée
- 17. Erreur de session PHP: "Fichier trop grand"
- 18. Le fichier binaire brut généré par objcopy est trop grand
- 19. keyhash android trop grand
- 20. WCF mex trop grand
- 21. Ruby on rails taille du fichier journal trop grande
- 22. Quand web.config est-il trop grand?
- 23. de popupWindow - trop grand
- 24. JMenuItem ImageIcon trop grand
- 25. problème trop grand
- 26. QTextEdit est trop grand?
- 27. UIPopoverController trop grand et UIPickerView trop petit
- 28. RPC: xdr_bytes "Impossible d'encoder les arguments" lorsque le tableau est trop grand
- 29. Mon MainViewController devient grand. Comment puis-je le diviser?
- 30. problème de fichier journal SQL Server
Vous pouvez demander à serverfault si c'est quelque chose que SQL Server peut être dit de faire par lui-même. Cependant, vous devrez spécifier la version de SQL Server que vous utilisez. –
mssql 2008 (désolé à ce sujet) –
Je ne vois pas comment c'est hors sujet. –