Skip to content

Commit cb4ee50

Browse files
committed
Updating Scripts - July 10th
Updating Scripts
1 parent a6f6614 commit cb4ee50

19 files changed

+2179
-586
lines changed
1.5 KB
Binary file not shown.

Backup-Restore/Backup-Restore.ssmssqlproj

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,26 @@
1515
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
1616
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
1717
</ConnectionNode>
18+
<ConnectionNode Name="SQL-A:sa">
19+
<Created>2018-07-06T12:51:35.942614+05:30</Created>
20+
<Type>SQL</Type>
21+
<Server>SQL-A</Server>
22+
<UserName>sa</UserName>
23+
<Authentication>SQL</Authentication>
24+
<InitialDB>ProInternals</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
</Items>
1931
</LogicalFolder>
2032
<LogicalFolder Name="Queries" Type="0" Sorted="true">
2133
<Items>
2234
<FileNode Name="1) Generate - Backup Script.sql">
23-
<AssociatedConnectionMoniker />
24-
<AssociatedConnSrvName />
25-
<AssociatedConnUserName />
35+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:SQL-A:False:sa</AssociatedConnectionMoniker>
36+
<AssociatedConnSrvName>SQL-A</AssociatedConnSrvName>
37+
<AssociatedConnUserName>sa</AssociatedConnUserName>
2638
<FullPath>1) Generate - Backup Script.sql</FullPath>
2739
</FileNode>
2840
<FileNode Name="2) Script Out DB Permissions in case of DB Refresh.sql">

BlitzQueries/BlitzQueries.ssmssqlproj

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
<Items>
44
<LogicalFolder Name="Connections" Type="2" Sorted="true">
55
<Items>
6+
<ConnectionNode Name="BAN-2ADWIVEDI-L:CORPORATE\adwivedi">
7+
<Created>2018-07-02T09:16:00.3182224+05:30</Created>
8+
<Type>SQL</Type>
9+
<Server>BAN-2ADWIVEDI-L</Server>
10+
<UserName />
11+
<Authentication>Windows Authentication</Authentication>
12+
<InitialDB />
13+
<LoginTimeout>30</LoginTimeout>
14+
<ExecutionTimeout>0</ExecutionTimeout>
15+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
16+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
17+
</ConnectionNode>
618
<ConnectionNode Name="BAN-2ADWIVEDI-L:sa">
719
<Created>2018-06-13T16:03:02.7281313+05:30</Created>
820
<Type>SQL</Type>
@@ -15,6 +27,18 @@
1527
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
1628
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
1729
</ConnectionNode>
30+
<ConnectionNode Name="TUL1CIPCNPDB1:CORPORATE\adwivedi">
31+
<Created>2018-06-25T11:10:27.1229725+05:30</Created>
32+
<Type>SQL</Type>
33+
<Server>TUL1CIPCNPDB1</Server>
34+
<UserName />
35+
<Authentication>Windows Authentication</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>
1842
<ConnectionNode Name="TUL1CIPEDB2:CORPORATE\adwivedi">
1943
<Created>2018-06-18T22:17:38.8911865+05:30</Created>
2044
<Type>SQL</Type>
@@ -32,8 +56,8 @@
3256
<LogicalFolder Name="Queries" Type="0" Sorted="true">
3357
<Items>
3458
<FileNode Name="Blitz.sql">
35-
<AssociatedConnectionMoniker />
36-
<AssociatedConnSrvName />
59+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:BAN-2ADWIVEDI-L:True</AssociatedConnectionMoniker>
60+
<AssociatedConnSrvName>BAN-2ADWIVEDI-L</AssociatedConnSrvName>
3761
<AssociatedConnUserName />
3862
<FullPath>Blitz.sql</FullPath>
3963
</FileNode>
@@ -44,15 +68,15 @@
4468
<FullPath>BlitzCache.sql</FullPath>
4569
</FileNode>
4670
<FileNode Name="blitzFirst.sql">
47-
<AssociatedConnectionMoniker />
48-
<AssociatedConnSrvName />
71+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPEDB2:True</AssociatedConnectionMoniker>
72+
<AssociatedConnSrvName>TUL1CIPEDB2</AssociatedConnSrvName>
4973
<AssociatedConnUserName />
5074
<FullPath>blitzFirst.sql</FullPath>
5175
</FileNode>
5276
<FileNode Name="BlitzIndex.sql">
53-
<AssociatedConnectionMoniker />
54-
<AssociatedConnSrvName />
55-
<AssociatedConnUserName />
77+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:BAN-2ADWIVEDI-L:False:sa</AssociatedConnectionMoniker>
78+
<AssociatedConnSrvName>BAN-2ADWIVEDI-L</AssociatedConnSrvName>
79+
<AssociatedConnUserName>sa</AssociatedConnUserName>
5680
<FullPath>BlitzIndex.sql</FullPath>
5781
</FileNode>
5882
<FileNode Name="Blocking Tree.sql">
@@ -74,9 +98,9 @@
7498
<FullPath>CREATE TABLE [dbo].[whatIsRunning].sql</FullPath>
7599
</FileNode>
76100
<FileNode Name="Other queries.sql">
77-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:BAN-2ADWIVEDI-L:False:sa</AssociatedConnectionMoniker>
78-
<AssociatedConnSrvName>BAN-2ADWIVEDI-L</AssociatedConnSrvName>
79-
<AssociatedConnUserName>sa</AssociatedConnUserName>
101+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPEDB2:True</AssociatedConnectionMoniker>
102+
<AssociatedConnSrvName>TUL1CIPEDB2</AssociatedConnSrvName>
103+
<AssociatedConnUserName />
80104
<FullPath>Other queries.sql</FullPath>
81105
</FileNode>
82106
<FileNode Name="Perf Counters.sql">

