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

Friday, August 20, 2010

A Simple Thank You

         

In case you didn’t notice or have been on vacation for the last few days there has been quite the discussion going on in the SQL Community about the PASS Board of Directors election. I was going to write a blog post about my opinions on the elections but I’m pretty sure it’s all been said. Matter of fact here’s my favorite blogs on it.

Kendal van Dyke

Stuart Ainsworth

I don’t have anything that needs to be said about the election that has not been said already. Ok so what the hell is this blog post about then? I wanted to focus on some of the great things that PASS has done for me. Perhaps I’m wrong to mention the good things they have done when it seems like all they do is make mistakes but I guess it’s just in my happy nature to do so. Please do not think this post is in relation to any specific people out there. It’s just my way of saying thank you.

1. Thank you for giving us a world renowned summit where we can learn and socialize as Database professionals.

2. Thank you for supporting chapters. Working with the local people to get things done and encouraging others to start chapters.

3. Thank you for learning transparency. While so many mention that we still have not reached the goal of full transparency. In the 5 years I’ve been volunteering you have made huge strides and I know you will continue to do so.

4. Thank you for your time and hard work. Just because something isn’t done or responded to in a timely manner doesn’t mean people did not work on it and put lots of effort into it.

5. Thank you for helping me to meet and socialize with some of the greatest people I’ve ever met. As well for the countless others that have met at summits or chapter meetings.

6. Most importantly thank you to the volunteers of this organization. Not every project you work on goes as planned and many that you put your time and heart into don’t work out as you expect. But pushing on and keeping going is what makes this a great organization.

Many of you are going to be at SQL Saturday #51 this weekend with many of the Board members. While I want and expect you to tell them what they are doing wrong. Let’s try and keep in mind some of the things that have been done right. Perhaps even a thank you is in order not only for the good things they have done but for the mistakes they have made. None of us would be here if we didn’t make mistakes.

Thursday, July 22, 2010

Reads and Writes per DB, Using DMV’s

So years ago when I was working with a SQL 2000 database I had a need to see how many reads and writes were happening on each DB so I could properly partition a new SAN we had purchased. The SAN guys wanted Reads/Sec and Writes/Sec and IO’s/Sec total. Perfmon couldn’t give this for each DB so I had to use fn_virtualFileStats. I wrote a procedure that would tell me per DB what was going on and then store it down into a table for later comparison.

I’ve found a need for this again since I’m running some load tests and want to know what my data files are doing. This is easier now thanks to sys.dm_io_virtual_file_stats. It’s even better now that so many people in the community provide great content! Glen Alan Berry (Blog | Twitter) wrote and excellent DMV a day blog post series and in one of them he gives a great query on Virtual File stats. This gives you an excellent general point in time look at your server but was not exactly what I needed. I wanted to know for a specific period what were my reads and writes. This works better for my load testing needs to know just what is going on during a specific time.

You might want to use this during heavy business hours as well. The DMV is keeping track since the last Server restart so if you look at just the DMV you’re going to see everything that has occurred. Maintenance items (checkdb, Indexes, Backups) will all show up inside there so one DB might be very large in size and at night when the backup kicks off it might be using lots of Reads making it’s percent much higher but during the day no one really uses the DB so the DMV might show you that the DB is very busy when in reality your other DB’s are the busy one’s during the day. So If I’m planning for a new SAN or moving around files I would run this query at specific times so I could compare data points and find out what my databases are actually doing during critical times.

This script takes a Baseline record on the DMV. It then waits the amount of time you specify and takes a comparison line. It then compares the two and returns the percent’s. Lots more could be done with the comparison and certain things I’ve left in for later changes like Size. Right now I don’t do anything with Size but I plan to show the growth from the data points. I chose not to create the script as a stored proc just so it’s easy for you to put where you want. It only deals with 2 data points to keep it simple for now I have considered changing this in the future. The only setting you need to change is the @DelaySeconds parameter. Just set that to the number of seconds you want it to wait. 60 seconds is usually a good default to get a quick snapshot on the server. My suggestion to discover what your databases are doing during busy times I would probably run it for about 300 seconds (5 minutes) and then do that 2-3 times in an hour to see what the data looks like.

Would love to hear any comments on if this works for you!  Thanks. 




/*********************************************************************************************
File Stats Per DB
Date Created: 07-22-2010
Written by Pat Wright(@SqlAsylum)
Email: SqlAsylum@gmail.com
Blog: http://Www.Sqlasylum.com
This Scrpit is Free to download for Personal,Educational, and Internal Corporate Purposes,
provided that this main header is kept along with the script.  Sale of this script is
Prohibited in whole or in part is prohibited without the author's consent.  
*********************************************************************************************/

