Tuesday, January 24, 2023
SQL SERVER did not detect newly added CPUs
hi , we had a situation where Windows team added 2cpu and it did not detect in SQL SERVER
before:
EXECUTE
RECONFIGURE now the change showuld show and no need of reboot
After:
Thursday, January 12, 2023
Audit login time, login name, hostname ,program name, client Etc Connection tracking and other info
1.USE [master]
GO
/****** Object: Table [dbo].[DBALogonAudit] Script Date: 1/12/2023 4:39:31 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[DBALogonAudit](
[SessionId] [int] NULL,
[LogonTime] [datetime] NULL,
[HostName] [varchar](50) NULL,
[ProgramName] [varchar](500) NULL,
[LoginName] [varchar](50) NULL,
[ClientHost] [varchar](50) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
2.---create trigger
USE [master]
GO
/****** Object: DdlTrigger [LogonAuditTrigger] Script Date: 1/12/2023 4:26:12 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [LogonAuditTrigger] /* Creates trigger for logons */ ON ALL SERVER FOR LOGON AS
BEGIN DECLARE @LogonTriggerData xml, @EventTime datetime, @LoginName varchar(50), @ClientHost varchar(50), @LoginType varchar(50), @HostName varchar(50), @AppName varchar(500)
SET @LogonTriggerData = eventdata()
SET @EventTime = @LogonTriggerData.value('(/EVENT_INSTANCE/PostTime)[1]', 'datetime')
SET @LoginName = @LogonTriggerData.value('(/EVENT_INSTANCE/LoginName)[1]', 'varchar(50)')
SET @ClientHost = @LogonTriggerData.value('(/EVENT_INSTANCE/ClientHost)[1]', 'varchar(50)')
SET @HostName = HOST_NAME() SET @AppName = APP_NAME()
INSERT INTO DBALogonAudit
SELECT @@spid, @EventTime, @HostName, @AppName, @LoginName, @ClientHost
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ENABLE TRIGGER [LogonAuditTrigger] ON ALL SERVER
GO
3. put below inside a sql job
--table should exist in a database
Use master
go
DECLARE @xml NVARCHAR(MAX)
DECLARE @body NVARCHAR(MAX)
SET @xml = CAST(( SELECT @@SERVERNAME AS 'td','',
s.name + '.' + t.Name AS 'td','',
part.rows AS 'td','',
CAST((SUM( DISTINCT au.Total_pages) * 8 ) / 1024.000 / 1024.000 AS NUMERIC(18, 3)) AS 'td'
FROM
SYS.Tables t INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
INNER JOIN SYS.Indexes idx ON t.Object_id = idx.Object_id
INNER JOIN SYS.Partitions part ON idx.Object_id = part.Object_id
AND idx.Index_id = part.Index_id
INNER JOIN SYS.Allocation_units au ON part.Partition_id = au.Container_id
INNER JOIN SYS.Filegroups fGrp ON idx.Data_space_id = fGrp.Data_space_id
INNER JOIN SYS.Database_files Df ON Df.Data_space_id = fGrp.Data_space_id
where s.name + '.' + t.Name Like '%DBALogonAudit%'
GROUP BY t.Name, s.name, part.rows
ORDER BY 2 DESC
FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
SET @body ='
'
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SQLMAil', -- replace with your SQL Database Mail Profile
@body = @body,
@body_format ='HTML',
@recipients = 'abc@abc.com', -- replace with your email address
@subject = 'Audit report' ;
Schemas Info, Please vist master.dbo.DBALogonAudit table to get more detailed Login Report
Servername | Tablename | RowsModified | TotalSpaceinGB |
---|
Friday, January 6, 2023
Serious performance issues after migrating SQL SERVER 2016 on a windows platform from windows Server 2012 to 2019
We migrated sql server 2016 from windows 2012 to windows 2019 and we had very bad perforamnce on queries..
we updated stats with full scan, rebuildd indexes after migration.. looked at Mx dop cost of threshold etc all loked good from our side.
but no improvement and asked windows and network team to look what are rubnning new in 2019 vs 2012 and they found out that
They have identified one potential issue that may be causing the performance drop between Server 2012 and Server 2019. We've noticed that Server 2019 does not properly disable Windows Defender when FireEye is installed, which may be causing additional resource contention from having two malware scanning platforms installed and running concurrently.
Uninstalled windows defernder
reboot
and BOOM all queries are running as before in old production system
Backup Percentage completed, to check status and also to heck history of backups
SELECT command,
s.text,
percent_complete,
CAST(((DATEDIFF(s,start_time,GetDate()))/3600) as varchar) + ' hour(s), '
+ CAST((DATEDIFF(s,start_time,GetDate())%3600)/60 as varchar) + 'min, '
+ CAST((DATEDIFF(s,start_time,GetDate())%60) as varchar) + ' sec' as running_time,
CAST((estimated_completion_time/3600000) as varchar) + ' hour(s), '
+ CAST((estimated_completion_time %3600000)/60000 as varchar) + 'min, '
+ CAST((estimated_completion_time %60000)/1000 as varchar) + ' sec' as est_time_to_go,
start_time,
dateadd(second,estimated_completion_time/1000, getdate()) as est_completion_time
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) s
WHERE r.command in ('RESTORE DATABASE', 'BACKUP DATABASE', 'RESTORE LOG', 'BACKUP LOG','ALTER DATABASE','DROP DATABASE','CREATE DATABASE')
go
SELECT top 150
bs.database_name,
bs.backup_start_date,
bs.backup_finish_date,
bs.server_name,
bs.user_name,
bs.type,
bm.physical_device_name
FROM msdb.dbo.backupset AS bs
INNER JOIN msdb.dbo.backupmediafamily AS bm on bs.media_set_id = bm.media_set_id
where backup_start_date>'2023-01-06 09:00:00.000'
order by backup_finish_date desc
Subscribe to:
Posts (Atom)
https://blog.sqlauthority.com/2009/06/27/sql-server-fix-error-17892-logon-failed-for-login-due-to-trigger-execution-changed-database-context...
-
SELECT is_broker_enabled, name FROM sys.databases All Availability Group Databases =0 It’s a default behavior. The message will ...
-
Hi, I have set up Always on Availability Groups on top of Windows Server Failover Cluster(WSFC) with two sql server stand alone installat...