--查看當前數據庫的性能數據
/* Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64) Apr 2 2010 15:48:46 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) */
SELECT @@SERVERNAME
go
SELECT @@VERSION
go
--select process
SELECT spid, kpid, blocked
, CAST(waittime AS BIGINT) as waittime, lastwaittype, waitresource, dbid, uid
, CAST(cpu / 1000 AS BIGINT) as cpu
, CAST(physical_io AS BIGINT) as physical_io, memusage, login_time , last_batch , ecid
, CAST(open_tran AS BIGINT) as open_tran, status, hostname, program_name
, hostprocess, cmd, nt_domain, nt_username, net_address, net_library, loginame, stmt_start, stmt_end
FROM master.dbo.sysprocesses
where hostprocess <> '' and
go
--for idera!
--select performance data declare @LgReads bigint select @LgReads=cntr_value from master.dbo.sysperfinfo where counter_name='Page lookups/sec' if object_id(N'tempdb.dbo.#waits') is not null GOTO InsertTb if object_id(N'tempdb.dbo.#waits') is null GOTO CreateTb CreateTb: create table #waits (type varchar(128), req bigint, waittime bigint, signal bigint) GOTO InsertTb InsertTb: insert into #waits exec('dbcc sqlperf(waitstats)') --insert into WaitsLog (DT,CPU,Locks,Reads,Writes,Network,PhReads,PhWrites,LgReads) select getdate() AS DT, CAST(@@CPU_BUSY * CAST(@@TIMETICKS AS FLOAT) / 1000 AS BIGINT) as CPU, -- in milliseconds sum(convert(bigint, case when type like 'LCK%' then waittime else 0 end)) as Locks, sum(convert(bigint, case when type like 'LATCH%' or type like 'PAGELATCH%' or type like 'PAGEIOLATCH%' then waittime else 0 end)) as Reads, sum(convert(bigint, case when type like '%IO_COMPLETION%' or type='WRITELOG' then waittime else 0 end)) as Writes, sum(convert(bigint, case when type in ('NETWORKIO','OLEDB') then waittime else 0 end)) as Network, @@TOTAL_READ AS PhReads, @@TOTAL_WRITE AS PhWrites, ISNULL(@LgReads, 0) AS LgReads from #waits
--EOF