SQL_Server_数据库巡检脚本.docx_第1页
SQL_Server_数据库巡检脚本.docx_第2页
SQL_Server_数据库巡检脚本.docx_第3页
SQL_Server_数据库巡检脚本.docx_第4页
SQL_Server_数据库巡检脚本.docx_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

-1.查看数据库版本信息select version-2.查看所有数据库名称及大小exec sp_helpdb-3.查看数据库所在机器的操作系统参数exec master.xp_msver-4.查看数据库启动的参数exec sp_configure-5.查看数据库启动时间select convert(varchar(30),login_time,120)from master.sysprocesses where spid=1-6.查看数据库服务器名select Server Name:+ltrim(servername)-7.查看数据库实例名select Instance:+ltrim(servicename)-8.数据库的磁盘空间呢使用信息exec sp_spaceused-9.日志文件大小及使用情况dbcc sqlperf(logspace)-10.表的磁盘空间使用信息exec sp_spaceused tablename-11.获取磁盘读写情况selecttotal_read 读取磁盘次数,total_write 写入磁盘次数,total_errors 磁盘写入错误数,getdate() 当前时间-12.获取I/O工作情况select io_busy,timeticks 每个时钟周期对应的微秒数,io_busy*timeticks I/O操作毫秒数,getdate() 当前时间-13.查看CPU活动及工作情况selectcpu_busy,timeticks 每个时钟周期对应的微秒数,cpu_busy*cast(timeticks as float)/1000 CPU工作时间(秒),idle*cast(timeticks as float)/1000 CPU空闲时间(秒),getdate() 当前时间-14.检查锁与等待exec sp_lock-15.检查死锁exec sp_who_lock -自己写个存储过程即可/*create procedure sp_who_lockasbegin declare spid int,bl int, intTransactionCountOnEntry int, intRowcount int, intCountProperties int, intCounter int create table #tmp_lock_who (id int identity(1,1),spid smallint,bl smallint) IF ERROR0 RETURN ERROR insert into #tmp_lock_who(spid,bl) select 0 ,blocked from (select * from sys.sysprocesses where blocked0 ) a where not exists(select * from (select * from sys.sysprocesses where blocked0 ) b where a.blocked=spid) union select spid,blocked from sys.sysprocesses where blocked0 IF ERROR0 RETURN ERROR - 找到临时表的记录数 select intCountProperties = Count(*),intCounter = 1 from #tmp_lock_who IF ERROR0 RETURN ERROR if intCountProperties=0 select 现在没有阻塞和死锁信息 as message - 循环开始 while intCounter 50 AND SessionID IS NULL OR er.session_id = SessionID ORDER BY er.blocking_session_id DESC , er.session_id END*/-19.查看所有数据库用户登录信息exec sp_helplogins-20.查看所有数据库用户所属的角色信息exec sp_helpsrvrolemember-21.查看链接服务器exec sp_helplinkedsrvlogin-22.查看远端数据库用户登录信息exec sp_helpremotelogin-23.获取网络数据包统计信息selectpack_received 输入数据包数量,pack_sent 输出数据包数量,packet_errors 错误包数量,getdate() 当前时间-24.检查数据库中的所有对象的分配和机构完整性是否存在错误dbcc checkdb-25.查询文件组和文件select ,df.physical_name,df.size,df.growth, filegroup,f.is_defaultfrom sys.database_files df join sys.filegroups fon df.data_space_id = f.data_space_id-26.查看数据库中所有表的条数select as tablename , a.rowcnt as datacountfrom sysindexes a , sysobjects bwhere a.id = b.id and a.indid 2 and objectproperty(b.id, IsMSShipped) = 0-27.得到最耗时的前10条T-SQL语句;with maco as( select top 10 plan_handle, sum(total_worker_time) as total_worker_time , sum(execution_count) as execution_count , count(1) as sql_count from sys.dm_exec_query_stats group by plan_handle order by sum(total_worker_time) desc)select t.text , a.total_worker_time , a.execution_count , a.sql_countfrom maco a cross apply sys.dm_exec_sql_text(plan_handle) t-28. 查看SQL Server的实际内

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论