Download

SQLServer UG: Managing your tempdb

Updated on May 23, 2013

Tempdb is a piece of simple stuff that often overlooked in SQL Server planning. Many DBAs ask for more CPU, RAM, and storage but let alone tempdb stays in drive C. Tempdb can be the big bottleneck in system performance, because it contains many stuff for SQL Server operation.

What’s in tempdb, actually?

Here are the short list of tempdb contents:

  • User objects: your @tablevariable and #tempTable are 2 common example
  • Internal objects: required for internal SQL Server to run, but not directly created by users. Example: worktable in hash join and rebuilding index maintenance
  • Version store: obviously, when snapshot isolation is enable then SQL Server need to keep version store in tempdb

To summarize: when the application query uses alots of temporary operation, tempdb will grow very fast as well. How do we forecast tempdb size? Sad to say but true: there is no exact formula to calculate its size.

Sunil Agarwal from SQL product group has done a series of writing on tempdb monitoring and maintenance. I suggest you to read it for better understanding. His posts collection are here: http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/tempdb/

I presented this topic for SQL Server Group in MS Office – Jakarta on Febr 28, 2013. Below is the summary of tempdb tuning and optimization:

tempdb

 

The complete PPT and sample code are available for download here:

KPI Report with Reporting Services 2008 R2

There is a new gem in SQL Server 2008 R2: Indicator control. It enables us to create KPI style report in easy way. You may ask how is it difference with Gauges that already exists in SQL Server 2008?

Well, Gauges is cool by displaying speedometer style indicator. But sometime they are just too much. I don’t want the fancy circle style, instead I want it to be a simple traffic light or dot indicator like this:

image

If you are a Reporting Services veteran then you know what to do: upload couple of traffic light symbols and bind them to a cell. Then write an expression to hide or unhide each symbol accordingly. We don’t need to do this anymore in R2. Here is the way to achieve it in easy way.

First, as usual we need to provide a cell as placeholder for this indicator. Second, place indicator control inside the cell then bind them to corresponding columns in the dataset.

image

The last step is configuring the expression logic for them. By default is only showing 3 state: Red, Yellow, and Green. But we can add as many states according to requirement. Once its done, just render the page to show KPI report.

Here is my sample KPI report. It requires Reporting Services 2008 R2 and AdventureWorksDW2008 database.

The same concept also applied to display trend in R2. I posted about creating trend sparklines in SSRS 2008, which is require to do a bit workaround. Not in R2 version, because It has dedicated sparklines control as well.

Practical SQL Performance Troubleshooting

DBA daily life is always hectic. They receive many issues ranging from network, performance, security, or application. I had collected many scripts and tools since couple of years ago. They are very useful for ad-hoc troubleshooting and diagnose the problem on the spot.

When I mentioned ad-hoc means the ability to locate and diagnose the problem quickly, without collecting data with SQL Profiler or Perfmon. I’m not saying that ad-hoc approach is better, but there are many situations when we just do not have enough time to collect the data while my users are screaming. The DMVs become handy tools for this purpose. It shipped since SQL Server 2005, and has been improved in 2008. I always has those DMVs in my shortcut folder, or in most cases in my thumb drive.

I had the opportunity to do demo on this topic at Singapore SQL User Group meeting last month. The response was fantastic, knowing that we have many free scripts to solve our daily problem. I promised to upload all presentation and sample codes, so here they are:

Presenting Trend with Reporting Services

I posted KPI report in previous entry, something that really cool in SSRS 2008. There is another method to display a trend without much attention on number and achievements. It’s called sparklines. There are many occasions when decision maker only need to know the trend regardless of actual values. A simple visualizations can help them to grab the fact quickly.

Below is an examples of sparklines:

sparklines1

How to create a sparklines report? It is actually simple. In general, there are 3 steps:

  • Create a chart of your choice. Lines chart is a popular form. Bind it to the data of interest such as sales amount, total cost, etc.
  • Squeeze the chart as small as possible but still maintain its readability. Remove all unnecessary details like X and Y axis, legend, series label, etc.
  • Drag and drop the chart in to data area of your report and tidy up for better presentation.

The good thing about sparklines is its dynamic behaviour. Since it is located inside data area, it follows whatever grouping setup in rows and column. The sparklines adopts to drill down report setup along with its grouping, like the following example:

collap expand

The most important thing of creating sparklines are data binding and removing unnecessary chart properties. In the following picture, the chart is bounded to Sum(SalesAmount). I removed X and Y axis and also its title. This is a straight forward task by right clicking every property and select disable or delete.

delete

The last step is to add additional column in report table for sparklines container. I use “Total Trend” as presented in the first picture, then drag and drop the chart in to column and tidy up for better visualization. What about source code? Download sample .rdl file from here:

As usual, it needs AdventureWorksDW2008 sample database which freely available from codeplex.

KPI Report with Reporting Services 2008

Reporting Services 2008 brought many enhancements for data visualization. The queen is Gauge, which is ideal tool to create scorecard and KPI. Imagine the report popping up in front of manager with colourful and fancy indicators like this:

thermo1

Gauge is only one among many other things. Charting is more fun than ever, with many 3D effects and customizable areas. I also like new feature such as calculated series that deliver moving average report in minutes. No more complex expression to calculate median or moving average data.

Gauge also comes with many type such as radial type with speedometer style. I can display sales indicator and turn the pointer to red, yellow, or green like this:

gauge1

I did demo and discussion about this topic in Singapore SQL UG meeting on June 25, 2009. As I promised to upload my slide deck, you can grab it here:

Of course I release the source code too for deeper exploration. Apologize that I don’t have enough passion to tidy up the reports for best appearance. It is available in my skydrive:

All reports need AdventureWorks2008 and AdventureWorks2008DW sample, available to download from CodePlex.

Below are some pictures from the meeting:

SQLUG-25Jun 2009-06-25 006

SQLUG-25Jun 2009-06-25 009

PPT from CTU 2009: Reporting with Data Mining

Well, traditional reporting is quite common. It connects to relational database, perform calculation and agregation, then display it in a nice and neat report. What is data mining reporting anyway?

It is also a report, but connects to mining model rather than traditional RDBMS. Example: a model to forecast the customer behavior created in SSAS. It predicts whether a customer will favor buy or not buy toward our product. Then we have another dataset of our potensial customers. We want to predict their behavior, will they favor BUY over not buying?

We can use SQL Reporting Services, connect to decision trees mining model inside SSAS, and use potensial customers data as input. The result is predicted behaviour and probability whether Mr.Bob will BUY (90%) and Mr. John not buy (60%). Another cool tool is Excel Data Mining Add-In. It uses Excel 2007 as data mining client tool, very nice and intuitive for end user. There is a very nice overview how does it work, read it here.

I also presented this tool, together with SSRS data mining reporting at Singapore CTU on May 23, 2009. The crowd were very enthusiast about this guy. Nice tool very end user power user, event for IT Pro.
My PPT can be downloaded here:

Sharepoint – Reporting Services Integration

I did presentation for MaxIT event on May 29, 2009 and one of the interesting discussion was SharePoint integration with Reporting Services. I know that SharePoint is hot here in Singapore. I also did demo on some new features of SSRS 2008 such as tablix and charting. My presentation slide can be downloaded here:

There are several advantages of integrating SSRS with SharePoint:

  • Seamless UI for end user. They do not need to jump from one screen to another to open report and SharePoint dashboard at the same time.
  • All reports are deployed as document library, so it follows all SharePoint library setting. It saves lots of time instead of managing report in separate report manager.
  • All reports are under SharePoint security setting, giving better consolidated administrative from SharePoint perspective
  • Render reports inside web part. It makes building SharePoint dashboard faster and easier.

What do we need to configure this:

  • SharePoint Services 3.0 or MOSS 2007, It’s better if upgraded to SP1 or SP2.
  • SQL Server 2005 Reporting Services with SP2, or Reporting Services 2008.
  • Reporting Services add-in for SharePoint. There are 2 versions of add-in: SSRS 2005 and SSRS 2008.

Configuration can be simple (all in one box) or scale up to separate boxes. Below is the logical architecture if SSRS and SharePoint are installed on separate boxes:

ssrs-sharepoint

Assuming that SharePoint already installed, below are the explanations to do integration.

Install SSRS 2005 + SP2 in the SharePoint box, or separate machine. Just make sure to select “Install Report Server but do not configure” when doing this. The default configuration is native mode instead of SharePoint integrated, so please take note. Once SSRS installed, upgrade to SP2 (minimum) or directly to SP3.

In the case of SSRS 2008, SharePoint integration feature is already built in. Upgrading to SQL 2008 SP1 is recommended but not compulsory. Another improvement of SSRS 2008 is guided installation wizard. Once the installation CD is plugged in, there will be a menu to install SSRS in SharePoint mode instead of native stand alone.

Configure SSRS to integrate with SharePoint. Open SSRS configuration manager and connect to SSRS instance then create a new virtual directory for ReportServer. This should be the address of existing IIS website where the report server to be configured.

reportserversharepoint1

Configuring Windows Service and Web Service identity is straight forward. Use Network Service as identity account if it is a single box installation. In the case of scale up scenario, it needs to provide a dedicated SSRS service account from AD and use it as SSRS identity.

reportserversharepoint2

The next step is to create a new database for ReportServerDB and make sure to specify database as SharePoint integrated mode. It has to connect to existing SQL Server database instance.

reportserversharepoint3

It is not necessary to configure IIS website for Report Manager because SharePoint is our report manager now. Email and execution account configuration can be ignored in the meantime, specially if we do not use automated report delivery by email.

Another part of configuration is inside SharePoint central admin. Install SharePointRS.msi (SharePointRS_X64.msi for 64 bit) in SharePoint box. This package needs to be installed at every front end web server if SharePoint is configured as web farm. By the way, this file is Reporting Services add-in for SharePoint I mentioned earlier. Once installation finished, do IISRESET and open SharePoint Central Admin. A new Reporting Services configuration menu is available.

