Thursday, September 20, 2012

Set based Windows function should remove the need of cursors completly

Today I was refreshing myself with the new Windows functions availaible in SQL Server 2012. It all started with back in windows server 2005, when we saw lot of usage of CTE,OVER(), RANK,DENSE_RANK etc to support lot of complex queries into simple code.

With SQL Server 2012, this list has extended with extended support over clause, FRAME, LEAD,LAG,FIRST_VALUE,LAST_VALUE,PERCENT_RANK,PERCENTILE_DISC etc

As a developer, you should leverage more of these set based functions and as a DBA, when reviewing code, make sure you see usage of these functions more :)

Thursday, May 10, 2012

Effect of Transactional Replication on your Publisher database!

This is one of the other similar things, which you can only tell once you have performed some kind of test.

Have you ever wondered, If transactional replication has any overhead on your Production database? and if yes, then how much really?

As transactional replication relies on reading and writing transactional logs, The answer is "YES" :)

You will notice degrade in your write performance if you have transactional replication configured!

In a scenario, where you are hosting distribution database on the separate server, I have seen write performance going bad by even 30% !! Consider a scenario, where you are inserting 100 of thousands of rows as a part of your batch process.You will be better of pausing your replication, If you want to speed up this operation.


Thursday, December 22, 2011

Where is my IO?


We all are aware of sys.dm_io_virtual_file_stats and how useful is this DMV, But to be honest I could not find even one place which could give me the right working script leveraging this DMV and tell me if currently IO is an issue or not!

Well it think wait is over.I tried to put something together and come up with this. Feel free to correct this, but this works for me.

Anything more than 25 ms(that’s a Microsoft threshold J), practically anything more than 80 - 100ms can be something which you can dig into.

This gives you the real time picture and not since last time sql server started.
You can change the WAITFOR DELAY number to increase the delta figure.


-- Calculates average stalls per read, per write, and per total input/output for each database file.

SELECT DB_NAME(database_id) AS [Database Name], file_id ,io_stall_read_ms, num_of_reads,

CAST(io_stall_read_ms/(1.0 + num_of_reads) AS NUMERIC(10,1)) AS [avg_read_stall_ms],io_stall_write_ms,

num_of_writes,CAST(io_stall_write_ms/(1.0+num_of_writes) AS NUMERIC(10,1)) AS [avg_write_stall_ms],

io_stall_read_ms + io_stall_write_ms AS [io_stalls], num_of_reads + num_of_writes AS [total_io],

CAST((io_stall_read_ms + io_stall_write_ms)/(1.0 + num_of_reads + num_of_writes) AS NUMERIC(10,1))

AS [avg_io_stall_ms]

into #iostats_first

FROM sys.dm_io_virtual_file_stats(null,null)

ORDER BY avg_io_stall_ms DESC;


WAITFOR DELAY '00:05:00';

-- Calculates average stalls per read, per write, and per total input/output for each database file.

SELECT DB_NAME(database_id) AS [Database Name], file_id ,io_stall_read_ms, num_of_reads,

CAST(io_stall_read_ms/(1.0 + num_of_reads) AS NUMERIC(10,1)) AS [avg_read_stall_ms],io_stall_write_ms,

num_of_writes,CAST(io_stall_write_ms/(1.0+num_of_writes) AS NUMERIC(10,1)) AS [avg_write_stall_ms],

io_stall_read_ms + io_stall_write_ms AS [io_stalls], num_of_reads + num_of_writes AS [total_io],

CAST((io_stall_read_ms + io_stall_write_ms)/(1.0 + num_of_reads + num_of_writes) AS NUMERIC(10,1))

AS [avg_io_stall_ms]

into #iostats_second

FROM sys.dm_io_virtual_file_stats(null,null)

ORDER BY avg_io_stall_ms DESC;

select f.[Database Name],f.file_id,

(s.io_stall_read_ms - f.io_stall_read_ms) as 'io_stall_read_ms',

case (s.io_stall_read_ms - f.io_stall_read_ms)

when 0 then 0

else

