Thursday 7 November 2013

How can I Increase the Number of SQL Server Error Logs

How can I Increase the Number of SQL Server Error Logs
Problem

By default, there are six achieved SQL Server Error Logs along with the ERRORLOG which is currently used. However, it is a Best Practice to increase the number of SQL Server Error Logs from the default value of six.

Solution

A new error log is created when an instance of SQL Server is restarted. Also database administrators can run the command sp_cycle_errorlog system stored procedure to cycle the error log without recycling the instance of SQL Server. The most recent error log backup will have a name ERRORLOG.1, the second most recent error log backup will have the name as ERRORLOG.2 and the current error log will have the name ERRORLOG.
It is a BEST PRACTICE to increase the SQL Server Error Log from the default value of 6, because the error logs may contain critical information about your database server. As mentioned, by default there will be 7 error log files that exist, 6 archives and the current one.  When a new error log is created the oldest archive gets removed and that data is then lost forever.  So if you are trying to troubleshoot a system problem and are doing several restarts of SQL Server you may end up replacing all of your archives and then lose this valuable information in the error logs.


With help of below Steps we can Increase the Number of SQL Server Error Logs in SQL Server 2008 / 2005: 

1. Connect to SQL Server 2008 or SQL Server 2005 Instance using SQL Server Management Studio
2. In the Object Explorer, Click on "Management" and expand "SQL Server Logs"
3. Right click SQL Server Logs and click on "Configure" option from the drop down list as shown in the below snippet.

4. This will open up Configure SQL Server Error Logs window as shown in the below snippet. Here, for Maximum number of error logs option you can specify a value between 6 and 99. In this example, I have changed the value from the default value of 6 to 10.


5. Once you have specified the new value for Maximum number of error log files click OK to save the changes.
As SQL Server Database Engine is not restarted frequently in a production environment, it will be a good practice for a DBA to schedule a SQL Server Agent Job which runs once in a day to execute either DBCC ERRORLOG or sp_cycle_errorlog system stored procedure to create a new SQL Server Error Log. It becomes easier to open up SQL Server Error Log file when it is small in size.
With help of the below command we can recycle the sql server agent error log also.
EXEC msdb.dbo.sp_cycle_agent_errorlog

Happy Learning 

Wednesday 6 November 2013

How to find the location of the sql server error log...

How to find the location of the sql server error log

Steps to find the location of the sql server log:

1)Click on start button and click on all programs and select the Microsoft Sql server 2008 -à configuration Tools --à SQL Server configuration Manager.

 2)Select the Sql server services and then right click on SQL Server(MSSQL) and select the properties tab.

 3)Go to Advanced tag and select the Startup parameters. In this option select the drop down button. In this box after the “-e” is the location of the sql server error log. Please check the below SH.


      4)If you want to change the location of the sql server error log, you can change it here. Just past the new location after –e. and don’t forget to put the \errorlog after pasting the new location.

5)After this one you need to restart the sql services to take the effect of the new location. Same like this process you can change the master database file locations. But here small change i.e after changing the location at startup parameters you need to stop the sql server services and past the master database mdf and ldf files from old location to new location and then start the sql server services.


Happy Learning :)


Tuesday 29 October 2013

About Quorum


About Quorum

In short quorum is minimum number of votes required for majority. the nodes participating in the windows cluster are connected through a private network and communicate through User Datagram Protocol (UDP) port 3343.The quorum configuration in a failover cluster determines the number of failures (failure of nodes) that the cluster can sustain while still remain online. If additional failure happened beyond this threshold, the cluster will stop running.Quorum is designed to handle the Split Brain scenario. When nodes are unable to communicate each other, each node assume that, resource groups owned by other nodes have to brought online. When same resource brought online on multiple nodes at the same time,data corruption can occur. This scenario is called Split Brain.

Quorum role in cluster

When both nodes of a cluster are up and running, participating in their relevant roles (active and passive) they communicate with each other over the network. For example, if you change a configuration setting on the active node, this configuration change is automatically sent to the passive node and the same change made. This generally occurs very quickly, and ensures that both nodes are synchronized.

