Skip to content

Commit ee668b6

Browse files
committed
Modified Scripts for Blog Posts
Modified Scripts for Blog Posts
1 parent f7112dd commit ee668b6

File tree

59 files changed

+1553
-303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1553
-303
lines changed
-359 KB
Binary file not shown.

.vs/slnx.sqlite

152 KB
Binary file not shown.

Audit/Audit.ssmssqlproj

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="Audit">
3+
<Items>
4+
<LogicalFolder Name="Connections" Type="2" Sorted="true">
5+
<Items />
6+
</LogicalFolder>
7+
<LogicalFolder Name="Queries" Type="0" Sorted="true">
8+
<Items>
9+
<FileNode Name="create-database-audit.sql">
10+
<AssociatedConnectionMoniker />
11+
<AssociatedConnSrvName />
12+
<AssociatedConnUserName />
13+
<FullPath>create-database-audit.sql</FullPath>
14+
</FileNode>
15+
</Items>
16+
</LogicalFolder>
17+
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
18+
<Items />
19+
</LogicalFolder>
20+
</Items>
21+
</SqlWorkbenchSqlProject>

Audit/create-database-audit.sql

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
USE master;
2+
3+
CREATE SERVER AUDIT audit_dba
4+
TO FILE
5+
(
6+
FILEPATH = 'E:\audit',
7+
MAXSIZE = 5120 MB,
8+
MAX_ROLLOVER_FILES=4,
9+
RESERVE_DISK_SPACE = OFF
10+
)
11+
WITH (QUEUE_DELAY = 5000)
12+
GO
13+
ALTER SERVER AUDIT audit_dba WITH( STATE = ON)
14+
GO
15+
16+
USE facebook
17+
go
18+
create database audit specification audit_dba
19+
for server audit audit_dba
20+
add (SELECT, INSERT, UPDATE, DELETE ON dbo.some_table by public),
21+
add (SELECT, INSERT, UPDATE, DELETE ON dbo.some_table by public)
22+
WITH (STATE = ON)
-5.91 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
Template Path
22
\\dbatestserver\H$\Performance-Issues\DBA_PerfMon_Collector-Template.xml
33
\GitHub\SQLDBA-SSMS-Solution\Baselining\DBA_PerfMon_Collector-Template.xml
4+
\\Msi\sqlwatch
45

56
LogMan.exe => Manage Performance Monitor & performance logs from the command line.
7+
https://docs.microsoft.com/en-us/archive/blogs/jeff_stokes/how-to-sustain-your-data-collector-set-through-a-reboot
8+
http://www.myfaqbase.com/q0001438-Software-OS-Windows-Command-Line-What-is-the-syntax-of-logman-exe-command.html
69
https://ss64.com/nt/logman.html
710
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/logman
11+
https://www.sqlshack.com/sql-server-performance-tuning-using-windows-performance-monitor/
12+
https://www.mssqltips.com/sqlservertip/1722/collecting-performance-counters-and-using-sql-server-to-analyze-the-data/
13+
https://techcommunity.microsoft.com/t5/testingspot-blog/how-to-import-perfmon-logs-into-a-sql-database-to-create-excel/ba-p/367635
814

9-
logman import -name “DBA_PerfMon_Collector” -xml “E:\GitHub\SQLDBA-SSMS-Solution\Baselining\DBA_PerfMon_Collector-Template.xml
10-
logman update -name “DBA_PerfMon_Collector” -f bin -v mmddhhmm -o "E:\Downloads" -rf 00:05:00 -max 102400
11-
logman start -name “DBA_PerfMon_Collector”
15+
cls
1216

13-
perfmon /sys
17+
$collector_root_directory = 'D:\MSSQL15.MSSQLSERVER\SQLWATCH';
18+
$data_collector_template_path = “$collector_root_directory\DBA_PerfMon_Collector-Template.xml”;
19+
$log_file_path = "$collector_root_directory\$($env:COMPUTERNAME)__"
20+
$data_collector_set_name = 'DBA_PerfMon_Collector';
21+
$file_rotation_time = '00:00:05'
22+
$sample_interval = '00:00:05'
23+
$version_format = 'yyyyMMdd\-HHmmss'
24+
25+
logman import -name “$data_collector_set_name” -xml “$data_collector_template_path”
26+
logman update -name “$data_collector_set_name” -f bin -cnf "$file_rotation_time" -o "$log_file_path" -si "$sample_interval"
27+
logman start -name “$data_collector_set_name”
28+
29+
<#
30+
logman stop -name “$data_collector_set_name”
31+
logman delete -name “$data_collector_set_name”
32+
#>
33+
34+
35+
perfmon /sys