CREATE TABLE #FileStatsPerDb
  
(
  
ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
  
[databaseName] [NVARCHAR](128) NULL,
  
[FileType] [NVARCHAR](60) NULL,
  
[physical_name] [NVARCHAR](260) NOT NULL,
  
[DriveLetter] VARCHAR(5) NULL,
  
[READS] [BIGINT] NOT NULL,
  
[BytesRead] [BIGINT] NOT NULL,
  
[Writes] [BIGINT] NOT NULL,
  
[BytesWritten] [BIGINT] NOT NULL,
  
[SIZE] [BIGINT] NOT NULL,
  
[InsertDate] [DATETIME] NOT NULL DEFAULT GETDATE()
)
ON [PRIMARY]

DECLARE @Counter TINYINT
DECLARE @DelaySeconds INT
DECLARE
@TestTime DATETIME


--Set Parameters
/*
The counter is just to initialize the number to 1
The Delayseconds Tells SQL Server how long to wait before it runs the second data point.  
How long you want this depends on what your needs are.  If I have a load test running for
5 minutes and I want to know what the read and Write percents were during those 5 minutes
I set it to 300. If I just want a quick look at the system I'll usually set it to 60 seconds,
To give me a one minute view.  This depends on if it's a busy time and what's going on during that time.
*/
SET @Counter = 1
SET @DelaySeconds = 60
SET @TestTime = DATEADD(SS,@delayseconds,GETDATE())



WHILE @Counter <=2
BEGIN
INSERT INTO
#FileStatsPerDb (DatabaseName,FileType,Physical_Name,DriveLetter,READS,BytesRead,Writes,BytesWritten,SIZE)
SELECT
  
DB_NAME(mf.database_id) AS DatabaseName
  
,Mf.Type_desc AS FileType
  
,Mf.Physical_name AS Physical_Name
  
,LEFT(Mf.Physical_name,1) AS Driveletter
  
,num_of_reads AS READS
  
,num_of_bytes_read AS BytesRead
  
,num_of_writes AS Writes
  
,num_of_bytes_written AS BytesWritten
  
,size_on_disk_bytes AS SIZE
FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS fs
JOIN sys.master_files AS mf ON mf.database_id = fs.database_id
AND mf.FILE_ID = fs.FILE_ID
IF @Counter = 1
  
BEGIN
       WAITFOR
TIME @TestTime
  
END
SET
@Counter = @Counter + 1
END

