Wednesday 16 November 2011

TCP Transport level errors - Can be caused by TCP Chimney offload

You may sometimes get TCP Transport errors on an application server or client server trying to connect to your SQL server if TCP Chimney offload is enabled on either the SQL Server or the Client Server/Workstation. This is because this setting can impact performance and concurancy on SQL Server workloads.

For this reason I personnaly always disable this setting on my SQL Servers. This needs to be done at the operating system level and in the NIC Card Properties if the NIC support Chimney offload.

TCP Chimney offload very basically offloads TCP processing from the Processor to a NIC Card that Supports Chimney offload. See Technet article: http://technet.microsoft.com/en-us/library/gg162709%28WS.10%29.aspx

The following steps show how to disable TCP Chimney Offload. By default Server2008r2 has the setting as automatic on a global level.

Operating System for Server2008/2008r2:

1.)    Open a command prompt with elevated privileges
2.)    Run the following command to check the setting: netsh int tcp show global  (If Chimney is set to automatic or enabled go to next step)

 3.)    Run the following command to disabled TCP Chimney offload: netsh int tcp set global chimney=disabled



4.)    Run the netsh int tcp show global command again to confirm changed.


Operating System for Server 2003 SP2 or above:

1.)    Click Start, click Run, type regedit, and then click OK.
2.)    Locate the following registry subkey:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
3.)    Right-click EnableTCPChimney, and then click Modify.
4.)    In the Value data box, type 0, and then click OK.
5.)    Right-click EnableRSS, and then click Modify.
6.)    In the Value data box, type 0, and then click OK.
7.)    Right-click EnableTCPA, and then click Modify.
8.)    In the Value data box, type 0, and then click OK.
9.)    Exit Registry Editor, and then restart the computer.

Disable TCP Chimney offload in NIC Adaptor:

1.)    Open the NIC Adapter Settings.
2.)    Click Properties
3.)    Click Configure
4.)    Click Advanced Tab
5.)    Find Offload TCP settings and set to disabled.

Monday 14 November 2011

Lock Pages In Memory SQL 2005/2008 Standard on 64bit

When you grant the SQL Server Service Account the ability to 'Lock Pages in Memory' with SQL 2005/2008 Standard on 64bit systems you need to enable a Trace Flag in the Startup Parameter for the SQL Service:

"Lock pages in memory" comes as a trace flag that can be enabled on the following cumulative updates:
CU2 for SQL Server 2008 SP1 =>
http://support.microsoft.com/kb/970315/en-us
CU4 for SQL Server 2005 SP3 => http://support.microsoft.com/kb/970279/en-us

I will not explain here how to Enable the 'Lock Pages In Memory' at the Windows level as there are plenty of Blogs on how to do this: See MSDN article http://msdn.microsoft.com/en-us/library/ms190730.aspx

To add the Trace Flag to the Startup Parameter of your SQL Server Service, follow these steps:
  1. Open Configuration Manager for SQL Server.
  2. Browse to the SQL Server Service, Right Click and Select Properties.
  3. Click on the Advanced Tab.
  4. Select Startup Parameters and add the Trace Flag -T845. It should look something like this: -dG:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\master.mdf;-eE:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG;-lH:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\mastlog.ldf;-T845 Obviously your file locations will be different and you may already have other Global Trace Flags set up.... If you do have another Trace Flag just add a ; after your existing Trace Flag and add the new -T845 after this.
  5. Once the Trace Flag has been added to the Startup Parameter you will need to restart the service for the change to be applied.
If you need to apply this change temporarily for all sessions you can use the DBCC TRACEON command.


DBCC TRACEON(845, -1)
GO

To check the status of any Trace Flags running on your server, run the following DBCC Command:


DBCC TRACESTATUS

Wednesday 9 November 2011

Listing Indexes and Columns From A Database

Script written by Giuseppe Dimauro.
Taken from the following link:



declare @empty varchar(1)
select @empty = ''

-- 35 is the length of the name field of the master.dbo.spt_values table
declare    @IgnoreDuplicateKeys varchar(35),
@Unique varchar(35),
@IgnoreDuplicateRows varchar(35),
@Clustered varchar(35),
@Hypotethical varchar(35),
@Statistics varchar(35),
@PrimaryKey varchar(35),
@UniqueKey varchar(35),
@AutoCreate varchar(35),
@StatsNoRecompute varchar(35)