But, as you might imagine, it is possible that you could make a change on the active node, but before the change is sent over the network and the same change made on the passive node (which will become the active node after the failover), that the active node fails, and the change never gets to the passive node. Depending on the nature of the change, this could cause problems, even causing both nodes of the cluster to fail.

To prevent this from happening, a SQL Server 2005 cluster uses what is called a quorum, which is stored on the quorum drive of the shared array. A quorum is essentially a log file, similar in concept to database logs. Its purpose is to record any change made on the active node, and should any change recorded here not get to the passive node because the active node has failed and cannot send the change to the passive node over the network, then the passive node, when it becomes the active node, can read the quorum file and find out what the change was, and then make the change before it becomes the new active node.

In order for this to work, the quorum file must reside on what is called the quorum drive. A quorum drive is a logical drive on the shared array devoted to the function of storing the quorum.
Quorum models

Windows 2008 cluster supports four quorum models.

1 Node Majority 

2 Node and Disk Majority 

3 Node and File Share Majority

4 No Majority (disk only)


Node Majority: Node majority option is recommended for cluster with odd number of nodes.This configuration can handle a loss of half of the number of cluster nodes rounded off downwards. For example , a five node cluster can handle failure of two nodes. In this scenario three of the nodes (N1,N2,N3) can communicate each other but other two(N4 and N5) are not able to communicate. The group constituted by three node have the quorum (majority) and cluster will remain active and cluster service will be stopped on the other two nodes (N4 and N5). The resource group (sql server instance) hosted on that two nodes goes offline and come online on one of the three nodes based on possible owner settings.


Node and Disk Majority: This option is recommended for cluster with even number of nodes.In this configuration every node gets one vote and witness disk (quorum disk) gets one vote which makes total votes a odd number. The witness disk is a small ( approx 1 GB ) clustered disk.This disk is highly available and can failover between nodes. It is considered as part of the cluster core resource group.In a four node cluster, if there is a partition between two subsets of nodes, one of the subset will have witness disk and that subset will have quorum and cluster will remain online. This means that the cluster can lose any two voters,whether they are two nodes or one node and the witness disk.


Node and File Share Majority: This configuration is similar to the the Node and Disk Majority, but in this case the witness disk is replaced with a file share which is also known as File Share Witness Resource (FSW). This quorum configuration usually used in multi-site clusters (nodes are in different physical location) or where there is no common storage. The File Share Witness resource is a file share in any server in the same active directory which all the cluster nodes have access to. One of the node in the cluster will place a lock on the the file share to consider that node as owner of the file share.When this node goes offline or lost the connectivity another node grabs the lock and own the file share.On a standalone sever, the file share is not highly available , however the file share can also put on a clustered file share on an independent cluster,making the FSW clustered and giving it the ability to fail over between node. It is important that, this file share should not put in a node of the same cluster, because losing that node would cause for loosing two votes. A FSW does not store cluster configuration data like witness disk. It contain information about which version of the cluster configuration database is most recent.


No Majority (Disk only) : This configuration was available in windows server 2003 and has been maintained for compatibility reason and it is highly recommended not to use this configuration. In this configuration,only witness disk has a vote and there are no other voters in the cluster. That means if all nodes are online and able to communicate , but when witness disk failed or corrupted, the entire cluster will go offline.This is considered as single point of failure.

Monday 3 June 2013

