Tuesday, September 13, 2016

SQL info Script - get details about what sql database is doing.

I recently wanted to see if SQL was not over eating the resources. Apart from checking the disks, the task manager and resource monitor, the following script helped me. Just copying and pasting it to the sql server management studio and running it shows
"SQLServer:Buffer Manager-Page life expectancy" whose value should not be too low.

-- SQL INFO TEMPDB CONFIG AND SQL INFO SNAPSHOT 

USE Master
GO

SELECT getdate() as myCurrentDateTime, 
@@SERVERNAME as myServerName, 
os.Cores, df.Files 
FROM 
(SELECT COUNT(*) AS Cores FROM sys.dm_os_schedulers WHERE status = 'VISIBLE ONLINE') AS os, 
(SELECT COUNT(*) AS Files FROM tempdb.sys.database_files WHERE type_desc = 'ROWS') AS df; 
GO 

SELECT 
   name AS FileName, 
   size*1.0/128 AS FileSizeinMB, 
   type_desc, 
   CASE max_size 
       WHEN 0 THEN 'Autogrowth is off.' 
       WHEN -1 THEN 'Autogrowth is on.' 
       ELSE 'File will grow to a maximum size of 2 TB.' 
   END, 
   growth AS 'GrowthValue', 
   'GrowthIncrement' = 
       CASE 
           WHEN growth = 0 THEN 'Size is fixed and will not grow.' 
           WHEN growth > 0 AND is_percent_growth = 0 
               THEN 'Growth value is in 8-KB pages.' 
           ELSE 'Growth value is a percentage.' 
       END 
FROM tempdb.sys.database_files ORDER BY FileName ASC; 
GO 

begin 
     select getdate() as myDateTime, 
     @@SERVERNAME as myServer, 
     SERVERPROPERTY('ProductVersion') as myVersion, 
     SERVERPROPERTY('Edition') as myEdition 
     exec sp_readerrorlog 0, 1, 'using locked pages for buffer' 
     exec sp_readerrorlog 0, 1, 'significant part of sql server process memory' 
     exec sp_readerrorlog 0, 1, 'taking longer than 15 seconds to complete' 
     dbcc tracestatus 
     exec sp_configure 'show advanced options', 1 
     reconfigure 
     exec sp_configure 'max server memory (MB)' 
     exec sp_configure 'max degree of parallelism' 
     select object_name,counter_name,cntr_value 
     from   master..sysperfinfo 
     where  counter_name IN ('Total Server Memory (KB)','Target Server Memory (KB)', 'Page life expectancy', 'User Connections') 
     AND instance_name = '' 
end 

No comments:

Post a Comment