;
WITH FileStatCTE (Databasename,Filetype,Driveletter,TotalReads,TotalWrites,TotalSize,TotalBytesRead,TotalBytesWritten)
AS
(SELECT BL.Databasename,BL.FileType,Bl.DriveLetter,
      
NULLIF(SUM(cp.Reads-bl.Reads),0) AS TotalReads,
      
NULLIF(SUM(cp.Writes-bl.Writes),0) AS TotalWrites,
      
NULLIF(((SUM(cp.Size-bl.Size))/1024),0) AS TotalSize,
      
NULLIF(((SUM(cp.BytesRead-bl.BytesRead))/1024),0) AS TotalKiloBytesRead,
      
NULLIF(((SUM(cp.BytesWritten-bl.BytesWritten))/1024),0) AS TotalKiloBytesWritten
FROM
( SELECT insertdate,Databasename,FileType,DriveLetter,READS,BytesRead,Writes,BytesWritten,SIZE  
  
FROM #FileStatsPerDb
WHERE InsertDate IN (SELECT MIN(InsertDate) FROM #FileStatsPerDb) )  AS BL --Baseline
JOIN
( SELECT insertdate,Databasename,FileType,DriveLetter,READS,BytesRead,Writes,BytesWritten,SIZE  
  
FROM #FileStatsPerDb
WHERE InsertDate IN (SELECT MAX(InsertDate) FROM #FileStatsPerDb) )  AS CP -- Comparison
ON BL.Databasename = cp.Databasename
          
AND bl.filetype = cp.filetype
          
AND bl.DriveLetter = cp.DriveLetter
GROUP BY BL.databasename,BL.filetype,Bl.driveletter)

/*
Return the Read and write percent for Each DB and file.  Order by ReadPercent
*/
SELECT databasename,filetype,driveletter,
      
100. * TotalReads / SUM(TotalReads) OVER() AS ReadPercent,
      
100. * TotalWrites / SUM(TotalWrites) OVER() AS WritePercent
FROM FileStatCTE
ORDER BY ReadPercent DESC,WritePercent DESC            

In my haste I forgot to add a sample of what you would get from this.  The names of the DB’s have been changed. 

readpercentsample

Monday, June 21, 2010

Question Everything.

waterandchalkartfestival 033

The world is full of information. So much so that we may believe there’s nothing left to write or do. As I try to get back to blogging more frequently I find myself wondering what to write about. It’s not to say my day is not full of lots of things to do. The question I was asking myself is why should I write these things when the world already has great writers and great information out there?

The answer of course is simple. Question Everything.

Ask any of the experts in a field of study and they will tell you one of the best ways to learn a new topic is to present on it. You force yourself to learn about what you’re presenting so that you are prepared for it. Now don’t get me wrong I use the scripts available out in the community all the time. I suggest them to clients and to fellow DBA’s. I am not advocating re-inventing the wheel. They are no doubt an essential tool in helping to make our lives easier and better.

Just because you get the perfect script to meet your needs doesn’t release you from responsibility from what it does. If you install a new script on your servers and it slows things down or has a negative side effect that the original designer didn’t mention or you didn’t realize, then your boss is not going to blame that on the person or blog you got the script from. They will blame you for releasing it into the environment.

So what should you do? Well as the person using the script you should read what the person who designed it wrote about it. Most of the time the designer of the script will detail what it does in blog posts or in some sort of documentation if by chance it doesn’t have that then dissect the script and figure out what it does. I prefer to take apart a script myself so that it forces you to learn how to read other’s code and how to figure out what it is doing which to me is an essential part of being a DBA. We rarely get things in the format we expect. Unfortunately many people don’t think like a DBA.

For the Senior/Master/gurus out there don’t just hand your new guys scripts and say run this and it will do what you need. Perhaps tell them you have a script that does what they need and here are the ways you did it perhaps the new guy can find a new better way. This teaches them and guides them at the same time. A good example of this is Quest’s new Perfmon counter poster. You have a lot of information at your fingertips but don’t just look at the benchmark numbers and assume that’s what works for all situations make sure to benchmark your own servers and find out what numbers are right for your situation. As I read through this new poster this weekend I realized there was some things I could change in what I was tracking to give me more information about my server.

If your one of the ones out there writing the scripts THANK YOU! I applaud anyone that has put something out there for others to use and that has helped make our lives a little easier. Keep up the good work and keep doing what you’re doing.

Friday, June 18, 2010

24 Hours of PASS Recordings

                 Oregon Road Trip-222

It’s over! It’s gone we just can’t get it back! Just in case you missed the most recent 24 hours of PASS don’t worry, you can relax because it’s available via recording! So don’t  worry just click on the link below and all your troubles(and performance issues will be fixed). :)

http://www.sqlpass.org/LearningCenter/24Hours.aspx

You will need a Pass login to view the recordings.  It’s free so sign up now grab some popcorn and Mountain dew and get watching.  :)

Thursday, June 17, 2010

DTExec and SSIS

I could list lots of excuses as to why it’s been so long since I blogged but I’d rather get to the blog post so let’s just say I’m lazy and working on getting better.  :)

I’ve been doing work with SSIS and running it at a command prompt so I could use it to load test a Database.  My hope is later to move this into a simple application that calls the procedures I want but until I start learning C# for now I’ll stick with SSIS. 

The problem I ran into was passing parameters.  I have a loop inside my package and I want it to run X amount of times for my testing needs.  That’s not a problem on setting up the loop you can find that here.  But how do you pass the variable to the package so that you can tell it how many loops you want?  Well for that here is  another blog that talks about it.    Ok so now that I’ve linked off most this post to others what the hell am I trying to add to all this?

Well I read those blogs and it worked until I started adding multiple set options and I ran into some simple syntax issues.  I also noticed there was few examples out there of the full syntax of what it looks like.  Call me crazy but this always screws me up when I’m trying to get syntax right with SSIS.  So here are my scripts that I use currently to execute my package. 

DTExec.exe /Rep N
/set \Package.Variables[User::iCounterEnd].Properties[Value];100
/set \Package.Variables[User::RunDataLoad].Properties[Value];-1
/set \Package.Variables[User::InitialLoadEnd].Properties[Value];1000000
/File "c:\TestAdventureWorks\runstresstests.dtsx"


Now as you might guess in my package I have  3 variables called iCounterEnd,RunDataLoad and InitialLoadEnd.  For all you SQL people out there that are not use to coding environments they are case sensitive(yes this has been hard for me as well).  Also notice that RunDataLoad is a –1.  The variable is a Boolean which I would have assumed would say “true” or “False”  but I was wrong.  It is –1(True) or 0(false) for the setting. 

Now a great way to get examples of what should and should not be is to use Package Configurations.  If you enable package configurations and write an xml file down to some directory then you can get the variable path/name that you need and the value it’s currently set to.  Here’s a screenshot of what the package config file will look like. 

ssisconfig

The Path = is what you need above to make sure you have the correct path to the variable. 

Hopefully this will help others to take a little less time to get a package to run from the command line.

Pat

Friday, May 14, 2010

5 Things SQL Server Should Get Rid Of

 

I’ve been wanting to toss my hat into the latest Meme by Paul Randal( Blog | Twitter).  So here’s my list. 

1.  Auto Shrink.  I agree with Paul on this.  It should never be turned on and it’s not needed.  I don’t like to have to shrink files but allowing them to Auto shrink is even worse.  Just asking for performance problems. 

2.  Defaults for files.  I promise I’m not trying to copying Paul verbatim here.  This one effects me all the time.  I have a client that makes lots  of databases then throws millions of rows into them.  They never change this setting!  Until I come in to look at the server and find thousands of autogrows.  Why not let me set the model to a specific setting and everything uses that as the default?  Or perhaps you could have a server property to set it?  I’m planning some work on PBM in the future to see if I can get this to do it for me. 

3.  Enterprise Edition.  Now before you get the tomatoes ready here me out.  I don’t want MS to kill the flagship product with all the features I want them to move many of those features down to Standard.  I work with lots of small customers that have sometimes hundreds of db’s and can’t afford Enterprise edition but could really use something like Resource governor or Data Compression.  The Big customers and big enterprises I work for rarely use these technologies because they’ve got 20 developers to write there own resource management or ways around compression.  They have the benefit of resources to find another way.  Give these features to the little guys so they really utilize the new features.  I typical see the smaller companies are the ones trying to blaze new trails with the new features. 

4.  ONE TEMPDB!  I would love to see the ability to create multiple TEMPDB resources and assign groups of DB’s to it.  Think of those out there with 100’s or thousands of Db’s you have a tempdb bottleneck always.  Now yes you can split the files and put it on fast disks but it’s always going to be a single point of contention. 

5.  Last but not Least.  SSMS.  I know others have mentioned this one as well.  This tool tried to be a dev studio and a management studio and failed.  It’s ok at both.  Why not just leave VS as the dev studio(which rocks) and create a rocking Management Studio.  Something like Quest Fog light/Spotlight.  Give us some of the cool tools out there to really MANAGE our servers not just Design against them. 

Since I crashed the party I won’t bother Tagging anyone.  :) 