BlitzQueries/BlitzQueries.ssmssqlproj

+21-15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
2828
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
2929
</ConnectionNode>
30+
<ConnectionNode Name="SQL-A:sa">
31+
<Created>2020-07-25T15:51:01.3754048+05:30</Created>
32+
<Type>SQL</Type>
33+
<Server>SQL-A</Server>
34+
<UserName>sa</UserName>
35+
<Authentication>SQL</Authentication>
36+
<InitialDB />
37+
<LoginTimeout>30</LoginTimeout>
38+
<ExecutionTimeout>0</ExecutionTimeout>
39+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
40+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
41+
</ConnectionNode>
3042
</Items>
3143
</LogicalFolder>
3244
<LogicalFolder Name="Queries" Type="0" Sorted="true">
@@ -98,8 +110,8 @@
98110
<FullPath>Detect n Reduce High VLFs - All Dbs.sql</FullPath>
99111
</FileNode>
100112
<FileNode Name="Detect n Reduce High VLFs.sql">
101-
<AssociatedConnectionMoniker />
102-
<AssociatedConnSrvName />
113+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
114+
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
103115
<AssociatedConnUserName />
104116
<FullPath>Detect n Reduce High VLFs.sql</FullPath>
105117
</FileNode>
@@ -110,9 +122,9 @@
110122
<FullPath>Find-Indirect-Connections.sql</FullPath>
111123
</FileNode>
112124
<FileNode Name="Find-Statistics.sql">
113-
<AssociatedConnectionMoniker />
114-
<AssociatedConnSrvName />
115-
<AssociatedConnUserName />
125+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:SQL-A:False:sa</AssociatedConnectionMoniker>
126+
<AssociatedConnSrvName>SQL-A</AssociatedConnSrvName>
127+
<AssociatedConnUserName>sa</AssociatedConnUserName>
116128
<FullPath>Find-Statistics.sql</FullPath>
117129
</FileNode>
118130
<FileNode Name="Fragmentation-Analysis.sql">
@@ -127,12 +139,6 @@
127139
<AssociatedConnUserName />
128140
<FullPath>Other queries.sql</FullPath>
129141
</FileNode>
130-
<FileNode Name="Perf Counters.sql">
131-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:LOCALHOST:True</AssociatedConnectionMoniker>
132-
<AssociatedConnSrvName>LOCALHOST</AssociatedConnSrvName>
133-
<AssociatedConnUserName />
134-
<FullPath>Perf Counters.sql</FullPath>
135-
</FileNode>
136142
<FileNode Name="Plan-Cache-Analysis.sql">
137143
<AssociatedConnectionMoniker />
138144
<AssociatedConnSrvName />
@@ -145,11 +151,11 @@
145151
<AssociatedConnUserName />
146152
<FullPath>Querying Deadlocks From System_Health XEvent.sql</FullPath>
147153
</FileNode>
148-
<FileNode Name="ResourceMonitor-Memory-Signals.sql">
154+
<FileNode Name="ResourceMonitor-PerfMon-CPU-Memory.sql">
149155
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
150156
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
151157
<AssociatedConnUserName />
152-
<FullPath>ResourceMonitor-Memory-Signals.sql</FullPath>
158+
<FullPath>ResourceMonitor-PerfMon-CPU-Memory.sql</FullPath>
153159
</FileNode>
154160
<FileNode Name="SQL Server 2008 R2 Diagnostic Information Queries.sql">
155161
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:LOCALHOST:True</AssociatedConnectionMoniker>
@@ -176,8 +182,8 @@
176182
<FullPath>SQL Server 2016 Diagnostic Information Queries.sql</FullPath>
177183
</FileNode>
178184
<FileNode Name="SQL Server 2017 Diagnostic Information Queries.sql">
179-
<AssociatedConnectionMoniker />
180-
<AssociatedConnSrvName />
185+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
186+
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
181187
<AssociatedConnUserName />
182188
<FullPath>SQL Server 2017 Diagnostic Information Queries.sql</FullPath>
183189
</FileNode>

