在Sqlserver使用过程中msdb数据库越来越大 这个就要定期删除长时间不用的日志。
---1.查看作业历史记录
SELECT TOP 1000 [instance_id] ,[job_id] ,[step_id] ,[step_name] ,[sql_message_id] ,[sql_severity] ,[message] ,[run_status] ,[run_date] ,[run_time] ,[run_duration] ,[operator_id_emailed] ,[operator_id_netsent] ,[operator_id_paged] ,[retries_attempted] ,[server] FROM [msdb].[dbo].[sysjobhistory] --删除操作记录 delete from [msdb].[dbo].[sysjobhistory]
---2.查看维护计划日志
--查询指定日期前的日志 SELECT [task_detail_id] ,[plan_id] ,[subplan_id] ,[start_time] ,[end_time] ,[succeeded] ,[logged_remotely] ,[source_server_name] ,[plan_name] ,[subplan_name] FROM [msdb].[dbo].[sysmaintplan_log] where start_time<'2021-01-01' -- 删除指定日期前的日志 delete from [msdb].[dbo].[sysmaintplan_log] where start_time<'2021-01-01'
---3.查看维护计划日志详情
--查询指定日期前的日志明细 SELECT [task_detail_id] ,[line1] ,[line2] ,[line3] ,[line4] ,[line5] ,[server_name] ,[start_time] ,[end_time] ,[error_number] ,[error_message] ,[command] ,[succeeded] FROM [msdb].[dbo].[sysmaintplan_logdetail] where start_time<'2021-01-01' --删除指定日期前的日志明细 delete from [msdb].[dbo].[sysmaintplan_logdetail] where start_time<'2021-01-01'