Friday, April 30, 2010

The Rabbit hole, Tips on Dynamic SQL

Leaving the Subway 

Ya never know what’s down the rabbit hole. 

I always try and warn people when you go down the Dynamic SQL path you have to be ready to go down the rabbit hole. You always think it’s just a simple thing until you’re face to face with the Queen of hearts and she yells “Off with her head!”There is one thing that Dynamic SQL is good at, Making you think out of the box.

So I’ll share some tips on Dynamic SQL  through a conversation I had with a friend. We’ll call him Bob.

Bob: hey why can’t I do this in Dynamic SQL, select @reccount = count ( * ) in dynamic sql?

Me: you have to declare the variable you are trying to set inside the Dynamic SQL, Remember Dynamic SQL is in another Process/Thread. So it cannot see cursors/variables outside its set of Dynamic SQL. If you run a USE statement in the Dynamic SQL it will only effect the statements inside the Dynamic SQL. To get something like a count between the two threads you would need to insert it into a temp table. I’ve listed a typical way to do this below.

--Original way that fails. 
DECLARE @cmd NVARCHAR(4000) 
DECLARE @reccount INT 

SET
@cmd = 'Select @reccount = Count(*) from master..sysdatabases'

PRINT @cmd 
EXEC sp_executeSQL @cmd 

--Way that works by inserting to a temp table. 
DECLARE @cmd NVARCHAR(4000) 
DECLARE @reccount INT 
DROP TABLE
#rowcount
CREATE TABLE #rowcount 
  
(reccount INT NULL)

SET @cmd = 'Select Count(*) from master..sysdatabases'

PRINT @cmd 
INSERT INTO #rowcount (reccount) 
EXEC sp_executeSQL @cmd 

SELECT * FROM #rowcount

Bob: Ok so what about this problem I have of adding all these strings together this get’s really complicated and hard to read when I’m adding 4-5 variables together. Here’s an example.

DECLARE @cmd NVARCHAR(4000) 
DECLARE @startdate date
DECLARE @enddate date
DECLARE @dblevel INT 

SET
@startdate = '02-01-10'
SET @enddate = '05-01-10'
SET @dblevel = 100