BlitzQueries/Perf Counters.sql

-68
This file was deleted.

BlitzQueries/ResourceMonitor-Memory-Signals.sql renamed to BlitzQueries/ResourceMonitor-PerfMon-CPU-Memory.sql

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- https://www.sqlskills.com/blogs/jonathan/identifying-external-memory-pressure-with-dm_os_ring_buffers-and-ring_buffer_resource_monitor/
2-
exec sp_HealthCheck 2
2+
--exec sp_HealthCheck 2
33

4-
select cast(sm.total_physical_memory_kb * 1.0 / 1024 / 1024 as numeric(20,0)) as total_physical_memory_gb,
4+
select 'sys.dm_os_sys_memory' as RunningQuery, cast(sm.total_physical_memory_kb * 1.0 / 1024 / 1024 as numeric(20,0)) as total_physical_memory_gb,
55
cast(sm.available_physical_memory_kb * 1.0 / 1024 / 1024 as numeric(20,2)) as available_physical_memory_gb,
66
cast((sm.total_page_file_kb - sm.available_page_file_kb) * 1.0 / 1024 / 1024 as numeric(20,0)) as used_page_file_gb,
77
cast(sm.system_cache_kb * 1.0 / 1024 /1024 as numeric(20,2)) as system_cache_gb,
@@ -10,6 +10,15 @@ select cast(sm.total_physical_memory_kb * 1.0 / 1024 / 1024 as numeric(20,0)) as
1010
cast(((sm.total_physical_memory_kb-sm.available_physical_memory_kb) * 100.0) / sm.total_physical_memory_kb as numeric(20,2)) as memory_usage_percentage
1111
from sys.dm_os_sys_memory as sm
1212

