SQL Server 数据库巡检脚本.docx
上传人:qw****27 上传时间:2024-09-12 格式:DOCX 页数:5 大小:22KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

SQL Server 数据库巡检脚本.docx

SQLServer数据库巡检脚本.docx

预览

在线预览结束,喜欢就下载吧,查找使用更方便

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

--1.查看数据库版本信息select@@version--2.查看所有数据库名称及大小execsp_helpdb--3.查看数据库所在机器的操作系统参数execmaster..xp_msver--4.查看数据库启动的参数execsp_configure--5.查看数据库启动时间selectconvert(varchar(30),login_time,120)frommaster..sysprocesseswherespid=1--6.查看数据库服务器名select'ServerName:'+ltrim(@@servername)--7.查看数据库实例名select'Instance:'+ltrim(@@servicename)--8.数据库的磁盘空间呢使用信息execsp_spaceused--9.日志文件大小及使用情况dbccsqlperf(logspace)--10.表的磁盘空间使用信息execsp_spaceused'tablename'--11.获取磁盘读写情况select@@total_read[读取磁盘次数],@@total_write[写入磁盘次数],@@total_errors[磁盘写入错误数],getdate()[当前时间]--12.获取I/O工作情况select@@io_busy,@@timeticks[每个时钟周期对应的微秒数],@@io_busy*@@timeticks[I/O操作毫秒数],getdate()[当前时间]--13.查看CPU活动及工作情况select@@cpu_busy,@@timeticks[每个时钟周期对应的微秒数],@@cpu_busy*cast(@@timeticksasfloat)/1000[CPU工作时间(秒)],@@idle*cast(@@timeticksasfloat)/1000[CPU空闲时间(秒)],getdate()[当前时间]--14.检查锁与等待execsp_lock--15.检查死锁execsp_who_lock--自己写个存储过程即可/*createproceduresp_who_lockasbegindeclare@spidint,@blint,@intTransactionCountOnEntryint,@intRowcountint,@intCountPropertiesint,@intCounterintcreatetable#tmp_lock_who(idintidentity(1,1),spidsmallint,blsmallint)IF@@ERROR<>0RETURN@@ERRORinsertinto#tmp_lock_who(spid,bl)select0,blockedfrom(select*fromsys.sysprocesseswhereblocked>0)awherenotexists(select*from(select*fromsys.sysprocesseswhereblocked>0)bwherea.blocked=spid)unionselectspid,blockedfromsys.sysprocesseswhereblocked>0IF@@ERROR<>0RETURN@@ERROR--找到临时表的记录数select@intCountProperties=Count(*),@intCounter=1from#tmp_lock_whoIF@@ERROR<>0RETURN@@ERRORif@intCountProperties=0select'现在没有阻塞和死锁信息'asmessage--循环开始while@intCounter<=@intCountPropertiesbegin--取第一条记录select@spid=spid,@bl=blfrom#tmp_lock_whowhereid=@intCounterbeginif@spid=0select'引起数据库死锁的是:'+CAST(@blASVARCHAR(10))+'进程号,其执行的SQL语法如下'elseselect'进程号SPID:'+CAST(@spidASVARCHAR(10))+'被'+'进程号SPID:'+CAST(@blASVARCHAR(10))+'阻塞,其当前进程执行的SQL语法如下'DBCCINPUTBUFFER(@bl)end--循环指针下移set@intCounter=@intCounter+1enddroptable#tmp_lock_whoreturn0end*/--1