SET @cmd = 'Select * from master..sysdatabases where crdate between ''' + CONVERT(VARCHAR(25),@startdate) + ''' and ''' + CONVERT(VARCHAR(25),@enddate) + ''' and cmptlevel = ' + CONVERT(VARCHAR(10),@dblevel)
PRINT @cmd 

EXEC sp_executeSQL @cmd 

This is hard to read and I have to do lots of conversions to get things to work.

Me: I’ve found when dealing with Dynamic SQL it’s best to write the query you want with values and then replace the place holders you want to change. So taking your example here’s another way.

DECLARE @cmd NVARCHAR(4000) 
DECLARE @startdate date
DECLARE @enddate date
DECLARE @dblevel INT 

SET
@startdate = '02-01-10'
SET @enddate = '05-01-10'
SET @dblevel = 100

SET @cmd = 'Select * 
from master..sysdatabases 
where 
crdate between ''<startdate>'' and ''<Enddate>''
and 
cmptlevel = ''<dblevel>'''

SET @cmd = REPLACE(@cmd,'<startdate>',@startdate)         
SET @cmd = REPLACE(@cmd,'<enddate>',@enddate)
SET @cmd = REPLACE(@cmd,'<dblevel>',@dblevel)
PRINT @cmd 
EXEC sp_executeSQL @cmd 

This is much easier to read and find what you’re looking for and what you need to replace. Now of course there’s many ways to do this for me this has always been easier.

BOB: Ok last question. Sometimes my Dynamic SQL doesn’t run. It doesn’t return anything and doesn’t seem to do anything at all. It won’t print it doesn’t error it just does nothing! It’s very frustrating. Any idea as to why this happens?

Me: This is where you need to be careful down the rabbit hole. Very careful, here’s an example of what will cause this exact situation to occur can you spot the difference and what the problem is?

DECLARE @cmd NVARCHAR(4000) 
DECLARE @startdate date
DECLARE @enddate date
DECLARE @dblevel INT 

SET
@startdate = '02-01-10'
SET @enddate = '05-01-10'
SET @dblevel = NULL

