Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c6dc991

Browse files
Modified Scripts
Modified Scripts
1 parent 17d0a2a commit c6dc991

File tree

10 files changed

+346
-79
lines changed

10 files changed

+346
-79
lines changed
4 KB
Binary file not shown.

‎Audit/Connection Limit.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ GO
211211
USE [master]
212212
GO
213213

214-
ALTER TRIGGER [audit_login_events] ON ALL SERVER
214+
CREATE TRIGGER [audit_login_events] ON ALL SERVER
215215
FOR
216216
LOGON
217217
AS

‎ErrorLogs/ErrorLogs.ssmssqlproj‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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="ErrorLogs">
3+
<Items>
4+
<LogicalFolder Name="Connections" Type="2" Sorted="true">
5+
<Items>
6+
<ConnectionNode Name="(local):MSI\ajayd">
7+
<Created>2020年08月25日T17:10:22.8227624+05:30</Created>
8+
<Type>SQL</Type>
9+
<Server>(local)</Server>
10+
<UserName />
11+
<Authentication>Windows Authentication</Authentication>
12+
<InitialDB>DBA</InitialDB>
13+
<LoginTimeout>30</LoginTimeout>
14+
<ExecutionTimeout>0</ExecutionTimeout>
15+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
16+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
17+
</ConnectionNode>
18+
</Items>
19+
</LogicalFolder>
20+
<LogicalFolder Name="Queries" Type="0" Sorted="true">
21+
<Items>
22+
<FileNode Name="PS-Search-SystemEventLogs.sql">
23+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
24+
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
25+
<AssociatedConnUserName />
26+
<FullPath>PS-Search-SystemEventLogs.sql</FullPath>
27+
</FileNode>
28+
<FileNode Name="QRY-Search-ErrorLog.sql">
29+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
30+
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
31+
<AssociatedConnUserName />
32+
<FullPath>QRY-Search-ErrorLog.sql</FullPath>
33+
</FileNode>
34+
<FileNode Name="QRY-SqlCluster-Failover-Time.sql">
35+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
36+
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
37+
<AssociatedConnUserName />
38+
<FullPath>QRY-SqlCluster-Failover-Time.sql</FullPath>
39+
</FileNode>
40+
</Items>
41+
</LogicalFolder>
42+
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
43+
<Items />
44+
</LogicalFolder>
45+
</Items>
46+
</SqlWorkbenchSqlProject>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
select cast(el.TimeGenerated as smalldatetime) as TimeGenerated,
2+
el.UserName, el.EventID, el.EntryType, el.Source
3+
,el.Message
4+
from tempdb..event_logs_ajay as el
5+
where ((Source = 'Microsoft-Windows-FailoverClustering')
6+
or (Source = 'Service Control Manager' and (Message like '%stop%' or Message like '%running%') )
7+
or (Source = 'Service Control Manager' and Message like '%SQL Server%')
8+
)
9+
and
10+
( Message not like 'The Background Intelligent Transfer Service service%'
11+
and Message not like 'The Remote Registry service%'
12+
and Message not like 'The AppX Deployment Service (AppXSVC) service%'
13+
and Message not like 'The Microsoft Monitoring Agent service%'
14+
and Message not like 'The Microsoft Account Sign-in Assistant service%'
15+
)
16+
order by el.TimeGenerated
17+
18+
/*
19+
$server = 'ServerNameHere'
20+
$Begin = Get-Date -Date '8/16/2020 02:00:00'
21+
$End = Get-Date -Date '8/16/2020 02:55:00'
22+
$event_logs = Get-EventLog -LogName System -After $Begin -Before $End
23+
$event_logs | Write-DbaDataTable -Database tempdb -SqlInstance $server -Table 'event_logs_ajay' -AutoCreateTable
24+
25+
26+
$tql_query = @"
27+
select cast(el.TimeGenerated as smalldatetime) as TimeGenerated,
28+
el.UserName, el.EventID, el.EntryType, el.Source
29+
,el.Message
30+
from tempdb..event_logs_ajay as el
31+
where ((Source = 'Microsoft-Windows-FailoverClustering')
32+
or (Source = 'Service Control Manager' and (Message like '%stop%' or Message like '%running%') )
33+
or (Source = 'Service Control Manager' and Message like '%SQL Server%')
34+
)
35+
and
36+
( Message not like 'The Background Intelligent Transfer Service service%'
37+
and Message not like 'The Remote Registry service%'
38+
and Message not like 'The AppX Deployment Service (AppXSVC) service%'
39+
and Message not like 'The Microsoft Monitoring Agent service%'
40+
and Message not like 'The Microsoft Account Sign-in Assistant service%'
41+
)
42+
order by el.TimeGenerated
43+
"@;
44+
45+
$query_rs = Invoke-DbaQuery -SqlInstance $server -Query $tql_query
46+
cls
47+
$query_rs | Out-String
48+
*/