((s.io_stall_read_ms - f.io_stall_read_ms)/(s.num_of_reads - f.num_of_reads))

end as 'avg_read_stall_ms',

(s.io_stall_write_ms - f.io_stall_write_ms) as 'io_stall_write_ms',

case (s.io_stall_write_ms - f.io_stall_write_ms)

when 0 then 0

else

((s.io_stall_write_ms - f.io_stall_write_ms)/(s.num_of_writes - f.num_of_writes))

end  as 'avg_write_stall_ms',

(s.io_stalls - f.io_stalls) as 'io_stalls',


case (s.io_stalls - f.io_stalls)

when 0 then 0

else((s.io_stalls - f.io_stalls)/(s.total_io - f.total_io)) end as 'avg_io_stall_ms'

from #iostats_first f

join #iostats_second s on f.[Database Name] = s.[Database Name]

and f.file_id = s.file_id

drop table #iostats_first

drop table #iostats_second

Wednesday, October 19, 2011

RAID 50 for database server!!! Good or Bad idea!


Just in case you wonder if RAID 50 is any good for database server!.

Dell says RAID 50 is great. Well It might be....... but not really for SQL database server. My and Microsoft view is that RAID 10 is a way to go because of excellent read and write performance.


RAID 50 is excellent for read but only “good” for random writes.


B.T.W , RAID 50 is a vendor specific configuration where multiple raid 5 arrays are striped across as well. It is still doing parity and now double the time. So how it can be good for write!!!..Not sure may be dell have done something else as well. In terms of performance it lies between RAID 10 and RAID 5.
 

According to equallogic , RAID Characteristics:
 

Table: RAID Level Characteristic Comparison
Workload Requirement
RAID10
RAID 50
RAID 5
RAID 6
Capacity
Average
Good
Excellent
Good
Availability
Excellent
Good
Average
Excellent
Sequential reads
Excellent
Excellent
Excellent
Excellent
Sequential writes
Good
Good
Good
Good
Random reads
Excellent
Excellent
Excellent
Excellent
Random writes
Excellent
Good
Average
Average
Performance impact of drive failure or RAID reconstruction
Minimal
Moderate
Moderate to heavy
Heavy



Random writes  are good in RAID 50 but excellent in RAID 10.

Monday, September 12, 2011

Why I say leverage SQL Server data and backup compression in 2008 R2??

If we all  look back, one thing you all will surely notice that CPU power has increased and its getting better and better every year.

If you compare the growth in technology with other components like disk speed ,memory, networking components etc etc, certainly CPU always stands out.

When we talk about SQL Server performance, its not stopped at disk speed, throughput and other individual components but is a mix of everything.

In SQL Server 2008 r2 ,compression is one great way to take away the load from the disk and memory perspective. Its simple, data and backup compression means less space and more data in cache. There is a little trade off in terms of processing the compression but now you have great processing power by intel series 2 sockets processors.

So why not go ahead and try it by yourself and see how much benefit you can get by exploring this feature.

I wont suggest you to go and blindly start compressing everything : ) :) , but start calculating your workload and focus on tables and indexes which are IO intensive and analyze if those objects can be compressed and give you more benefits in terms of IO and memory.

Tuesday, September 6, 2011

Thickness of arrow between operators in execution plans

In SQL Server if you have ever analysed the plans (execution plans) using SSMS plan analysis(I am sure you have :) ), then one thing you might have noticed is thickness of arrow between the two operators.

Thickness of arrow has been used by many DBA's as an estimation of size of data.

To correct the myth/confusion, this thickness of arrow just represents the row count and not actually the size of the data.

This means you can see a thin arrow representing 4 rows, but behind that it could be xml data of  GB size

so do not just rely on thickness of arrow before picking expensive operator and expensive flow of data between two operators.





enjoy 

Monday, August 15, 2011

How and where to find latest and greatest updates for SQL Server

As a DBA, Your prime duty is to make sure SQL Server updates are not out of date.There are many places which can give you the sql server release calender details.

The one I trust is :


This is safe as they also provide the matrix of build number and version number.

Enjoy :)