cassrs0

SharePoint has to know the address of Report Server which is under IIS virtual directory. Security configuration should be in windows integrated mode. This can be done under “Manage integration setting” link.

cassrs1

SharePoint also has to connect to ReportServerDB that already created earlier. Specify the name of SQL Server instance and click OK and specify windows account to connect to SQL Server.

cassrs2

There is another note for multiple boxes scenario: Reporting Services need to have local access to SharePoint object model in order to communicate with SharePoint. It means SharePoint binary has to be installed in SSRS machine, but left it empty without web application. It just needs to join existing SharePoint farm during installation, it is not necessary to create a site collection.

That’s all configuration needed. Now time to test it. Create a new library in SharePoint with the type of Report Library, for example “Sales Report”. Open existing SSRS source code (with Visual Studio of course) and deploy them to SharePoint. The tricky part is now the deployment location has changed. Remember that SharePoint is our report manager now. Below is the deployment configuration in Visual Studio:

vsdeployrs2sharepoint

What is the difference? Now it connects to SharePoint site as report server instead of http://myserver/reportserver. Data source and report folder location should point to address of “Sales Report” which is created earlier. The Sales Report library should display all reports after the deployment completed successfully.

reportdeployed

Clicking “Product Line Sales” bring up SSRS report under SharePoint, nice :).

ssrsinsharepoint

I don’t like full screen report, can we render them as web part?

Yes, report can be rendered as web part, and with all SharePoint flexibility, just drag and drop to any zones to display them. This web part is actually part of SharePointRS.msi installed previously. The name is Reporting Services viewer web part.

addssrswebpart

One page may render multiple web part and display them in a nice dashboard as follow:

reportwebpart

Managing the report is easy. Everything can be done under SharePoint. Click one of the report and java script popup tells us what all related reporting services setting can be done.

sharepointreportadmin

Nice feature eh? Now we have another more reason to implement BI under SharePoint :).

One more thing, Microsoft does provide a comprehensive guide to achieve this integration here.

Slide Deck and Demo on SharePoint + Silverlight

Technorati Tags: ,

This is a quick post for my presentation slide and demos at SharePoint Pro Singapore User Group Meeting last week. I discussed about configuration on SharePoint box to make it Silverlight enabled, and also giving some demos to write Silverlight video player then deploy it to SharePoint.

image

The PPT and demos are available for download from my Skydrive. Enjoy!

Presentation Slide at Singapore CTU 2008

I presented at Community Technology Update 2008, organized by Microsoft Singapore DPE on November 22, 2008. It was a fantastic community event, a place when community members gathered together to share their passion on latest Microsoft Technologies.

Heroes_Banner

My first session at the morning was Web 2.0 Programming with Visual Studio 2008. I presented Web 2.0 term, and what kind of tools available in Visual Studio 2008 to achieve Web 2.0 effects. I was much inspired by DropThings project  by fellow ASP.NET MVP Omar Al Zabir.

The second session was about SQL Server Performance Tools. No, this is not yet another Microsoft product come out. It is a collection of free tools, scripts, and tips to identify server bottleneck and resolve performance problems. My idea was to share hidden tools and script to reveal performance bottleneck. I was presenting about PAL, SQLDiag, server side script and database tuning advisor. I have to give a big credit to Itzik Ben Gan book for collection of server side trace script instead of using graphical Profiler. Both PPTs are available for download from my Skydrive:

Web 2.0 with VS 2008

SQL Server Performance Tools

I am not able to publish my demo code at the moment, because it was running on my real machine at that time, so I need to fine tune and modify some configuration to avoid any problem. Once I finished with the changes, I will update share my demo code here.

Sample Code on SQL Server Security

I spoke on SQL Server User Group Indonesia monthly meeting last month, discussed about a developer perspectives of SQL Server Security. I covered most of the session with some SQL Injection techniques, completed with real sample code in web application.

I started with the awareness that network administrator is not the only person who’s responsible for computer security. Networking guys are only responsible at the network (firewall) and host (OS) level. At the application level, is a developer responsiblity for the software security. Ensure that no single line of code contains a hole, something that can be utilized by an attacker to compromise the system.

These are the summarry for SQL Injection countermeasures:

  • Never use user input as a string concatenation element
  • Avoid string concatenation in SQL statement
  • Use Parameter collection of ADO.NET Command object for parameter parsing
  • Use stored procedure as possible
  • Validate user input, never trust them
  • Client side validation is not enough (java script can be removed)
  • Utilize built in database constraint
  • Change the sa password
  • Remove built in administrator

Some configurations for locking down SQL Server from any vulnerabilities:

  • Disable xp_cmdshell (default ON in SQL2000)
  • Disable OPENROWSET and OPENDATASOURCE (default ON in SQL2000)
  • Don’t enable SQL CLR if not needed
  • Minimize protocol used
  • Disable remote access if not needed
  • All setting can be modified using sp_configure
  • SQL authentication: create user mapping, don’t use the real SQL user
  • Use Application Role if possible

Download the presentation here.
Download the sample code here.