‎ErrorLogs/QRY-Search-ErrorLog.sql‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
declare @start_time datetime, @end_time datetime;
3+
set @start_time = '2020年08月22日 03:00:00.000' -- August 22, 2020 05:16:00
4+
--set @start_time = DATEADD(minute,-120,getdate());
5+
set @end_time = '2020年08月22日 03:30:00.000';
6+
--set @end_time = DATEADD(minute,30,@start_time)
7+
8+
declare @NumErrorLogs int;
9+
exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',
10+
N'Software\Microsoft\MSSQLServer\MSSQLServer',
11+
N'NumErrorLogs',
12+
@NumErrorLogs OUTPUT;
13+
if OBJECT_ID('tempdb..#errorlog') is not null drop table #errorlog;
14+
create table #errorlog (LogDate datetime2 not null, ProcessInfo varchar(200) not null, Text varchar(2000) not null);
15+
16+
declare @counter int = isnull(@NumErrorLogs,6);
17+
while @counter >= 0
18+
begin
19+
insert #errorlog
20+
EXEC master.dbo.xp_readerrorlog @counter, 1, NULL, NULL, @start_time, @end_time, "asc";
21+
set @counter -= 1;
22+
23+
if exists (select * from #errorlog where LogDate > @end_time)
24+
break;
25+
end
26+
27+
select ROW_NUMBER()over(order by LogDate asc) as id,*
28+
from #errorlog as e
29+
where 1 = 1
30+
--and e.Text like '%pricing%'
31+
--and e.ProcessInfo not in ('Backup','Logon')
32+
--and not (e.ProcessInfo = 'Backup' and (e.Text like 'Log was backed up%' or e.Text like 'Database backed up. %' or e.Text like 'BACKUP DATABASE successfully%') )
33+
--and e.Text not like 'DbMgrPartnerCommitPolicy::SetSyncState:%'
34+
--and e.Text not like 'SQL Server blocked access to procedure%'
35+
--and e.Text not like 'Login failed for user %'
36+
--and e.Text not like 'AlwaysOn Availability Groups connection with secondary database terminated for primary database %'
37+
--and e.Text not like 'AlwaysOn Availability Groups connection with secondary database established for primary database %'
38+
--and e.Text like '%ALTER DATABASE%'
39+
order by LogDate asc
40+
41+
/*
42+
select create_date
43+
from sys.databases d
44+
where d.name = 'tempdb'
45+
46+
*/
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
-- https://sqlgeekspro.com/script-get-sql-cluster-failover-time-node-name/
2+
CREATE TABLE #ErrorLog(
3+
LogDate DATETIME,
4+
ErrorSource NVARCHAR(MAX),
5+
ErrorMessage NVARCHAR(MAX)
6+
)
7+
8+
CREATE TABLE #NumberOfLogs(
9+
ID INT PRIMARY KEY NOT NULL,
10+
LogDate DATETIME NOT NULL,
11+
LogFileSize bigint
12+
)
13+
14+
INSERT INTO #NumberOfLogs(ID,LogDate,LogFileSize)
15+
EXEC master.dbo.xp_enumerrorlogs
16+
17+
DECLARE @ErrorLogID INT
18+
19+
DECLARE cNumberOfLogs CURSOR FOR
20+
SELECT ID
21+
FROM #NumberOfLogs
22+
23+
OPEN cNumberOfLogs
24+
FETCH NEXT FROM cNumberOfLogs INTO @ErrorLogID
25+
WHILE @@FETCH_STATUS = 0
26+
27+
BEGIN
28+
INSERT INTO #ErrorLog(LogDate,ErrorSource,ErrorMessage)
29+
EXEC sp_readerrorlog @ErrorLogID, 1, 'NETBIOS'
30+
31+
INSERT INTO #ErrorLog(LogDate,ErrorSource,ErrorMessage)
32+
EXEC sp_readerrorlog @ErrorLogID, 1, 'SQL Server is terminating'
33+
FETCH NEXT FROM cNumberOfLogs INTO @ErrorLogID
34+
END
35+
36+
CLOSE cNumberOfLogs
37+
DEALLOCATE cNumberOfLogs
38+
39+
SELECT LogDate, ErrorMessage FROM #ErrorLog
40+
41+
DROP TABLE #ErrorLog
42+
DROP TABLE #NumberOfLogs