Finding the active trace flags in Microsoft sql server
With help of below command we can find the active trace flags on Microsoft sql server instance.
DBCC TRACESTATUS
The output of the command is:
TraceFlag   Status Global Session
------------  -------- ----------  ----------
4199             1           1              0
4616             1              1              0
(2 row(s) affected )
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
If there are no active trace flags, we will get the output like:
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Enable session based trace flags
To enable trace flags only in your session use the following two commands.
DBCC TRACEON (trace#)
DBCC TRACEOFF (trace#)
Enable the trace flags globally:
With help of below command we can enable the trace flags globally…
DBCC TRACEON (trace#, -1)
DBCC TRACEOFF (trace#, -1)

Enable Multiple Trace at same time separating each trace with a comma.
DBCC TRACEON(1205,2528)


Disable Multiple Trace at same time separating each trace with a comma.
DBCC TRACEOFF(1205,2528)

To enable a trace flag to persist through a restart. Alter the “Startup Parameters” in the Advanced tab for the SQL Server service in SQL Server Configuration Manager.
For Example: Before Modification
-dc: \Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\log\ERRORLOG;
-lC:Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\mastlog.ldf
After Modification:
-dc: \Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\log\ERRORLOG;
-lC:Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\mastlog.ldf;-T4199

Available trace flages in sql server...


Sunday 21 April 2013

Moving System Databases files

Moving System Databases files from old location to new location
Some times after instalation of the sql server, we need to change the system databases file locations. the below process guide us to change the system databases files locations from old to new.
Moving the  Tempdb,Msdb and Model database files from old to new location:
with help of the below command we can move the system databases files from old to new locations logically (not physically).

USE master;
GO
alter database tempdb MODIFY FILE (NAME = tempdev,FILENAME='NEW PATH');
GO
alter database tempdb MODIFY FILE (NAME = templog,FILENAME='NEW PATH');
GO

USE master;
GO
alter database msdb MODIFY FILE (NAME = MSDBData,FILENAME='NEW PATH');
go
alter database msdb MODIFY FILE (NAME = MSDBLog,FILENAME='NEW PATH');
go

USE master;
GO
alter database model MODIFY FILE (NAME = modeldev,FILENAME='NEW PATH');
go
alter database model MODIFY FILE (NAME = modellog,FILENAME='NEW PATH');
go


  1. Now stop the sql server services to move the system databases files from old to new locations physically. 
  2. after moving the system databases files physically, start the sql server services and with help of below command we can confirm the databases new location.

  3. USE msdb;
    SELECT physical_name from sys.database_files
    USE model;
    SELECT physical_name from sys.database_files
 Note: no need to move the tempdb files physically, because it's recrate always when sql services are start.
 Moving the Master and Resources database files:
 Edit the startup parameters to reflect the new path for –d(datafile), –l(logfile) and -e(sql log file) parameters.

go to start ----> all programs ----> Micro soft sql server 2005 ----> configuration tool ----> sql server configuration manager 

 After this we need to follow the below steps for sql server 2005, why because the resource database is depended on master database. so, we need to put the resource database files at master database files location.

Note: above sql server 2005 version no need to follow the below steps. just restart the sql services. because the resources database is independent.
  1. Stop the services.
  2. Move the master and resource database files to the new location
  3. Start the services using NET START MSSQLSERVER /f /T3608 (*MSSQLSERVER is for default instance, if you have installed named instance then you need to use NET START MSSQL$Instancename /f /T3608)

 open the new query window and run the below command.(don't open the sql instance in management console). other wise run the below command in sqlcmd.
USE master;
GO
alter database mssqlsystemresource MODIFY FILE (NAME = data,FILENAME='NEW PATH\mssqlsystemresource.mdf');
go
alter database mssqlsystemresource MODIFY FILE (NAME = log,FILENAME='NEW PATH\mssqlsystemresource.ldf');
go
alter database mssqlsystemresource set READ_ONLY;
go

 stop and start the sql server services and confirm the new locations.

Note: Please post your comments...

Happy Learning
























How to stop and start the sql server services.

we have 4 ways to stop and start the sql server services.
1) services.msc
2) Management studio
3) Command prompt
4) Configuration Manager

Services.msc:
  with help of following steps we can stop and stat the sql server services.
1) Go to run
2) Type services.msc and press enter.
3) select the sql database engine services and then right click on service.
4) click on the stop button.

Note : The sql agent is dependent on the sql database engine services. so, when we stop the sql database engine services the agent services stop automatically. But when you start the sql database engine service the agent service doesn't start automatically. we need to start the agent services manually.
Start the sql server services:
1) 1) Go to run
2) Type services.msc and press enter.
3) select the sql database engine services and then right click on service.
4) press on the start button.
5) select the sql agent service and right click on the service.
6) press on the start button.

Through Management studio:
 with help of the following steps we can stop and start the sql services through Management studio.