BlitzQueries/Other queries.sql

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ SELECT @@servername as SvrName,
2525
DATEDIFF(day,create_date, GETDATE()) as ServiceStartDays
2626
FROM sys.databases as d where d.name = 'tempdb';
2727

28+
-- Current RAM share of SQL Server
29+
select m.total_physical_memory_kb/1024/1024 as [Ram(GB)], system_memory_state_desc from sys.dm_os_sys_memory as m
30+
2831
-- Get selected server properties (SQL Server 2014) (Query 3) (Server Properties)
2932
SELECT SERVERPROPERTY('MachineName') AS [MachineName], SERVERPROPERTY('ServerName') AS [ServerName],
3033
SERVERPROPERTY('InstanceName') AS [Instance], SERVERPROPERTY('IsClustered') AS [IsClustered],
@@ -348,7 +351,7 @@ select * from tt where tt.QueryText not like 'select name as objectName from sou
348351
and tt.QueryText not like 'SELECT program_base.[program_id] AS %'
349352
order by PlanCount desc
350353

351-
-- How to examine IO subsystem latencies from within SQL Server
354+
-- How to examine IO subsystem latencies from within SQL Server (Disk Latency)
352355
-- https://www.sqlskills.com/blogs/paul/how-to-examine-io-subsystem-latencies-from-within-sql-server/
353356
-- https://sqlperformance.com/2015/03/io-subsystem/monitoring-read-write-latency
354357
-- https://www.brentozar.com/blitz/slow-storage-reads-writes/
@@ -387,10 +390,11 @@ ORDER BY [Latency] DESC
387390
--ORDER BY [WriteLatency] DESC;
388391
GO
389392

390-
391-
-- Current RAM share of SQL Server
392-
select 32767/1024 [total gb], 30719/1024 [sql gb]
393-
go
393+
/* Look at pending I/O requests by file */
394+
SELECT DB_NAME(mf.database_id) AS [Database] , mf.physical_name ,r.io_pending , r.io_pending_ms_ticks , r.io_type , fs.num_of_reads , fs.num_of_writes
395+
FROM sys.dm_io_pending_io_requests AS r INNER JOIN sys.dm_io_virtual_file_stats(NULL, NULL) AS fs ON r.io_handle = fs.file_handle INNER JOIN sys.master_files AS mf ON fs.database_id = mf.database_id
396+
AND fs.file_id = mf.file_id
397+
ORDER BY r.io_pending , r.io_pending_ms_ticks DESC ;
394398

395399

