Posts

Showing posts from 2018

REBUILD MASTER DATABASE WITH COMMAND PROMPT

Image
If the services did not come online before you go for REBUILD database try to bring the server online by using the command below using TRACE FLAG. If this did not work  follow the rebuild process. First check with below command. If the above command does not work please add  "-f" parameter which is case sensitive  and try once. If you are rebuilding NAMED INSATNCE of sql server please use provide the server name like below whether you start in single user mode or whether you start normally. If you are  using domain account first image is the use ful image. Sometimes this REBUILD database(above script or immediate image below) will not bring back existing databases back which are there in previously, so we need to address this in a different way. So go through the below links for reference. Whether it is windows authentication or mixed mode authentication providing value to 'sa' account is compulsory. moving system databases MSSQLSERVER_17204 After RE...

SQL Server Agent Jobs Status from Multiple instances through powershell query

The below powershell script brings information about SQL Server Agent jobs and its status from more than one SQL Server instance. CLEAR $HOSTNAME = 'COMPUTERNAMEHERE' Import-Module sqlps -DisableNameChecking $servernames = @( "computername\namedinstancename1" , "computername\namedinstancename2" , "computername\namedinstancename3" , "computername\namedinstancename4" , "computername\namedinstancename5" ) $servernames | ForEach-Object {     $computername = $_     #Get a server object which corresponds to the default instance     $srv = New-Object `     -TypeName 'Microsoft.SQLServer.Management.Smo.Server' `     -ArgumentList $computername     $srv . JobServer . Jobs |     Select-Object OriginatingServer , Name , LastRundate , LastRunOutcome , NextRunDate , CurrentRunstatus |     Where-Object LastRunOutcome -EQ "Failed"...

SQL Management Objects(SMO) of SQL Server in Powershell and also finding out Server Management Objects

Import-Module SQLPS -DisableNameChecking $MyComputer = $env:COMPUTERNAME #Provide sql server instance name here $instanceName = $MyComputer + '\TEST' $instanceName #This information will give you all SMO'S of SQL Server $server = New-Object ` -TypeName Microsoft.SQLServer.Management.Smo.Server ` -ArgumentList $instanceName $server | Get-Member -MemberType "Property" | Where-Object Definition -like "*SMO*"  The below Powershell query will provide us the information about SQL Server Assemblies  clear [ appdomain ]:: CurrentDomain . GetAssemblies() | Where { $_ . FullName -match "SQLServer" } | Select FullName 

Which SQL Server Agent operator has which mail id's

The below query will tell you which SQL Server Agent Operator is internally calling which mail id's. These operators we can assign to every sql server agent job. So whenever these jobs gets failed it will route to those mail id's USE msdb  GO   EXEC dbo.sp_help_operator       @operator_name = N'Provide Operator name here'; 

Who is the Owner of SQL Server Agent Jobs

SELECT  j . [name]  AS   'JobName' , Enabled   =   CASE   WHEN  j . Enabled   =  0  THEN   'No' ELSE   'Yes' END , l . [name]  AS   'OwnerName' FROM  MSDB . dbo . sysjobs j INNER   JOIN   Master . dbo . syslogins  l ON  j . owner_sid  =  l . sid ORDER   BY  j . [name]

Stopping multiple job at a time.

USE msdb; GO -- Disable Multiple SQL Jobs at once: DECLARE @dynSql NVARCHAR(MAX) = '' SELECT @dynSql += N'exec msdb.dbo.sp_update_job @job_name = ''' + name + N''', @enabled = 0;' + CHAR(10) + CHAR(13) FROM msdb.dbo.sysjobs WHERE enabled = 1 ORDER BY name; PRINT @dynSql;

Start and Stop SQL Server Services with Power shell

Image

Database Mirroring problem with SQL Server 2016 management Studio, ERROR :927

Image
Recently i have installed SQL SERVER 2016 RTM version on my machine and started working on it. One day  i have configured Mirroring and found the below error. The error showing as "Database sample is in the middle of restore".  First i though i am doing wrong. Later i realized that this is bug with Microsoft SQL Server Management Studio 18. Try the same steps with SQL Server Management Studio 2014, this works perfectly and you are able to configure database successfully

How to Start and Connect to MongoDB environment.

Image
---To Start MongoDB service run below command in command prompt with Admin privileges "C:\Program Files\MongoDB\Server\4.0\bin\mongod.exe"  ---To connect to the MongoDB environment run below command n command prompt with Admin privileges "C:\Program Files\MongoDB\Server\4.0\bin\mongo.exe" If you see below first i ran the command prompt with Administrator account but i have installed mongodb with 'Hi' account . So first i changed the user from Administrator account to Hi account by using CD Going inside of mongodb, open another command prompt and run the below command

Log_reuse_wait_desc showing as Availability_Replica

Recently in one my Always On Availability replica environment I got an issue where one of the availability replica database log file has grown completely, and we got a request to shrink the issue. When we run the below command we found that “log_reuse_wait_desc” showing as “Availability_Replica What this means is this indicates that the logged changes in the availability database at the primary replica that have not arrived and that these changes were applied to the availability database at one of the secondary replicas. Until logged changes arrive and are applied, the changes cannot be truncated from the availability database log at the primary replica. Troubleshooting: "Log Send Queue" and "Redo Queue" are measurable data points during availability database synchronization. You can monitor these data points in order to determine whether an availability database log cannot be truncated because of the log uses type AVAILABILITY_REPLICA. ·     Log Send...

Log Re usage Wait Desc showing as Availability_Replica

https://support.microsoft.com/en-us/help/2922898/error-9002-the-transaction-log-for-database-is-full-due-to-availabilit Log_re_usage_wait_desc showing as Availability_Replica

Getting mount points/drive/disk free space available information in PowerShell, Send-MailMessage

CLEAR # This will output specific details for mountpoints $TotalGB = @{Name = "Capacity(GB)" ;expression = { [ math ]:: round(( $_ . Capacity / 1073741824 ) , 2 )}} $FreeGB = @{Name = "FreeSpace(GB)" ;expression = { [ math ]:: round(( $_ . FreeSpace / 1073741824 ) , 2 )}} $FreePerc = @{Name = "Free(%)" ;expression = { [ math ]:: round(((( $_ . FreeSpace / 1073741824 ) / ( $_ . Capacity / 1073741824 )) * 100 ) , 0 )}} function get-mountpoints { $volumes = Get-WmiObject win32_volume -Filter "DriveType='3'" $volumes | Select Name , Label , DriveLetter , FileSystem , $TotalGB , $FreeGB , $FreePerc | Format-Table -AutoSize } get-mountpoints ------another query we can use the below one clear #servername $servers = @( "server1" , "server2" ) Get-WmiOBject ` -ComputerName $servers ` -Class Win32_Volume | Select-Object @{N = "Name" ;E ...

Getting Drive space information through PowerShell.

Invoke-Command ` -ComputerName "ServerName" ` {     Get-WMIObject   Win32_Logicaldisk |     Select-Object PSComputername , DeviceID , @{Name = "SizeGB" ;Expression = { $_ . Size / 1GB -as [ int ] }} ,     @{Name = "FreeGB" ;Expression = { [ math ]:: Round( $_ . Freespace / 1GB , 2 )}} } ` -Credential "UserNameHere"

Great article about CPU utilization

Image
https://blogs.msdn.microsoft.com/docast/2017/07/30/sql-high-cpu-troubleshooting-checklist/ https://blogs.msdn.microsoft.com/docast/2017/07/30/sql-high-cpu-troubleshooting-checklist/ WITH DB_CPU AS (SELECT DatabaseID,  DB_Name(DatabaseID)AS [DatabaseName],  SUM(total_worker_time)AS [CPU_Time(Ms)]  FROM sys.dm_exec_query_stats AS qs  CROSS APPLY(SELECT CONVERT(int, value)AS [DatabaseID]   FROM sys.dm_exec_plan_attributes(qs.plan_handle)   WHERE attribute =N'dbid')AS epa GROUP BY DatabaseID)  SELECT ROW_NUMBER()OVER(ORDER BY [CPU_Time(Ms)] DESC)AS [SNO],  DatabaseName AS [DBName], [CPU_Time(Ms)],  CAST([CPU_Time(Ms)] * 1.0 /SUM([CPU_Time(Ms)]) OVER()* 100.0 AS DECIMAL(5, 2))AS [CPUPercent]  FROM DB_CPU  WHERE DatabaseID > 4 -- system databases  AND DatabaseID <> 32767 -- ResourceDB  ORDER BY SNO OPTION(RECOMPILE); If you get a plan handle pass that plan handle to the ...