select    @IgnoreDuplicateKeys = name
from    master.dbo.spt_values
where    type = 'I' and number = 1 --ignore duplicate keys

select    @Unique = name
from    master.dbo.spt_values
where    type = 'I' and number = 2 --unique

select    @IgnoreDuplicateRows = name
from    master.dbo.spt_values
where    type = 'I' and number = 4 --ignore duplicate rows

select    @Clustered = name
from    master.dbo.spt_values
where    type = 'I' and number = 16 --clustered

select    @Hypotethical = name
from    master.dbo.spt_values
where    type = 'I' and number = 32 --hypotethical

select    @Statistics = name
from    master.dbo.spt_values
where    type = 'I' and number = 64 --statistics

select    @PrimaryKey = name
from    master.dbo.spt_values
where    type = 'I' and number = 2048 --primary key

select    @UniqueKey = name
from    master.dbo.spt_values
where    type = 'I' and number = 4096 --unique key

select    @AutoCreate = name
from    master.dbo.spt_values
where    type = 'I' and number = 8388608 --auto create

select    @StatsNoRecompute = name
from    master.dbo.spt_values
where    type = 'I' and number = 16777216 --stats no recompute

select    o.name,
i.name,
'index description' = convert(varchar(210), --bits 16 off, 1, 2, 16777216 on
case
when (i.status & 16)<>0 then @Clustered
else 'non'+@Clustered
end +
case
when (i.status & 1) <> 0 then ', '+ @IgnoreDuplicateKeys
else @empty
end +
case
when (i.status & 2) <> 0 then ', ' + @Unique
else @empty
end +
case
when (i.status & 4) <> 0 then ', ' + @IgnoreDuplicateRows
else @empty
end +
case
when (i.status & 64) <> 0 then ', ' + @Statistics
else case
when (i.status & 32) <> 0 then ', ' + @Hypotethical
else @empty
end
end +
case
when (i.status & 2048) <> 0 then ', ' + @PrimaryKey
else @empty
end +
case
when (i.status & 4096) <> 0 then ', ' + @UniqueKey
else @empty
end +
case
when (i.status & 8388608) <> 0 then ', ' + @AutoCreate
else @empty
end +
case
when (i.status & 16777216) <> 0 then ', ' + @StatsNoRecompute
else @empty
end),
'index column 1' = index_col(o.name,indid, 1),
'index column 2' = index_col(o.name,indid, 2),
'index column 3' = index_col(o.name,indid, 3),
'index column 4' = index_col(o.name,indid, 4)
--'index column 5' = index_col(o.name,indid, 5),
--'index column 6' = index_col(o.name,indid, 6),
--'index column 7' = index_col(o.name,indid, 7),
--'index column 9' = index_col(o.name,indid, 9),
--'index column 10' = index_col(o.name,indid, 10),
--'index column 11' = index_col(o.name,indid, 11),
--'index column 12' = index_col(o.name,indid, 12),
--'index column 13' = index_col(o.name,indid, 13),
--'index column 14' = index_col(o.name,indid, 14),
--'index column 15' = index_col(o.name,indid, 15),
--'index column 16' = index_col(o.name,indid, 16),
--'index column 17' = index_col(o.name,indid, 17),
--'index column 18' = index_col(o.name,indid, 18),
--'index column 19' = index_col(o.name,indid, 19),
--'index column 20' = index_col(o.name,indid, 20)
from    sysindexes i, sysobjects o
where    i.id = o.id
and        indid > 0
and        indid < 255 --all the clustered (=1), non clusterd (>1 and <251), and text or image (=255)
and        o.type = 'U' --user table
--ignore the indexes for the autostat
and        (i.status & 64) = 0 --index with duplicates
and        (i.status & 8388608) = 0 --auto created index
and        (i.status & 16777216)= 0 --stats no recompute
order by
1
,2
,3
,4
--,5
--,6
--,7
--,8
--,9
--,10
--,11
--,12
--,13
--,14
--,15
--,16
--,17
--,18
--,19
--,20