396400
/* active tables without clustered index */
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Page Splits */
2+
USE Ajay;
3+
4+
create table dbo.PageSplitDemo
5+
( ID INT NOT NULL,
6+
Data varchar(8000) null
7+
)
8+
9+
create unique clustered index CI_UQ_PageSplitDemo
10+
on dbo.PageSplitDemo(ID);
11+
12+
;with tt as (select top 10000 ROW_NUMBER()over(order by a.number) as ID from master.dbo.spt_values as a cross apply master.dbo.spt_values as b)
13+
insert dbo.PageSplitDemo (ID)
14+
select ID*2 from tt where ID <= 620;
15+
16+
select page_count, record_count, avg_page_space_used_in_percent
17+
from sys.dm_db_index_physical_stats(db_id(),object_id(N'dbo.PageSplitDemo'),1,NULL,'DETAILED');
18+
/*
19+
page_count record_count avg_page_space_used_in_percent
20+
1 620 99.5552260934025
21+
*/
22+
select * from dbo.PageSplitDemo;
23+
24+
insert into dbo.PageSplitDemo (ID, Data)
25+
VALUES (101,REPLICATE('a',8000));
26+
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
This script estimates compression savings for all objects, indexes, and partitions in the current database.
3+
4+
See http://blogs.msdn.com/b/dfurman/archive/2011/02/25/estimating-data-compression-savings-for-entire-database.aspx for details.
5+
*/
6+
use Cosmo;
7+
8+
DECLARE @CompressionSavingsEstimate table
9+
(
10+
SchemaName sysname NOT NULL,
11+
ObjectName sysname NOT NULL,
12+
IndexName sysname NOT NULL,
13+
IndexType nvarchar(60) NOT NULL,
14+
PartitionNum int NOT NULL,
15+
CompressionType nvarchar(10) NOT NULL,
16+
[size_with_current_compression_setting (KB)] bigint NOT NULL,
17+
[size_with_requested_compression_setting (KB)] bigint NOT NULL,
18+
[sample_size_with_current_compression_setting (KB)] bigint NOT NULL,
19+
[sample_size_with_requested_compression_setting (KB)] bigint NOT NULL,
20+
PRIMARY KEY (SchemaName, ObjectName, IndexName, IndexType, PartitionNum, CompressionType)
21+
);
22+
DECLARE @ProcResult table
23+
(
24+
[object_name] sysname NOT NULL,
25+
[schema_name] sysname NOT NULL,
26+
[index_id] int NOT NULL,
27+
[partition_number] int NOT NULL,
28+
[size_with_current_compression_setting (KB)] bigint NOT NULL,
29+
[size_with_requested_compression_setting (KB)] bigint NOT NULL,
30+
[sample_size_with_current_compression_setting (KB)] bigint NOT NULL,
31+
[sample_size_with_requested_compression_setting (KB)] bigint NOT NULL
32+
);
33+
DECLARE @SchemaName sysname;
34+
DECLARE @ObjectName sysname;
35+
DECLARE @IndexID int;
36+
DECLARE @IndexName sysname;
37+
DECLARE @IndexType nvarchar(60);
38+
DECLARE @PartitionNum int;
39+
DECLARE @CompTypeNum tinyint;
40+
DECLARE @CompressionType nvarchar(60);
41+
42+
SET NOCOUNT ON;
43+
44+
DECLARE CompressedIndex INSENSITIVE CURSOR FOR
45+
SELECT s.name AS SchemaName,
46+
o.name AS ObjectName,
47+
i.index_id AS IndexID,
48+
COALESCE(i.name, '<HEAP>') AS IndexName,
49+
i.type_desc AS IndexType,
50+
p.partition_number AS PartitionNum
51+
FROM sys.schemas AS s
52+
INNER JOIN sys.objects AS o
53+
ON s.schema_id = o.schema_id
54+
INNER JOIN sys.indexes AS i
55+
ON o.object_id = i.object_id
56+
INNER JOIN sys.partitions AS p
57+
ON o.object_id = p.object_id
58+
AND
59+
i.index_id = p.index_id
60+
WHERE o.type_desc IN ('USER_TABLE','VIEW');
61+
62+
OPEN CompressedIndex;
63+
64+
WHILE 1 = 1
65+
BEGIN
66+
FETCH NEXT FROM CompressedIndex
67+
INTO @SchemaName, @ObjectName, @IndexID, @IndexName, @IndexType, @PartitionNum;
68+
69+
IF @@FETCH_STATUS <> 0
70+
BREAK;
71+
72+
SELECT @CompTypeNum = 0;
73+
WHILE @CompTypeNum <= 2
74+
BEGIN
75+
SELECT @CompressionType = CASE @CompTypeNum
76+
WHEN 0 THEN 'NONE'
77+
WHEN 1 THEN 'ROW'
78+
WHEN 2 THEN 'PAGE'
79+
END;
80+
81+
DELETE FROM @ProcResult;
82+
83+
RAISERROR('Estimating compression savings using "%s" compression for object "%s.%s", index "%s", partition %d...', 10, 1, @CompressionType, @SchemaName, @ObjectName, @IndexName, @PartitionNum);
84+
85+
INSERT INTO @ProcResult
86+
EXEC sp_estimate_data_compression_savings @schema_name = @SchemaName,
87+
@object_name = @ObjectName,
88+
@index_id = @IndexID,
89+
@partition_number = @PartitionNum,
90+
@data_compression = @CompressionType;
91+
92+
INSERT INTO @CompressionSavingsEstimate
93+
(
94+
SchemaName,
95+
ObjectName,
96+
IndexName,
97+
IndexType,
98+
PartitionNum,
99+
CompressionType,
100+
[size_with_current_compression_setting (KB)],
101+
[size_with_requested_compression_setting (KB)],
102+
[sample_size_with_current_compression_setting (KB)],
103+
[sample_size_with_requested_compression_setting (KB)]
104+
)
105+
SELECT [schema_name],
106+
[object_name],
107+
@IndexName,
108+
@IndexType,
109+
[partition_number],
110+
@CompressionType,
111+
[size_with_current_compression_setting (KB)],
112+
[size_with_requested_compression_setting (KB)],
113+
[sample_size_with_current_compression_setting (KB)],
114+
[sample_size_with_requested_compression_setting (KB)]
115+
FROM @ProcResult;
116+
117+
SELECT @CompTypeNum += 1;
118+
END;
119+
END;
120+
121+
CLOSE CompressedIndex;
122+
DEALLOCATE CompressedIndex;
123+
124+
SELECT SchemaName,
125+
ObjectName,
126+
IndexName,
127+
IndexType,
128+
PartitionNum,
129+
CompressionType,
130+
AVG([size_with_current_compression_setting (KB)]) AS [size_with_current_compression_setting (KB)],
131+
AVG([size_with_requested_compression_setting (KB)]) AS [size_with_requested_compression_setting (KB)],
132+
AVG([sample_size_with_current_compression_setting (KB)]) AS [sample_size_with_current_compression_setting (KB)],
133+
AVG([sample_size_with_requested_compression_setting (KB)]) AS [sample_size_with_requested_compression_setting (KB)]
134+
FROM @CompressionSavingsEstimate
135+
GROUP BY GROUPING SETS (
136+
(CompressionType),
137+
(SchemaName, ObjectName, IndexName, IndexType, PartitionNum, CompressionType)
138+
)
139+
ORDER BY SchemaName, ObjectName, IndexName, IndexType, PartitionNum, CompressionType DESC;
140+
141+
SET NOCOUNT OFF;

