Posts

Showing posts from March, 2020

Force Drop Publishing and Distributing in Publication/Replication

The below command will tell you how to forcefully remove publisher and distributor in the Replication or Publication ---Show or Delete distributors select * from msdb . dbo . MSdistpublishers delete from msdb . dbo . MSdistpublishers --Drop distribution database EXEC sp_dropdistributiondb 'distribution' ---Drop Distribution USE master go EXEC sp_dropdistributor @no_checks = 1 ----Show publication database EXEC sp_helptext 'sp_MSPublishdb'

ALTER ALWAYS ON ENDPOINT

Image
--Always On: Modify HADR_Endpoint Port --Skip to end of metadata --SSMS: Connect to the instance where you want to modify the listener --Execute the following TSQL-Satement to modify the TCP Port: ALTER ENDPOINT [Hadr_endpoint]     STATE = STARTED     AS TCP ( LISTENER_PORT = < enterPortNumberHere >, LISTENER_IP = ALL)     FOR DATA_MIRRORING ( ROLE = ALL, AUTHENTICATION = WINDOWS NEGOTIATE , ENCRYPTION = REQUIRED ALGORITHM AES )        --SSMS: Connect to the primary instance to update the AvailabiliityGroup Endpoint URL        --Execute the following TSQL-Statement: ALTER AVAILABILITY GROUP [ ] MODIFY REPLICA ON ' ' WITH ( endpoint_url = 'TCP:// : ' )        --Check, if Synchronization is running properly

Always On Database Health Status

SELECT ag . name AS [AG Name] , ar . replica_server_name , ar . availability_mode_desc , adc . [database_name] ,        drs . is_local , drs . is_primary_replica , drs . synchronization_state_desc , drs . is_commit_participant ,           drs . synchronization_health_desc , drs . recovery_lsn , drs . truncation_lsn , drs . last_sent_lsn ,           drs . last_sent_time , drs . last_received_lsn , drs . last_received_time , drs . last_hardened_lsn ,           drs . last_hardened_time , drs . last_redone_lsn , drs . last_redone_time , drs . log_send_queue_size ,           drs . log_send_rate , drs . redo_queue_size , drs . redo_rate , drs . filestream_send_rate ,           drs . end_of_log_lsn , drs . last_commit_lsn , ...

Last Backup Information in SQL Server

SELECT ISNULL ( d . [name] , bs . [database_name] ) AS [Database] , d . recovery_model_desc AS [Recovery Model] ,        d . log_reuse_wait_desc AS [Log Reuse Wait Desc] ,     MAX ( CASE WHEN [type] = 'D' THEN bs . backup_finish_date ELSE NULL END ) AS [Last Full Backup] ,     MAX ( CASE WHEN [type] = 'I' THEN bs . backup_finish_date ELSE NULL END ) AS [Last Differential Backup] ,     MAX ( CASE WHEN [type] = 'L' THEN bs . backup_finish_date ELSE NULL END ) AS [Last Log Backup] FROM sys . databases AS d WITH ( NOLOCK ) LEFT OUTER JOIN msdb . dbo . backupset AS bs WITH ( NOLOCK ) ON bs . [database_name] = d . [name] AND bs . backup_finish_date > GETDATE ()- 30 WHERE d . name <> N'tempdb' GROUP BY ISNULL ( d . [name] , bs . [database_name] ), d . recovery_model_desc , d . log_reuse_wait_desc , d . [name] ORDER BY d . recover...

Creating Extended Events For Blocked and Deadlocks

CREATE EVENT SESSION [BlockedProcesses_Deadlocks] ON SERVER ADD EVENT sqlserver . blocked_process_report ( ACTION ( sqlserver . client_app_name , sqlserver . client_hostname , sqlserver . database_id , sqlserver . session_id , sqlserver . sql_text , sqlserver . username )),           ADD EVENT sqlserver . xml_deadlock_report ( ACTION ( sqlserver . client_app_name , sqlserver . client_hostname , sqlserver . database_id , sqlserver . session_id , sqlserver . sql_text , sqlserver . username ))           ADD TARGET package0 . event_file ( SET filename = N'D:\ExtendedEvents\BlockedProcesses_Deadlocks.xel' ) WITH ( MAX_MEMORY = 4096 KB , EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS , MAX_DISPATCH_LATENCY = 30 SECONDS , MAX_EVENT_SIZE = 0 KB , MEMORY_PARTITION_MODE = NONE , TRACK_CAUSALITY = OFF , STARTUP_STATE = OFF ) GO

Getting all the sql server agent job schedules timings in SQL Server

select   sysjobs . name job_name , sysjobs . enabled job_enabled , sysschedules . name schedule_name , sysschedules . freq_recurrence_factor , case   when freq_type = 4 then 'Daily' end frequency , 'every ' + cast ( freq_interval as varchar ( 3 )) + ' day(s)'   Days , case   when freq_subday_type = 2 then ' every ' + cast ( freq_subday_interval as varchar ( 7 ))   + ' seconds' + ' starting at '   + stuff ( stuff (RIGHT( replicate ( '0' , 6 ) +   cast ( active_start_time as varchar ( 6 )), 6 ), 3 , 0 , ':' ), 6 , 0 , ':' )   when freq_subday_type = 4 then ' every ' + cast ( freq_subday_interval as varchar ( 7 ))   + ' minutes' + ' starting at '   + stuff ( stuff (RIGHT( replicate ( '0' , 6 ) +   cast ( active_start_time as varchar ( 6 )), 6 ), 3 , 0 , ':' ), 6 , 0 , ':' )   wh...