Thursday, October 15, 2009

Shrink Log File

Just a few days back I received an issue regarding disk size is out of space. I have tried to shrink the database using DBCC ShrinkFile but there isn’t any success.

I have follow below steps to resolve this issue and it really works.

I have check the below query for

Select name,log_reuse_wait_desc from sys.databases

  1. There was another database which is waiting log backup to release the space

  2. There was one database who is waiting for Replication to release the space


Database who is waiting for log backup to release the log space

I have taken the log backup two times and executed the database shrink file command to release the space and it has reclaimed 40GB space from transaction log file.

Database who is waiting for Replication to release the log space

This database is in Simple recovery mode and there isn’t any replication enable on this. I have executed the DBCC OPENTRAN command to see any active transaction. I have executed the DBCC OpenTran and it has provided me the below result.

Oldest active transaction:

    SPID (server process ID): 101

    UID (user ID) : -1

    Name          : INSERT

    LSN           : (999:138204:2)

    Start time    : OCT  13 2009  1:34:47:827PM

    SID           : 0x88d52e4051a71143adee5dc7b6619f8a

Replicated Transaction Information:

        Oldest distributed LSN     : (890:2091888:1)

        Oldest non-distributed LSN : (896:2784855:1)

I don’t know the exact reason what happened internally. But from the output it seems that there is unmark distributed transaction. So I have executed Sp_Repldone command to unmark the LSN

 

EXEC sp_repldone @xactid = NULL, @xact_segno = NULL, @numtrans = 0,     @time = 0, @reset = 1

 Than I have executed the DBCC ShrinkFile command and it has reclaimed the 400GB space

Tuesday, October 13, 2009

An error has occurred while establishing a connection to the server

Problem:

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 28 - Server doesn't support requested protocol) (Microsoft SQL Server, Error: -1)

Resolution:

Check the below setting at Server Level
1. Check the firewall for any blocking (i.e TCP/IP Port:1433)
2. Check the SQL Server Instance Name, there may be chances of the spelling mistakes
3. May be remote connection is disable. Use the SAC (SQL Server Surface area configuration tool for remote connection)
4. Check the status of SQL Browser Service, it should be running to allow remote connectivity

Thursday, October 8, 2009

What are the features we can enable using Surface Area Configuration Tool?

SQL Server Security Interview Questions

During the interview I always like to ask below security questions to DBA. I found that sometimes DBAs are not able to answer these questions.

Question 1: What will you do if you lost rights of your SQL Server instance?

We can use the below options

  1. Dedicated Administrator Connection

  2. BUILIN\Administrator Group (Incase its rights are not revoked)

  3. Final Option is to change the registry value

  4. You can change authentication mode via registry 


Question 2: - What is SQL Injection?

SQL Injection is developed where unhandled\unexpected SQL commands are passed to SQL Server in a malicious manner.  It is a problem because unknowingly data can be stolen, deleted, updated, inserted or corrupted. 

Question 3: - What is the Guest user account in SQL Server?  What login is it mapped to it?   

The Guest user account is created by default in all databases and is used when explicit permissions are not granted to access an object.  It is not mapped directly to any login, but can be used by any login.  Depending on your security needs, it may make sense to drop the Guest user account, in all databases except Master and TempDB 

Question 4: – What is the use of BUILTIN\Administrators Group in SQL Server?

Any Windows login in BUILTIN\Administrators group is by default a SQL Server system administrator. This single group can be used to manage administrators from a Windows and SQL Server perspective

How to change Min/Max Memory in SQL Server?

Step 1: Open SSMS

Step 2: Connect to desire Server and right click on the server (for i.e. sqldbpool) and Select properties

Memory1 

Step 3: Click on memory tab and configure Min and Max memory

Memory2

Wednesday, October 7, 2009

SQL Server 2008 Active-Passive/Active-Active Cluster Installation

Like SQL Server 2005, SQL Server 2008 supports clustering using both the Standard and Enterprise editions. The Standard edition supports a two-node cluster, and the Enterprise edition supports the maximum number of nodes that the OS supports 

The biggest changes in SQL Server 2008 cluster is that you can now use DHCP for clustering and use IP addresses from different subnets for each side of the cluster. The ability to use IP addresses from different subnets is most useful for creating multisite clusters, called geographically distributed clusters.

SQL Server Cluster Installation

Step 1: I hope you had done with all the pre-requisites required by cluster.If you're installing SQL Server 2008 in a cluster on Windows 2003, you'll need to download and install the hotfix specified in the Microsoft article at http://support.microsoft.com/kb/937444  before you can install SQL Server 2008.

Note: Installation of above hotfix requires a reboot, so you have to cancel out of the installer at this point and restart the process after installing that hotfix on all your cluster nodes.

Step 2: Open SQL Server 2008 installation executable file from your CD\DVD\Shared location

Double click on installation.exe and you will find the below screen. Now select New SQL Server Failover Cluster installation option highlighted as in below image. (Note: For standalone installation we have to select standalone option)