Misscellaneous Queries/Misscellaneous Queries.ssmssqlproj

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
4040
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
4141
</ConnectionNode>
42+
<ConnectionNode Name="TUL1CIPCNPDB1:CORPORATE\adwivedi">
43+
<Created>2018-06-25T18:25:06.6553428+05:30</Created>
44+
<Type>SQL</Type>
45+
<Server>TUL1CIPCNPDB1</Server>
46+
<UserName />
47+
<Authentication>Windows Authentication</Authentication>
48+
<InitialDB>master</InitialDB>
49+
<LoginTimeout>30</LoginTimeout>
50+
<ExecutionTimeout>0</ExecutionTimeout>
51+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
52+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
53+
</ConnectionNode>
4254
</Items>
4355
</LogicalFolder>
4456
<LogicalFolder Name="Queries" Type="0" Sorted="true">
@@ -73,6 +85,12 @@
7385
<AssociatedConnUserName />
7486
<FullPath>Find Long Running Query.sql</FullPath>
7587
</FileNode>
88+
<FileNode Name="HADR or Mirroring.sql">
89+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:BAN-2ADWIVEDI-L:False:sa</AssociatedConnectionMoniker>
90+
<AssociatedConnSrvName>BAN-2ADWIVEDI-L</AssociatedConnSrvName>
91+
<AssociatedConnUserName>sa</AssociatedConnUserName>
92+
<FullPath>HADR or Mirroring.sql</FullPath>
93+
</FileNode>
7694
<FileNode Name="Kill All Session for DB.sql">
7795
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:BAN-2ADWIVEDI-L:False:sa</AssociatedConnectionMoniker>
7896
<AssociatedConnSrvName>BAN-2ADWIVEDI-L</AssociatedConnSrvName>
@@ -86,8 +104,8 @@
86104
<FullPath>Return Query Output as HTML Table.sql</FullPath>
87105
</FileNode>
88106
<FileNode Name="RoboCopy.sql">
89-
<AssociatedConnectionMoniker />
90-
<AssociatedConnSrvName />
107+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPCNPDB1:True</AssociatedConnectionMoniker>
108+
<AssociatedConnSrvName>TUL1CIPCNPDB1</AssociatedConnSrvName>
91109
<AssociatedConnUserName />
92110
<FullPath>RoboCopy.sql</FullPath>
93111
</FileNode>
@@ -97,18 +115,18 @@
97115
<AssociatedConnUserName />
98116
<FullPath>SQL Server Error Logs.sql</FullPath>
99117
</FileNode>
100-
<FileNode Name="SQLQuery1.sql">
101-
<AssociatedConnectionMoniker />
102-
<AssociatedConnSrvName />
103-
<AssociatedConnUserName />
104-
<FullPath>SQLQuery1.sql</FullPath>
105-
</FileNode>
106118
<FileNode Name="System Memory Usage.sql">
107119
<AssociatedConnectionMoniker />
108120
<AssociatedConnSrvName />
109121
<AssociatedConnUserName />
110122
<FullPath>System Memory Usage.sql</FullPath>
111123
</FileNode>
124+
<FileNode Name="TableSizeMetrics - RecordCount n PageCount.sql">
125+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:BAN-2ADWIVEDI-L:True</AssociatedConnectionMoniker>
126+
<AssociatedConnSrvName>BAN-2ADWIVEDI-L</AssociatedConnSrvName>
127+
<AssociatedConnUserName />
128+
<FullPath>TableSizeMetrics - RecordCount n PageCount.sql</FullPath>
129+
</FileNode>
112130
<FileNode Name="Tempdb_Usage.sql">
113131
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:BAN-2ADWIVEDI-L:True</AssociatedConnectionMoniker>
114132
<AssociatedConnSrvName>BAN-2ADWIVEDI-L</AssociatedConnSrvName>

