[MSSQL]磁盘空间&SQL日志&作业执行情况
来源:互联网 发布:翻样算尺软件 编辑:程序博客网 时间:2024/06/05 10:53
---查看每个磁盘剩余空间大小(M)Exec master.dbo.xp_fixeddrives --或者declare @Fixed_tb table(Drive_NO char(1),Remainder_M bigint)INSERT INTO @Fixed_tb exec master.dbo.xp_fixeddrivesselect Drive_NO '驱动盘符',Remainder_M'剩余M',cast(((Remainder_M/1024)+0.001*(Remainder_M%1024))as dec(18,2))'剩余G' from @Fixed_tbGO-----SQL SERVER 日志 declare @tmp table (LogDate datetime,ProcessInfo varchar(32),Text nvarchar(max))insert into @tmpEXEC master.dbo.xp_readerrorlog 0, 1, NULL, NULL, NULL, NULL, N'desc'---读取SQL Server 日志select * from @tmp where 1=1/* 一共有7个参数: 1. 存档编号2. 日志类型(1为SQL Server日志,2为SQL Agent日志)3. 查询包含的字符串4. 查询包含的字符串5. LogDate开始时间6. 结果排序,按LogDate排序(可以为降序"Desc" Or 升序"Asc")7. 结果排序,按LogDate排序(可以为降序"Desc" Or 升序"Asc") 在输入第5和第6个参数的时候,使用时间里包含有秒、毫秒时候,有时候查询速度非常慢,而且导致CPU占用率为100%。*/--作业活动监视器 (不显示成功的JOB)详细内容 SELECT c.job_id,a.name,case when a.enabled =1 then '是' else '否' end '是否启用',a.date_created '创建时间',a.date_modified '修改时间',d.run_date as '最近运行日期', case when substring(b.last_outcome_message,1,CHARINDEX('。', b.last_outcome_message)) is NULL then '未知' else substring(b.last_outcome_message,1,CHARINDEX('。', b.last_outcome_message)) end '上次运行结果', d.message,left(b.last_run_date,4)+'/'+SUBSTRING(convert(varchar(8),b.last_run_date),5,2)+'/'+right(b.last_run_date,2)+' '+ case when b.last_run_time=0 then '0:00:00' when LEN(b.last_run_time)=3 then '0:0'+SUBSTRING(convert(varchar(6),b.last_run_time),1,1)+':'+RIGHT(b.last_run_time,2) when LEN(b.last_run_time)=4 then '0:'+LEFT(b.last_run_time,2)+':'+RIGHT(b.last_run_time,2) when len(b.last_run_time)=5 then left(b.last_run_time,1)+':'+SUBSTRING(convert(varchar(6),b.last_run_time),2,2)+':'+right(b.last_run_time,2) else left(b.last_run_time,2)+':'+SUBSTRING(convert(varchar(6),b.last_run_time),3,2)+':'+right(b.last_run_time,2)end'上次运行时间',left(c.next_run_date,4)+'/'+SUBSTRING(convert(varchar(8),c.next_run_date),5,2)+'/'+right(c.next_run_date,2)+' '+ case when c.next_run_time=0 then '0:00:00' when LEN(c.next_run_time)=3 then '0:0'+SUBSTRING(convert(varchar(6),c.next_run_time),1,1)+':'+RIGHT(c.next_run_time,2) when LEN(c.next_run_time)=4 then '0:'+LEFT(c.next_run_time,2)+':'+RIGHT(c.next_run_time,2) when len(c.next_run_time)=5 then left(c.next_run_time,1)+':'+SUBSTRING(convert(varchar(6),c.next_run_time),2,2)+':'+right(c.next_run_time,2) else left(c.next_run_time,2)+':'+SUBSTRING(convert(varchar(6),c.next_run_time),3,2)+':'+right(c.next_run_time,2)end '下次运行时间'FROM[msdb].[dbo].[sysjobs_view] a join [msdb].[dbo].[sysjobservers] bon a.job_id =b.job_id join [msdb].[dbo].[sysjobschedules] con a.job_id =c.job_id join (select job_id,max(run_date) run_date,message from [msdb].[dbo].[sysjobhistory] where run_status<>1 and sql_message_id>0 group by job_id,message) don b.job_id =d.job_id and b.last_run_date=d.run_date where a.enabled=1 and (a.category_id =0 or a.category_id =3) ----每个作业详细运行步骤及结果select a.name ,a.description,a.date_created,a.date_modified, b.message, left(b.run_date,4)+'/'+SUBSTRING(convert(varchar(8),b.run_date),5,2)+'/'+right(b.run_date,2)+' '+ case when b.run_time=0 then '0:00:00' when LEN(b.run_time)=3 then '0:0'+SUBSTRING(convert(varchar(6),b.run_time),1,1)+':'+RIGHT(b.run_time,2) when LEN(b.run_time)=4 then '0:'+LEFT(b.run_time,2)+':'+RIGHT(b.run_time,2) when len(b.run_time)=5 then left(b.run_time,1)+':'+SUBSTRING(convert(varchar(6),b.run_time),2,2)+':'+right(b.run_time,2) else left(b.run_time,2)+':'+SUBSTRING(convert(varchar(6),b.run_time),3,2)+':'+right(b.run_time,2)end'运行时间', case when b.run_status=1 then '成功' else '失败' end '状态' FROM [msdb].[dbo].[sysjobs_view] a ,[msdb].[dbo].[sysjobhistory] b where a.job_id =b.job_id and (a.category_id =0 or a.category_id =3)
0 0
- [MSSQL]磁盘空间&SQL日志&作业执行情况
- SQL查询作业执行情况
- mssql查看语句执行情况
- SQL SERVER 查询Job作业基本信息及执行情况
- [MSSQL]删除sql server日志
- SQL SERVER 查询作业(Job)基本信息及执行情况的sql
- 查询sql执行情况
- JCONSOLE 监控SQL执行情况
- Sql Server 监控 Job 执行情况
- Sql Server 监控 Job 执行情况
- SqlServer中监视sql执行情况
- oracle查看sql进程执行情况
- Trafodion 查看历史SQL执行情况
- 删除SQL SERVER数据库日志方法-Mssql数据库
- mssql 监控磁盘空间告警实现方法
- msSQL 引起磁盘空间不足的解决方法
- MSSQL errorlog 引起磁盘空间不足的解决方法
- SQL: 跟踪SQL语句的执行情况
- Python中序列的切片和加号
- 第8周项目1——建立顺序串的算法库
- HDOJ 2243 考研路茫茫——单词情结(AC自动机+矩阵快速幂)
- 九度OJ 1094:String Matching(字符串匹配) (计数)
- 2015-10-23 【项目5 - 计数的模式匹配】
- [MSSQL]磁盘空间&SQL日志&作业执行情况
- 第八周上机实践—项目2—建立链串的算法库
- WEB缓存原理
- Objective - C 字符串 数组 字典 集合的基本使用
- 第7周实践项目4 - 队列数组
- 【Android应用开发】Android Studio 错误集锦 -- 将所有的 AS 错误集合到本文
- 高精度除法与求余C++版和java版
- 寄存器知识
- 九度OJ 1095:2的幂次方 (递归)