13+
-- SQL Server Process Address space info (Query 6) (Process Memory)
14+
-- (shows whether locked pages is enabled, among other things)
15+
SELECT 'sys.dm_os_process_memory' as RunningQuery, physical_memory_in_use_kb/1024 AS [SQL Server Memory Usage (MB)],
16+
page_fault_count, memory_utilization_percentage, available_commit_limit_kb,
17+
process_physical_memory_low, process_virtual_memory_low,
18+
locked_page_allocations_kb/1024 AS [SQL Server Locked Pages Allocation (MB)],
19+
large_page_allocations_kb/1024 AS [SQL Server Large Pages Allocation (MB)]
20+
FROM sys.dm_os_process_memory WITH (NOLOCK) OPTION (RECOMPILE);
21+
1322
-- System Memory Usage
1423
SELECT top 3 EventTime,
1524
record.value('(/Record/ResourceMonitor/Notification)[1]', 'varchar(max)') as [Type],
@@ -27,6 +36,17 @@ FROM ( SELECT DATEADD (ss, (-1 * ((cpu_ticks / CONVERT (float, ( cpu_ticks / ms_
2736
) AS tab
2837
ORDER BY EventTime DESC;
2938

39+
--Total amount of RAM consumed by database data (Buffer Pool). This should be the highest usage of Memory on the server.
40+
Select SQLBufferPoolUsedMemoryMB = (Select SUM(pages_kb)/1024 AS [SPA Mem, Mb] FROM sys.dm_os_memory_clerks WITH (NOLOCK) Where type = 'MEMORYCLERK_SQLBUFFERPOOL')
41+
--Total amount of RAM used by SQL Server memory clerks (includes Buffer Pool)
42+
, SQLAllMemoryClerksUsedMemoryMB = (Select SUM(pages_kb)/1024 AS [SPA Mem, Mb] FROM sys.dm_os_memory_clerks WITH (NOLOCK))
43+
--How long in seconds since data was removed from the Buffer Pool, to be replaced with data from disk. (Key indicator of memory pressure when below 300 consistently)
44+
,[PageLifeExpectancy] = (SELECT cntr_value FROM sys.dm_os_performance_counters WITH (NOLOCK) WHERE [object_name] LIKE N'%Buffer Manager%' AND counter_name = N'Page life expectancy' )
45+
--How many memory operations are Pending (should always be 0, anything above 0 for extended periods of time is a very high sign of memory pressure)
46+
,[MemoryGrantsPending] = (SELECT cntr_value FROM sys.dm_os_performance_counters WITH (NOLOCK) WHERE [object_name] LIKE N'%Memory Manager%' AND counter_name = N'Memory Grants Pending' )
47+
--How many memory operations are Outstanding (should always be 0, anything above 0 for extended periods of time is a very high sign of memory pressure)
48+
,[MemoryGrantsOutstanding] = (SELECT cntr_value FROM sys.dm_os_performance_counters WITH (NOLOCK) WHERE [object_name] LIKE N'%Memory Manager%' AND counter_name = N'Memory Grants Outstanding' );
49+
3050
SELECT top 3 record_id, EventTime,
3151
CASE WHEN system_cpu_utilization_post_sp2 IS NOT NULL THEN system_cpu_utilization_post_sp2 ELSE system_cpu_utilization_pre_sp2 END AS system_cpu_utilization,
3252
CASE WHEN sql_cpu_utilization_post_sp2 IS NOT NULL THEN sql_cpu_utilization_post_sp2 ELSE sql_cpu_utilization_pre_sp2 END AS sql_cpu_utilization
@@ -42,4 +62,5 @@ FROM ( SELECT record.value('(Record/@id)[1]', 'int') AS record_id,
4262
AND record LIKE '%<SystemHealth>%'
4363
) AS t
4464
) AS t
45-
ORDER BY EventTime desc
65+
ORDER BY EventTime desc;
66+

BlitzQueries/whoIsActive.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
EXEC sp_WhoIsActive @get_full_inner_text=1, @get_transaction_info=1, @get_task_info=2, @get_locks=1, @get_avg_time=1, @get_additional_info=1,@find_block_leaders=1, @get_outer_command =1
1+
EXEC sp_WhoIsActive @get_transaction_info=1, @get_task_info=2, @get_locks=1, @get_avg_time=1, @get_additional_info=1,@find_block_leaders=1, @get_outer_command =1 --,@get_full_inner_text=1
22
,@get_plans=2
33
--,@filter_type = 'session' ,@filter = '325'
44
--,@filter_type = 'login' ,@filter = 'Contso\RichMedia'
55
--,@sort_order = '[reads] desc'
66

77
-- EXEC sp_WhoIsActive @help = 1;
88

9-
EXEC sp_healthcheck @p_getExecutionPlan = 1;
9+
--EXEC sp_healthcheck @p_getExecutionPlan = 1;
1010
-- EXEC [dbo].[sp_HealthCheck] '?'
1111

1212
/*

Blocking Alert/Blocking Alert.ssmssqlproj

+16-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
1616
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
1717
</ConnectionNode>
18+
<ConnectionNode Name="MSI:MSI\ajayd">
19+
<Created>2020-08-03T23:23:57.2241558+05:30</Created>
20+
<Type>SQL</Type>
21+
<Server>MSI</Server>
22+
<UserName />
23+
<Authentication>Windows Authentication</Authentication>
24+
<InitialDB />
25+
<LoginTimeout>30</LoginTimeout>
26+
<ExecutionTimeout>0</ExecutionTimeout>
27+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
28+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
29+
</ConnectionNode>
1830
<ConnectionNode Name="TUL1CIPCNPDB1:MSI\ajayd">
1931
<Created>2019-11-08T20:15:38.1374995+05:30</Created>
2032
<Type>SQL</Type>
@@ -92,14 +104,14 @@
92104
<FullPath>Blocking-Alert-Azure.sql</FullPath>
93105
</FileNode>
94106
<FileNode Name="BlockingTree-Live.sql">
95-
<AssociatedConnectionMoniker />
96-
<AssociatedConnSrvName />
107+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:MSI:True</AssociatedConnectionMoniker>
108+
<AssociatedConnSrvName>MSI</AssociatedConnSrvName>
97109
<AssociatedConnUserName />
98110
<FullPath>BlockingTree-Live.sql</FullPath>
99111
</FileNode>
100112
<FileNode Name="BlockingTree-Live-WhoIsActive.sql">
101-
<AssociatedConnectionMoniker />
102-
<AssociatedConnSrvName />
113+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:MSI:True</AssociatedConnectionMoniker>
114+
<AssociatedConnSrvName>MSI</AssociatedConnSrvName>
103115
<AssociatedConnUserName />
104116
<FullPath>BlockingTree-Live-WhoIsActive.sql</FullPath>
105117
</FileNode>

0 commit comments

Comments
 (0)