Showing posts with label SQL Server configuration. Show all posts
Showing posts with label SQL Server configuration. Show all posts

Wednesday, 3 May 2017

How to restore master database in Active Passive Cluster environment? or How to restore master database on a cluster instance?

Scenario- Today, One of my DBA friend faced this issue and as a friend he called me to take assistance.

In his production cluster environment. Unable to restart SQL Server Service manually because Master database was corrupted and client asked him to restore the DB without delay. Make everything online. 

He checked in Error log and found same issue.

Solution

1.            First you have to take SQL Server Service Offline from Cluster Admin

2.            Login to the active node of the cluster

3.            Go to the node running SQL Server and start it from the command prompt using below command and server name<INHYIZLP10722>:

 

C:\>sqlcmd -W -s , -S INHYIZLP10722

 

1.       Change the SQL Server Mode as Single User mode using below command-

 

1> sqlservr.exe -c -m

 

2.            Rebuild master database using below command( note – change/provide domain\username and password to run the SQL Server instance)

 

2> setup.exe /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLSYSADM
INACCOUNTS=Domain\Username /SAPWD=Passw$rdJai2212 /SQLCOLLATION=Latin_General_CI

_AS_KS




Snapshot of the Rebuild command prompt-


  OR  

Snapshot of the Restore command prompt-

  Restore master database using below command line


RESTORE DATABASE master FROM DISK = 'C:\BackupLocation\master.bck' WITH REPLACE;





3.            Once the master database is restored, the SQL Service will be shutdown automatically

4.            Now Start SQL Server Service from Cluster Admin.

5.            Now try to connect your User database from SSMS and ask end user to access the application/Database.


Please let me know if you know other method to perform same activity - Jainendra Verma

Tuesday, 2 May 2017

Step by Step Always On Availability Groups configuration in SQL Server 2012

Just  click on the below link to download PDF file which have complete configuration steps-


Step by Step Always On Availability Groups Setup in SQL Server 2012










.

Why Service Principal Name (SPN) need to configure for SQL Server? Unable to connect SQL Server due to SPN issue?

On servers without an SPN, we sometimes see the following kinds of intermittent connectivity errors:

“SSPI handshake failed with error code 0x80090311, state 14 while establishing a connection with integrated security; the connection has been closed. Reason: AcceptSecurityContext failed. The Windows error code indicates the cause of failure.”

Config Item
Default Value
Standard


SPN for SQL Servers running under domain accounts

Not created (because domain accounts lack permissions to create & register SPNs, by default)
All SQL servers running under a domain account must have an SPN created and registered in Active Directory, for the domain account under which the MsSQLserver service is running. 

What is SPN?

A service principal name (SPN) is the name by which a client uniquely identifies an instance of a service.  When a client wants to connect to a service, it locates an instance of the service, composes an SPN for that instance, connects to the service, and presents the SPN for the service to authenticate.   The benefit of having an SPN is that it allows the system to use Kerberos authentication along with NTLM.  In general, Kerberos(Kerberos is a network authentication protocol provides a highly secure method to authenticate client and server entities (security principals) on a network.) is known to perform better and is more secure than NTLM.


To reduce the possibility of network connectivity errors, all SQL servers running under a domain account must have an SPN created and registered in Active Directory, for the domain account under which the MsSQLserver service is running. 

How to create SPN ?

Window Server Team responsible to create it- 

·  To create an SPN for the NetBIOS name of the SQL Server use the following command: 

C:\> setspn –A MSSQLSvc/<SQL Server computer name or Virtual name of SQL Server>:1433 <Domain\Account>


·  To create an SPN for the FQDN of the SQL Server use the following command: 

  C:\> setspn -A MSSQLSvc/<SQL Server FQDN>:1433 <Domain\Account>

How to verify registered SPN ?