Misscellaneous Queries/RoboCopy.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33

44
-- Copy single file named 'ACTIONSHEET_DATA_20180321.csq' from source folder to destination folder
55
robocopy G:\Backup \\tul1dbapfs2\f$\TUL1CIPEDB2\Full_Backups ACTIONSHEET_DATA_20180321.csq
6-
robocopy \\tul1cipedb2\I$\pssdiag_Output_June06_Ajay "E:\Cosmo Issue\Replication_PSSDiag_Output" CosmoServer__0125AM_to_0205AM_CST.zip
6+
robocopy \\tul1cipedb2\I$\pssdiag_Output_June06_Ajay "E:\Cosmo Issue\Replication_PSSDiag_Output" CosmoServer__0125AM_to_0205AM_CST.zip
7+
8+
robocopy \\TUL1CIPEDB2\C$\DBA\SQLTrace E:\PerformanceAnalysis\Cosmo_Publisher_Baseline\SQLTrace TUL1CIPEDB2_25Jun2018_1030PM.zip
9+
robocopy \\TUL1CIPEDB2\C$\DBA\SQLTrace \\TUL1CIPCNPDB1\G$\DBA\SQLTrace TUL1CIPEDB2_25Jun2018_1030PM.trc
10+
robocopy \\TUL1CIPCNPDB1\G$\DBA\SQLTrace E:\PerformanceAnalysis\Cosmo_Publisher_Baseline\SQLTrace TUL1CIPCNPDB1_26Jun2018_0153AM.zip

0 commit comments

Comments
 (0)