‎SQLDBA-SSMS Solution.ssmssln‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "VLDB-Shrink", "VLDB-Shrink\
7979
EndProject
8080
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "TempScripts", "TempScripts\TempScripts.ssmssqlproj", "{2AA8E206-6A25-4890-8FDA-08B61B56AD00}"
8181
EndProject
82+
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "ErrorLogs", "ErrorLogs\ErrorLogs.ssmssqlproj", "{5BC08764-DBEC-4148-AD69-4DF9BE6CAFDC}"
83+
EndProject
8284
Global
8385
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8486
Default|Default = Default|Default
@@ -123,6 +125,7 @@ Global
123125
{9DBE8D07-B02C-4B14-9274-FF2D318432FA}.Default|Default.ActiveCfg = Default
124126
{FB2AAE53-3565-4BA7-BC05-AFDA583E2DB6}.Default|Default.ActiveCfg = Default
125127
{2AA8E206-6A25-4890-8FDA-08B61B56AD00}.Default|Default.ActiveCfg = Default
128+
{5BC08764-DBEC-4148-AD69-4DF9BE6CAFDC}.Default|Default.ActiveCfg = Default
126129
EndGlobalSection
127130
GlobalSection(SolutionProperties) = preSolution
128131
HideSolutionNode = FALSE

‎SQLDBA-SSMS Solution.tss‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@
55
<string>D:\GitHub\SQLDBA-SSMS-Solution\BlitzQueries\WhatIsRunning.sql</string>
66
</ArrayOfString>
77
<ArrayOfString>
8-
<string>D:\GitHub\SQLDBA-SSMS-Solution\Baselining\Job [DBA - Log_With_sp_WhoIsActive].sql</string>
8+
<string>D:\GitHub\SQLDBA-SSMS-Solution\StackOverflow\Generate Workloads.sql</string>
99
</ArrayOfString>
1010
<ArrayOfString>
11-
<string>D:\GitHub\SQLDBA-SSMS-Solution\SQLWATCH\Grafana-Queries.sql</string>
11+
<string>D:\GitHub\SQLDBA-SSMS-Solution\SQLDBATools-Inventory\SCH-usp_collect_performance_metrics.sql</string>
1212
</ArrayOfString>
1313
<ArrayOfString>
1414
<string>D:\GitHub\SQLDBA-SSMS-Solution\SQLDBATools-Inventory\Grafana-Queries.sql</string>
1515
</ArrayOfString>
16+
<ArrayOfString>
17+
<string>D:\GitHub\SQLDBA-SSMS-Solution\Audit\Connection Limit.sql</string>
18+
</ArrayOfString>
19+
<ArrayOfString>
20+
<string>D:\GitHub\SQLDBA-SSMS-Solution\ErrorLogs\QRY-SqlCluster-Failover-Time.sql</string>
21+
</ArrayOfString>
22+
</ArrayOfArrayOfString>
23+
<ArrayOfArrayOfString>
24+
<ArrayOfString>
25+
<string>D:\GitHub\SQLDBA-SSMS-Solution\TempScripts\WaitStats-Grafana.sql</string>
26+
</ArrayOfString>
1627
</ArrayOfArrayOfString>
1728
</ArrayOfArrayOfArrayOfString>

‎SQLDBATools-Inventory/SCH-Create-Function-utc2local.sql‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ begin
4242
end
4343
go
4444

45+
use master
46+
go
4547

46-
alter function time2duration (@time bigint, @unit varchar(20) = 'second')
48+
alter function time2duration (@time varchar(27), @unit varchar(20) = 'second')
4749
returns varchar(30)
4850
as
4951
begin
@@ -83,4 +85,5 @@ begin
8385
end
8486
go
8587

86-
--select master.dbo.time2duration(121,'s')
88+
89+
--select /* Convert 5428424 seconds into [DD hh:mm:ss] */ master.dbo.time2duration(5428424,'s');

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /