sqlserver的日常检查脚本归结
2012-02-15 12:23:49 来源:WEB开发网select @backupsize = backup_size from msdb..backupset where backup_start_date = ( select max(backup_start_date) from msdb..backupset where database_name = @dbname and type='d')
select @filepath = physical_device_name from msdb..backupmediafamily where media_set_id = @media_set_id
exec master..xp_fileexist @filepath , @filestatus out
if @filestatus = 1
set @fileavailable = 'available'
else
set @fileavailable = 'not available'
if (datediff(day,@db_bkpdate,getdate()) > 7)
set @status = 'warning'
else
set @status = 'healthy'
set @backupsize = (@backupsize/1024)/1024
insert into #backup_details select @svr_name,@dbname,@db_bkpdate,@backupsize,@status,@filepath,@fileavailable
update #backup_details
set status = 'warning' where bkpdate is null
set @counter = @counter - 1
end
select substring(servername,0,20) AS [服务器名],
substring(databasename,0,20) AS [数据库名],
rtrim(ltrim(bkpdate)) AS [备份日期],
rtrim(ltrim(backupsize_in_mb)) AS [备份大小],
rtrim(ltrim([status])) AS [备份状态],
substring(rtrim(ltrim(filepath)),0,40) AS [备份文件路径],
rtrim(fileavailable) AS [备份文件是否可用]
from #backup_details where databasename not in ('tempdb','northwind','pubs')
drop table #backup_details
set nocount off
go
print '*********************************'
print ' '
print ' '
print ' '
print '-------------------------------------'
print '16.监控CPU瓶颈'
print '-------------------------------------'
print '*********************************'
use master
go
print '-------------------------------------'
print '16.1当前缓存的哪些批处理或过程占用了大部分 CPU 资源'
print '-------------------------------------'
SELECT TOP 50
ltrim(SUM(qs.total_worker_time)) AS total_cpu_time,
ltrim(SUM(qs.execution_count)) AS total_execution_count,
ltrim(COUNT(*)) AS number_of_statements,
qs.sql_handle
FROM sys.dm_exec_query_stats AS qs
GROUP BY qs.sql_handle
ORDER BY SUM(qs.total_worker_time) DESC
go
print ' '
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››Sql server 2005拒绝了对对象 'xx表' (数...
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接