SET @cmd = 'Select * 
from master..sysdatabases 
where 
crdate between ''<startdate>'' and ''<Enddate>''
and 
cmptlevel = ''<dblevel>'''

SET @cmd = REPLACE(@cmd,'<startdate>',@startdate)         
SET @cmd = REPLACE(@cmd,'<enddate>',@enddate)
SET @cmd = REPLACE(@cmd,'<dblevel>',@dblevel)
PRINT @cmd 
EXEC sp_executeSQL @cmd

I set the @dblevel = null. Anytime a variable is null and you place it into a Dynamic SQL string it nullifies the entire string. Worse yet it doesn’t error or complain about this issue it just does nothing. Go ahead and test it out on your system pass any NULL into a Dynamic SQL string and it will do nothing. You should make 100% sure that every variable/value that you pass into a Dynamic String is not a null.

This is just some quick tips I had for Dynamic SQL it’s by no means a full list of all the issues. I do warn people that with “Great power comes great responsibility” – Ya I went there.  :) Here’s some simple pro’s and con’s to keep in mind with Dynamic SQL

Pro’s

  • Great flexibility
  • Ability to get through many db’s without writing code that lives in each one. If you have many db’s on a server and you need to check X then there’s a way to do that.
  • They can now store execution plans. I still wouldn’t guarantee this but they previous to Sql 2005 Dynamic SQL never re-used plans.

Con’s

  • Prone to errors, it’s very hard to track errors and deal with errors in Dynamic SQL.
  • SQL Injection, this is the primary method to get SQL injection into your system. Protect and check your variables.
  • Readability, even with the sample I posted above it’s hard to read and figure out what Dynamic SQL is doing
  • Debugging/Testing, Debugging Dynamic SQL consists of many print statements and lots of trial and error to make sure you have everything just right.

I would also suggest that you look into PowerShell before going the Dynamic SQL route. Many of the things you would use Dynamic SQL for can now be done in PowerShell. Here are some Articles about PowerShell from Buck Woody and Aaron Nelson.

Regardless of what you decide be careful when you going down the Rabbit hole sooner or later you’ll be stuck in a big way with only a little door to get out from.

Thanks to @SqlVariant (Blog|Twitter) on the tips for Simple-Talk’s Prettify code.   It made the code samples in here look much better. 

Saturday, October 31, 2009

New PASS Executive Committee

I wanted to wish a big Congratulations to the new Executive Committee for PASS for next year.  The New committee will be

Rushabh Mehta as President. 

Bill Graziano as Executive Vice President of Finance

Rick Heiges as Vice President of Marketing

I hope them all the best in making a great next year for the PASS Community. 

The official announcement can be found here. 

http://www.sqlpass.org/Community/PASSBlog/articleType/ArticleView/articleId/118.aspx

Tuesday, October 27, 2009

Different Approach to the PASS Summit this year

Volunteer Committee Last year at the Volunteer Outing. 

This will be my 5th PASS summit this year.  My second and final as a PASS Board of Director.  Each PASS has been different for me but most have all had one theme in common.  Meet and Network with many people while learning great things about SQL Server.  This year I still intend to Meet and Network with others and learn about SQL Server but I’m also going to document and focus on the people at PASS.  Everyone knows I’m a photo nut and tend to have my camera with me to much.  Well this year it will always be on me.  I’ve decided to forego my normal large laptop/camera bag for just a camera bag and net book.  Most of the time my camera will be around me shoulder/neck on my R-Strap ready to take pictures whenever I can.

I’m a visual person and have a hard time remembering names and faces.  Hopefully for me this will help me to recognize people for the next PASS Summit.  All my pictures will end up on my Flickr Photostream and will be available to those that I have taken pictures of.  If you would like a quick headshot or a picture with a friend at PASS feel free to seek me out and we’ll set something up. 

If you would like to have fun and see Seattle and take pictures as well we have a Photowalk planned on Monday at 8:00 a.m. Feel free to come join us. 

 

pat

Monday, October 26, 2009

Holy Bingo, I’m a Square!

That’s right this year at the PASS Summit you get to play Bingo!  Not just any Bingo but Twtiter Bingo.  Stuart A(@StuartA), Brent O(@brento) and Blythe M(@blytheMorrow) have put together rules and all the details of the contest. Stuart has blogged about it here.  Basically you need to find people on the Bingo card on Tuesday you need to get a straight line.  Monday two straight lines and then on Wednesday a blackout.  Each day once you have gotten the specific pattern you need to turn it into the Quest booth at the expo hall.  They will have a drawing for fabulous gifts and prizes.  :) 

Now I’m telling you all this because I’m a Bingo Square!  My handle on twitter is @SqlAsylum.  I will be one of the easiest squares to find because I'm typically wearing a red vest as a PASS Ambassador.  patpass2007 So most of the time you can see me near the PASS Booth or in the halls helping to direct others to where they are trying to go.  I’m also a PASS Board of director and would love to hear your thoughts on the PASS Elections, the conference or the Community in general.  Hopefully you will all have a chance to find me. I’ll even tell you the story or my code word if you would like.  It’s all about the PASS Conference and it’s history. 

Pat

Friday, October 23, 2009

Photowalking at the 2009 PASS Summit

It’s that time of year again for the PASS Summit.  Which means it’s time for a PASS Photowalk.  Tim Ford(@sqlagentman)  and myself wanted to get together last year and take some pictures around Seattle.  Many friends joined us and the PASS Photowalk was born.  We will be leading a Photowalk once again this year  Here are all the details. 

Where: Sheraton Lobby
When:  Monday Nov 2nd 8:00 a.m.
Who:  Anyone with a camera.  The only requirement to Photowalking  is a camera of some sort.  If it's a camera on your phone that's fine. The goal is to socialize and meet other PASS/SQL folks and to take pictures while doing it. 

Myself and Tim Ford will be leading the Photowalk.  We will start off at the Sheraton and hopefully do a quick group shot and then work our way down to Pikes Place Market and then to Sculpture Park near Pikes place.  From there will be anyone's guess.  We will most likely stop at Pikes Place for some breakfast of some sort.   Many of us will have things to attend later in the day on Monday so the walk most likely will not go past lunch time.   Hopefully everyone is attending Don Gabor’s session later in the day as well. 

We will use #sqlpassphotowalk as the hash tag for the event in case you want to follow where we are on twitter.  I’m sure a few other people on the walk will be using twitter.  If you know your going to be late email me at pat.wright@sqlpass.org and I’ll pass on my cell phone number so you can call me and find out where we are. 

I've created a Flickr group for us to post photo's from the Photowalk.  You can visit it here.  http://www.flickr.com/groups/passphotowalk/ please Tag your photos with SQLPASS. For ease of searching.  If you don’t have a flickr account it’s free to setup.  You can see my pictures from last years Photowalk as well to get an idea of the walk.  

Here are some suggestions to make this a good photowalk for you.

1. Be sociable.  This is about learning and networking.

2. Be prepared.  Last year we were lucky with excellent weather.  We will see if we are that lucky again.  Dress in layers and either carry an umbrella or be prepared to get wet.  If your brining a Digital SLR like myself it’s best to have something to cover it up with such as a bag to keep the water out. 

3. Walking.  While we may stop at a location to take pictures there will be much walking.  Wear shoes that are appropriate to do so. 

4. Have fun.  As with all things at PASS have a good time.

If there’s any questions comments feel free to add them here.  I’ve also posted this in the Hotels.sqlpass.org  forums .

Hope to see you all there! 

Pat

Tuesday, September 15, 2009

“The Cube” Summary of Peter Myer’s User group presentation.

Peter Myers is in SLC this week to do some training. He was kind enough to approach the Local SQL PASS user group and offer to do a presentation. I helped out by organizing the location at New Horizons. This would be a good time to check for your Local SQL PASS Chapter if you don’t know where it is. Here’s a list!

Peter’s Presentation was “Developing a UDM with Analysis Services” UDM = Unified Dimension Model. This is a new name MS has given for Cubes in 2008. So don’t let the name fool you UDM =Cubes. Peter did a great overall presentation on Cubes showing us how to create them and enriching them with more features. Here’s some of the key points.

Reasons for Moving to OLAP Structures instead of OLTP

Performance,

Multiple Disparate Systems of data can be combined to one,

Interpretation /One Truth of the data can be controlled in one location.

DW is a continuing process never ending. Answering questions will always just yield more questions.

We all know that the more questions you answer the more questions the business has for you. So when someone says to you that the DW process will be done in 2-3 years it really won’t it will keep evolving. Much of the design and work to load the DW could be complete but more questions will keep coming.

Data Source Views

Allow for the abstraction of your data layer. It’s good to build the foundation properly and setup your DW database in the fact/dimension table schema that you have designed. When that’s not always possible or your given read only access to the data and you can’t change the underlying schema then you need to make those changes in Data source views. Here’s some key items you can do.

Create columns based on other columns.

Create tables based off queries and filter tables based off a query.

Create friendly names to make it easier to use in the cube.

Dimensions

Peter suggested creating your dimensions before allowing the cube wizard to create your dimensions for you. Typically I create my dimension tables in the underlying data structure and then allow the wizard to create the dimensions for me. I agree with Peter though that this will allow you to be more in control by creating the dimensions first and modifying them for your need and then just telling the wizard where to go to get the data. I like this approach much better and plan to move to it in the future.

It’s a good idea to change your Key columns and your Name columns in your dimensions to the data that you actually want. The wizard does not always get this right and should be something that you get the information you are looking for.

Limit your dimensions and don’t show the columns the end user doesn’t need.

Create hierarchies to help the end user navigate better.

SSAS 2008 incorporates best practices into it so if you see a blue squiggly line it’s making a suggestion that it wants' you to change something to meet best practices.

Cubes

Peter really showed us the building blocks to building the Cube so when it came to actually building the Cube it took very little time and worked very well. I’ve been a firm believer in building your foundation first for your cubes so huge props to Peter for doing an excellent job in explaining it this way for everyone.

Excel

I’ve used pivot tables in excel for many years so most of this was review for me but as always you should keep learning new things and I once again learned something new here. I learned that about the formula for =CubeMember() in excel. I was not aware of this before allowing you to place cube data just about anywhere in excel. This will be great for some specific reports that we have that are manually updated right now. I can place a sheet on the work book that has the cube data and just hide the sheet and reference it with this throughout the report that they want. Great added functionality.

Overall Peter not only knew his stuff but was an Excellent presenter. I really have a hard decision to make now on what pre-con I want to attend. :)

I’m planning some follow up blog posts on a few other key items he mentioned. Attribute hierarchies, properties of dimensions and more on using excel and CubeMember()

Thanks again Peter!

Friday, September 11, 2009

When a Second just isn’t fast enough

So I find myself performance tuning queries and statements all the time for SQL Server.  Many times I run into easy statements that are missing an index or calling a function 20 million times and causing problems.  These queries typically move from 20 seconds to 1-2 seconds very easily with some quick changes.  My problem this week was a query that took  1.5 seconds.  I needed to get this to run under 1 second consistently. I knew could get a little more out of the query by looking at the execution plan but I also knew I would have to consider the Architecture and the application itself to really get it the way I wanted it. 

I was surprised to find something in the execution plan that helped me out more than I expected.  The Key Lookup (In 2000 they are called Bookmark Lookups).  These show up in the execution plan and look like this. 

image

You will usually find these in your execution plans along with an Index seek/scan.  But what really do they mean?  SQL Server has found your data in the index but some of the values you have asked for in the query are not located in the index pages and it must go and lookup the data.  This will take a little more time as SQL Server goes and fetches your data. The funny thing about this query is that for the Execution plan it only put cost at 10% on this particular lookup.  Which seemed odd to me because when I looked at the IO STATS ( Set STATISTICS IO ON) it seemed like many of my reads were to pull back this data.  I decided I would ignore the Cost %  and place a covering index on the fields that are getting pulled back. I changed the index that it was using in the seek to add columns in my select statement as INCLUDE columns in my index.  This made a larger improvement than just the 10% that it had estimated.  It removed about 500ms of time from the query.  Which is a lot when your trying to go from 1.5 seconds to <1 second. 

Of course you do have a trade off here. By adding the columns to the index I’ve made my index larger and take up more space so don’t go around just adding all your fields into the INCLUDE of a index.  You need to evaluate and find out if the trade off is worth it.  In this case it is.  I’m also making changes to the application so that it doesn’t request columns it doesn’t need then I can remove them from the INCLUDE and save myself some space. 

If there is one thing I’ve learned from performance tuning and reading execution plans is never take them at face value.  They are a tool that was created to help you make better decisions.  They are not always right so make sure to do your homework and really test your procedures and break them down to find the real bottlenecks. 

Happy Performance Tuning

Wednesday, June 3, 2009

Reasons for NOT using Varchar (MAX)

Let me start by saying I am not against using Varchar (MAX). I love the idea of it, it has greatly simplified the use of LOB data types in my opinion.  I am simply listing out some points I used recently to not use Varchar (MAX) . I recently reviewed a DB structure and found that ALL the Varchar fields were set to Varchar (MAX).  Things like Name, Username(I would be very interested to see a 8GB username),  City, etc…   I’m not one to tell someone though you have to change your design “just because”  I said so.  I wanted some reasons.  I posted the question on Twitter and looked around online for some good reasons here are the ones I ultimately ended up using. 

1. Adding a Text Data type / Varchar (MAX) to a table removes the ability for online re-indexing. --Thanks @paulRandal

2. Performance Degradation.  This goes back to another point about only get what you need.  Their was Varchar(Max) on almost every table adding overhead to that many tables causes Performance Pain.  Thanks @AaronThehobt for pointing that out. 

3.  Poor Design Practice.  In general you should only be grabbing what you need.  Creating a field that can store just about any amount of data just to hold 100 characters is simply a wasteful operation.  I would suggest finding out what the business need/ logical need for the field and then use that to define the structure.  Thanks @peschkaj for bringing the design aspect up.

So hopefully this will help you to convince someone else in the future to avoid using this as a catch all for any string based field.  Feel free to add comments with other suggestions for reasons NOT to use it. 

Monday, May 25, 2009

Path to DBA

Recently I needed to make a list of what tasks I thought would be needed to qualify someone from a Jr. DBA to a DBA.  One of the people I was managing had started as a Jr. DBA that we were training and after a year of training and tasks we felt it was time to move him up in rank to a full time DBA.  Of course we wanted a checklist of items to prove this so below is the list I used to qualify the person. 

1. Fixing corruption issues

2. Determining optimal Disk layout based on application needs. 

3. Index suggestions based on Slow running Stored Procedure.

4. Index/performance suggestions based on profiler running against application. 

5. Defragmentation, Stats, reindex schedule suggestions.

6. Understanding of Sql Server configuration best practices.

7. Ability to place the db in Single user mode, Rebuild master, Attaching/Detaching Db’s.

8. Understanding Security differences in Role/user security

9. Understanding Isolation levels, difference suggestions for using each one. 

10. When is a good Use of (nolock) and for what?

11. What are memory configurations and settings for SQL server.

12. Backup and Restore Db through t-sql and to a point in time.

13. Setting up Db mail.

Along with this list was some specific goals and suggestions for the specific company and application we worked with.  A good DBA not only understands the Database system they are working with but they also know the system and how it is used. 

I’m sure there are more things people could think of feel free to add more in the comments if you have suggestions for additional items. 

Thursday, June 26, 2008

Pass Summit

Did you know that the PASS Summit is right around the corner? Well Ok it's in November but The Early bird discount expires on June 30th! Now is the time to register for the Best SQL Server summit around! They have also just announced some of the sessions on the Summit Website I would suggest taking a look at them. In my opinion there's nowhere you can get so much great training on SQL server and networking with more SQL Dba's then the PASS Summit. This also will be our largest Summit ever and the 10th summit in PASS's History!


http://summit2008.sqlpass.org/spotlight-sessions.html
http://summit2008.sqlpass.org/program-sessions.html

I almost forgot the Keynote Speakers are listed also. Typically Keynote's are not the best sessions of the conference for me but with Ted speaking on the future of SQL Server I think that's not going to be one to miss. I also met and spoke with Tom Casey at a Ms event recently and I think that will be a great presentation he's interested in everything about SQL Server and should be an excellent keynote speaker.

http://summit2008.sqlpass.org/keynotes.html


Check it out and Get Registered! I hope to see you there!