Step1

Step 3: Once you have selected Step 2 option, installation will check for setup support rules to identify the problem. If it is failed due to any reason, you have to correct the issue. Please find the below screen shot. If it passed click on OK command button.

Step2

Step 4: Installation wizard will install the setup support files, click on Install command button

Step3

Step 5: This step will walk you through all the required information as below. Click on Next button

1. Product Key

2. Licence Terms

3. Feature Selection

4. Disk Space Reuirements

5. Error and Usage Reporting

6. Cluster instllation Rules

7. Ready to install

8. Installation Progress

Step4

Step 6: Enter Product Key or It will take automatically. See the below image for it.

Step5

Step 7: Select required features, which you want install.

Step6

Step 8: Specify the Network Name/Virtual Name for SQL Server to failover. As we are installing Active-Passive cluster we have to specify one virtual/network name. (Note: For Active-Active clustering you have specify different network names as per the number of nodes)

Step7

Step 9: SQL Server will review the disk space requirement for the features you have selected

Step8

Step 10: This step will create a new cluster resource group for your SQL server failover. Please see the note in the image.

Step9

Step 11: Select shared cluster disk resources for your SQL Server failover cluster

Step10

Step 12: Here you have to select network resources for your SQL Server failover cluster. You have to add IP address as well.

Step11

Step 13: Here you have to specify the service account for SQL Server services. It is a best practice always keeps SQL Services in cluster in manual mode

Step12

Step 14: Specify the authentication more and SA password in account provisioning tab, configure the location of the data files, log files, temp database in data directories tab and enable file stream as per the requirement

Step13

Step 15 

Step 14: Specify the authentication more and SA password in account provisioning tab, configure the location of the data files, log files, temp database in data directories tab and enable file stream as per the requirement

Step13

Step14

Step 15: Select check boxes as per your requirement, I haven't checked any option. Proceed with the next button

Step15

Step 16: Installation wizard will check the cluster installation rules, please correct if you found any failure and proceed with the next button

Step16

Step 17: Now your SQL Server cluster is ready to install. Click on Install button

Step17

Step 18: Apply the required Service Pack/Patch and reboot the server

Step 19: Once installation is done on this node, we have to proceed with the installation of SQL Server on the other cluster nodes. SQL Server 2005 was the last edition of SQL Server to automatically install SQL Server on all nodes at once.  Beginning with SQL Server 2008, we must manually install and patch each cluster node individually. This process allows for less downtime as we are patching the cluster or upgrading your cluster from SQL Server 2005 to SQL Server 2008.

Step 20 Installation on the other nodes is similar to installing on the first node except that we have select the Add Node to a SQL Server failover cluster option from the initial menu. The same software requirements apply to the other nodes in the cluster, so the installer will handle the verification and installation of these components as well.

Because most of the settings are picked up from the other node(s) in the cluster that already have SQL Server installed on them, the process of adding a node to the cluster is bit shorter than installing on the first node 

Step 20 Installation on the other nodes is similar to installing on the first node except that we have select the Add Node to a SQL Server failover cluster option from the initial menu. The same software requirements apply to the other nodes in the cluster, so the installer will handle the verification and installation of these components as well.


Because most of the settings are picked up from the other node(s) in the cluster that already have SQL Server installed on them, the process of adding a node to the cluster is bit shorter than installing on the first node

Step18

Monday, October 5, 2009

How to move Cluster Resource/Services to proper node using command prompt?

cluster group "SQL Server Group" /move: Physical_Name_Of_Node1

cluster group "SQL Server Group INST2" /move: Physical_Name_Of_Node2

How to check cluster resources are running on proper node using command prompt?

cluster clusterName resource >> clusterResourcestatus.txt

Note: Text highlighted in Blue color is command or parameter you can execute.

Login Issue

Recently I received below error while executing XP_ReadErrorlog command from SSMS.

Msg 22004, Level 16, State 1, Line 0

Failed to open loopback connection. Please see event log for more information.

Msg 22004, Level 16, State 1, Line error log location not found 

As per the above error message I have checked event viewer log and got the below information from event viewer log. 

The description for Event ID ( 17052 ) in Source ( MSSQLSERVER ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Severity: 16 Error:18456, OS: 18456 [Microsoft][SQL Native Client][SQL Server]Login failed for user 'domain\service-sql'..

I have opened error log file from log directory and observed the number of login service-sql with the state 11. 

2009-09-30 22:45:31.69 Logon       Login failed for user 'domain\service-sql'. [CLIENT: 10.10.10.10]

2009-09-30 22:45:34.26 Logon       Error: 18456, Severity: 14, State: 11.

Service-SQL account has sysAdmin rights on SQL Server and it is added through SQL Server Service – Production AD group. I can see this AD group has SysAdmin rights on SQL Server. 

Resolution: Remove account from local administrator group and from SQL Server Logins. Add account again with the same privileges in local administrator group and SQL Server logins.