To view registered SPNs on a server for the domain account under which SQL Server is running, we can use the Setspn command as follows (the output below is the simplified output for just one named SQL instance your on server 


C:\> setspn -U -L Redmond\_backup

For more information about SPNs see the following links: MSDN important Links- 


Please comment below if know more about SPN - Jainendra Verma

Tuesday, 30 April 2013

Max degree of parallelism (MAXDOP) in SQL server 2000/2008/2008R2/2012/2014/2014/2017.

As an SQL Server DBA, recently, I have given interview and interviewer asked below questions in Bangalore(India).

  1. What is max degree of parallelism<MAXDOP> in SQL server 2000/2008/2008R2/2012/2014/2014/2017?
  2. When SQL Server considers parallel execution plans for queries?
  3. How to change max degree of parallelism in SQL server? 
  4. Who can change the max degree of parallelism in SQL server? 
  5. What permission required change max degree of parallelism in SQL server? 
  6. Where we can set of max degree of parallelism in SQL server? 
  7. What is the limitation of max degree of parallelism in SQL server?
  8. In which scenario, we need to use max degree of parallelism option in SQL server?
  9. Examples of max degree of parallelism?
What is max degree of parallelism<MAXDOP> in SQL server 2000/2008/2008R2/2012/2014/2014/2017?

A max degree of parallelism is a number of processor. which says, how many CPU or Microprocessor will use execution plan parallelly to execute the query.
When the SQL instance run the query in SSMS that use microprocessor or CPU to execute the query. At that time, CPU or microprocessor detect max degree of parallelism.

For example, if the max degree of parallelism value set as 4, and we are running any query, so the 4 CPU will parallel execute the execution plan of that query.


When SQL Server considers parallel execution plans for queries?

When run DBCC CHECKTABLE, DBCC CHECKDB, and DBCC CHECKFILEGROUP, index data definition language (DDL) operations, parallel insert, online alter column, parallel stats collection, and static and keyset-driven cursor population.


How to change max degree of parallelism in SQL server?

Right Click on SQL Server Instance à Properties à Advance à max degree of parallelism à change the value  à Ok.



OR

USE AdventureWorks2012 
GO  
EXEC sp_configure 'show advanced options', 1
GO 
RECONFIGURE WITH OVERRIDE; 
GO 
EXEC sp_configure 'max degree of parallelism', 4; 
GO 
RECONFIGURE WITH OVERRIDE; 
GO

Who can change the max degree of parallelism SQL server? What permission required change max degree of parallelism SQL server?

User should have sysadmin and serveradmin fixed server roles.

What is the limitation of max degree of parallelism SQL server?

If the affinity mask set as default (option is checked), it will not restrict the number of processors available to SQL Server on symmetric multiprocessing (SMP) systems.
If affinity mask not set as default (option is Unchecked) it will restrict the number of processors available to SQL Server on symmetric multiprocessing (SMP) systems.




Where we can set of max degree of parallelism in SQL server?

We can set it on instance level and object level. In below example, we have set on object level.

In which scenario, we need to use max degree of parallelism option in SQL server?

As per the number of query- 

If you have very small number of queries that are executing at the same time compared with the number of processors, you can set the MAXDOP value to a larger value.
For example, you can set the MAXDOP value to 16.  
If you a have very large number of queries that are executing at the same time compared with the number of processors, you can set the MAXDOP value to a smaller value.
For example, you can set the MAXDOP value to 4. 

As per the Microsoft Stranded- 

MaxDop setting will vary depending upon the number of CPU cores:

CPU Cores (Total)
MaxDop
1
1
2-7
2
8-16
4
>16
8

* Assuming mixed SQL workloads, involving both OLTP and reporting.
Note Any value that you consider using should be thoroughly tested against the specific application activity or pattern of queries before you implement that value on a production server.


Examples:-

To go the table à expend à Indexes à select Index à right click on select index à Properties à Option à change the value (default value is 0).


Example - MAXDOP for Create Index: -

USE AdventureWorks2012; 
GO 
CREATE INDEX IX_Product_NewID ON Product (ID)  WITH (MAXDOP=4); 
GO 

Example - MAXDOP for Rebuild Index: -


USE AdventureWorks2012; 
GO 
Alter INDEX IX_Product_NewID ON Product  REBUILD WITH (MAXDOP=4); 
GO 


Example - MAXDOP for select command: -

USE AdventureWorks2012; 
GO 
Select * from Product (nolock)  ORDER BY ProductID
OPTION (MAXDOP 1)


Note: - If the MAXDOP is set for the query and query execution time is more then check the execution plan of that query, in the plan you can see the parallelism cost in %, and then increase or decrease MAXDOP value. 



Please add if you have some interesting fact on MAXDOP - Jainendra Verma