1) Open the Management studio.
2) Connect to the sql instance, which we want to stop.
3) right click on the instance name and select the stop button.
Note: Once we closed the Management studio after stop the sql server services, it is not possible to start the sql server services through Management studio. we need to follow the other process to strat the sql server services.
Command Prompt :
1) Open the run and type cmd and press ok button.
2) type below command on cmd and press enter.
net stop mssqlserver --- ( for default instance)
net stop mssql$instancename ---- ( for named instance )
3) type the below command for start the sql server service.
net start mssqlserver ---- ( for default instance )
net start mssql$instancename ---- ( for named instance )
Configuration Manager :
1) Go to start and select all programs and then select Microsoft sql server under this one select the configuration tools and then select the sql server configuration manager.
2) select sql server service on left side panel like on above screen shot. and then select the sql server instance name which you want to stop the services. and right click and select stop button to stop the sql database engine services.

3) same process to start the sql server services.

Note: Please post your comments...

Happy Learning

Tuesday 16 April 2013

Configure the Master target server or multi server environment


Configure the Master target server or multi server environment:
Multi server administration requires that you set up a master server and one or more target servers. Jobs that will be processed on all the target servers are first defined on the master server and then downloaded to the target servers.
Automating administration across multiple instances of SQL Server is called multi server administration. Use multi server administration to do the following:
·         Manage two or more servers.
·         Schedule information flows between enterprise servers for data warehousing.
To take advantage of multi server administration, you must have at least one master server and at least one target server. A master server distributes jobs to, and receives events from, target servers. A master server also stores the central copy of job definitions for jobs that are run on target servers. Target servers connect periodically to the master server to update their schedule of jobs. If a new job exists on the master server, the target server downloads the job. After the target server completes the job, it reconnects to the master server and reports the status of the job. The following illustration shows the relationship between master and target servers:



If you administer departmental servers across a large corporation, you can define the following:
·         One backup job with job steps.
·         Operators to notify in case of backup failure.
·         An execution schedule for the backup job.
Write this backup job one time on the master server and then enlist each departmental server as a target server. From the time of their enlistment, all the departmental servers run the same backup job, yet you defined the job only once.
NOTE:  Multiserver administration features are intended for members of the sysadmin role. However, a member of the sysadmin role on the target server cannot edit the operations that are performed on the target server by the master server. This security measure prevents job steps from being accidentally deleted and operations on the target server from being interrupted.

Configure the Master target server
Here’s a basic look at how to setup Multi Server Administration. First thing I’m going to do is register both servers in SQL Server Management Studio (SSMS). If you do not see the Registered Servers tab in SSMS navigate to 'View' | 'Registered Servers' or press 'Ctrl + Alt + G'.
Once both servers are registered I can start configuring Multi Server Administration. To do this right click on 'SQL Server Agent' on your master server and choose 'Multi Server Administration' | 'Make this a Master…' to begin the process.


Click Next on the Welcome for the Master Server Wizard.
The next screen is where we can configure an operator. Just like when we create an operator for local jobs, we can create one for our Multi Server jobs. You can also leave this section blank if you prefer not to have an operator although I would not recommended this practice.  Once completed, press the 'Next' button to continue.


On the Target Servers screen is where we specify our target servers. You can have multiple targets, but for this example I’m only using one.  You can select target servers using your 'Registered Servers' from your SSMS session or you can add a connection by clicking the 'Add Connection...' button.  I’m going to select Mirror as my target and click the 'Next' button to continue the process.


Next, SQL Server will check that the versions of the master and target server are compatible as shown on the screen shot below.
On the Master Server Login Credentials screen security is checked between the master and target servers. If needed, the check box can be selected to create a login and assign it rights to the master server. Click the 'Next' button to continue the process.
Once you click the 'Finish' button on the Complete the Wizard screen it will start the configuring the servers.
Be aware that a common problem exists during configuration and the following error (The enlist operation failed (reason: SQLServerAgent Error: The target server cannot establish an encrypted connection to the master server 'Server Name'.  Make sure that the MsxEncryptChannelOptions registry subkey is set correctly on the target server.)  (Microsoft SQL Server Error: 22026)) may be thrown as shown on the screen shot below:
As the error indicates, we need to make a registry change on the target server. To accomplish this, logon to the target server and navigate to 'Start' | 'Run' | type 'Regedit'. As a best practice, be sure to backup your registry before making changes.  From the Registry Editor browse to 'HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\<Your instance>\SQLServerAgent and change the MsxEncryptChannelOptions' value to '0'. Save the change and close the Registry editor. 
Once this is complete, run the wizard from the master server again and it should finish successfully as shown below.
To verify everything was configured correctly, connect to both servers and beside SQL Server Agent it should have either '(MSX)' or 'TSX:<master server>' as shown below.

To set up a Multi Server Job under SQL Server Agent you must connect to the master server in SSMS and navigate to 'SQL Server Agent' | 'Jobs' | 'Multi-Server Jobs". Configure the job as needed and on the 'Targets tab' select the target servers you want this job to execute on.

Once finished, click the 'OK' button to save job to both servers.
The same general process applies to Maintenance Plans, connect to the master server and navigate to 'Management' | 'Maintenance Plans' | right click and choose 'New Maintenance Plan…'.  This process starts by naming the job as shown below.
Configure the Maintenance Plan as needed and on the Servers button select the servers you want this Maintenance Plan to execute on.
Once finished, click 'Save and Close' to save both Maintenance Plans to both servers as shown below.
1.       In Object Explorer, connect to an instance of the Microsoft SQL Server Database Engine, and then expand that instance.
2.       Right-click SQL Server Agent, point to Multi Server Administration, and then click Make this a Target. The Target Server Wizard guides you through the process of making a target server.
1.       In Object Explorer, expand a server that is configured as a master server.
2.       Right-click SQL Server Agent, point to Multi Server Administration, and then click Add Target Servers.
3.       Complete the Target Server Wizard, which guides you through the process.
1.       In Object Explorer, expand a server that is configured as a target server.
2.       Right-click SQL Server Agent, point to Multi Server Administration, and then click Defect.
3.       Click Yes to confirm that you want to defect this target server from a master server.
1.       In Object Explorer, expand a server that is configured as a master server.
2.       Right-click SQL Server Agent, point to Multi Server Administration, and then click Manage Target Servers.
3.       Click Post Instructions, and then in the Instruction type list, select Defect.
4.       Under Recipients, do one of the following:
·         Click All target servers to defect all target servers of this master server. Use this option if you want to completely uninstall the current multiserver administration configuration.
·         Click These target servers, and then click the corresponding Select box, to defect some, but not all, target servers of this master server.
Distributed jobs that have steps which are associated with a proxy run under the context of the proxy account on the target server. Make sure that the following conditions are met or job steps that are associated with a proxy will not be downloaded from the master server to the target:
·         The master server registry sub key \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\<instance_name>\SQL Server Agent\AllowDownloadedJobsToMatchProxyName (REG_DWORD) is set to 1 (true). By default, this sub key is set to 0 (false).
·         A proxy account exists on the target server that has the same name as the master server proxy account under which the job step runs.
If job steps that use proxy accounts fail when downloading them from the master server to the target server, you can check the error message column in the sysdownloadlist table in the msdb database for the following error messages:
·         "The job step requires a proxy account; however proxy matching is disabled on the target server."
To resolve this error, set the
AllowDownloadedJobsToMatchProxyName registry sub key to 1.
·         "Proxy not found."
To resolve this error, make sure a proxy account exists on the target server that has the same name as the master server proxy account under which the job step runs.
Secure Sockets Layer (SSL)
Full Secure Sockets Layer (SSL) encryption and certificate validation are enabled for connections between master servers and target servers by default.
The wizard takes you through the following steps:
·         Checking the security settings for the SQL Server Agent service and the SQL Server service on all servers intended to become target servers.
We recommend that both services should be running in Microsoft Windows domain accounts.
·         Creating a master server operator (MSXOperator) on the master server.
MSXOperator is the only operator that can receive notifications for multiserver jobs.
·         Starting the SQL Server Agent service on the master server.
·         Enlisting one or more servers as target servers.
If you have a large number of target servers, avoid defining your master server on a production server. Otherwise, target server traffic can slow performance on your production server. If you also forward events to a dedicated master server, you can centralize administration on one server.
Note: I collected the above information from different links. If you have any doubts on the above topic, please feel free to post the question, i will try to get the answer for your question.
HAPPY LEARNING