Limit resources available to query in SQL Server - sql

I want to limit the system resources available to queries run by specific users in SQL Server 2008.
Some queries are seemingly running away with all the resources of the machine causing the server to become unresponsive.
My thought process is that if there is a way to cap the amount of resources (mem/cpu cycles/bw) a query can grab, this problem would go away.
Is this possible? Are there better techniques to accomplish this?
This is MS Sql Server 2008,

If you're running the Enterprise Edition, you could take a look at the Resource Governor.

Related

SQL Server Express Casues CPU to Peg at 100% on Single Core Tablet

I am running an instance of SQL Server Express on an old underpowered tablet PC used for a special purpose application. Periodically the SQL Server process kicks in and hammers the CPU at 100% bringing the application to a halt. (Technically, it doesn't halt, it just slows it down to the point where key processes time-out.) It will be another two or three years before the hardware is replaced so that's not an option. Is there a way to throttle SQL Server Express?
There are a few techniques to identify CPU-hogging activity on MSSQL, but since your box is completely unresponsive at the time, you have few options. Using SQL Profiler to run a background trace logging to a table or file might be your best bet.
Until very recently, you needed a paid version of MSSQL to use Profiler, however MS now includes Profiler with MSSQL Express 2012 SP1. Here's a direct download link:
http://www.microsoft.com/en-us/download/details.aspx?id=35579
(Note, you can probably install Profiler without upgrading your MSSQL server instance, if you don't want to).
If you've never used Profiler to diagnose CPU-hogging queries before, here's how I would suggest going about it:
new trace > connect to your MSSQL instace
make sure the "CPU" column is selected
make sure both the "started" and "completed" events for all the queries (Statement/Query/Batch/Procedure/etc) are checked.
Use a "column filter" to only show events where there is a value in the "CPU" column
Select a name for the trace, and a destination (table or .TRN file)
Start the trace and leave it running
After experiencing the CPU issue, once your box recovers: open the trace results, paying particular attention to the CPU column, and the date/time the 100% utilization started. Here's a link with more about using Profiler to analyze traces:
http://msdn.microsoft.com/en-us/library/ms175848.aspx

Displaying heavy SQL query intermediate results

I am using SQL Server 2008 and SQL Server Management Studio.
I need to run a heavy SQL query looking through a large number of rows and doing XQuery selection. I have had to stop the execution because it ran for over 30 minutes and it apparently causes timeouts in the software system using the database.
Is there any way of showing the results as they are found instead of in the end, or can I even get some live statistics on the load?
Yes, the WITH FAST query hint allows this kind of behaviour.... it gives you a start, but the overall run time may be longer.
Andy Warren's videos are always worth watching: http://www.sqlshare.com/UsingtheOPTIONFASTQueryHint_819.aspx
Some old guidance from 2006: http://blogs.msdn.com/b/queryoptteam/archive/2006/05/03/589529.aspx

Possible Server Improvements?

I need an expert insight to my problem. most of my experience is development so i dont have enough grasp regarding server issues or maintenance. Main problem is when traffic is high request to this SQL server times out. there are several applications connecting to this server, some are web some are windows app. i would like to know if i need to do hardware upgrade(more ram, more hdisk space and how much of each is enough) or SQL server maintenance (rebuilding index, SP enhancement, denormalization etc.) or both?
OK first let me give you some specs of the server i'm having trouble with.
OS: MS Windows Server 2003 Standard
Version: 5.2.3790 SP 1 Build 3790
System Type: x64-based PC
Processor: EM64T Family 6 Model 15 Stepping 6 GenuinIntel ~2993 Mhz
RAM: 8gb
free C: space: 400mb
SQL Server Soft. Ver.: Sql Server 2005 Developer Edition
hope info above is enough for a diagnosis. my main concern initially is the available space in c:. also i'm looking at the RAM, i use perfmon and when traffic is high its reaching its max. as for CPU i have no idea but sometimes its running at 100% but its not always like that so i think its normal.
next question i think will be pointless because i cant give you sql db details but i will ask anyway. Will reindexing help or SP optimazation and to what extent? db is at 50+gb now
do we need a new server(hardware)?
Will Updating the sql server software help? from 2005 to 2008? is there an issue when your SQL server prod is only dev edition?
when you have an issue like this what could be the default fix or quick fix if there are any..
I hope an experienced Sys. Ad. or DBA or some programming god have pitty on me and enlighten me regarding this problem
Thanks in advance.
The first step would be to provide more useful information in your question. How does the server behave under pressure.
Use perfmon and or Sql Profiler http://msdn.microsoft.com/en-us/library/ms187929.aspx to log a number of data points while it is under load.
Also see Performance tuning with SQL Server and https://serverfault.com/questions/4700/how-to-do-periodic-sql-server-performance-monitoring-and-troubleshooting

SQL Server 2008 express performance in production environment?

I am about to move servers and i was talking to somebody and they suggested using sql server express 2008 installed on the servers. I have full access to the server.
Does this express engine work at the same speed (performance) as a true sql server 2008?
I know about the limitations i..e max 4 GB per DB ... and max 1 GB of ram... Considering the server has 2GB installed and is shared with windows... i don't see this being a problem but would love to hear some feedback..
I have around 4 dbs .. and they have maybe 4 users logged into them at the same time, its not a great deal of use really...
What i really trying to mesure up is if i should installed SQL SERVER 2008 FULL version on the server or express..
Any help with a choice would be really helpful.
It appears express uses the same DB engine as the FULL version ...
I don't need any clever replication, clustering or things like that...
But i want to go down the right path ...
Any help really appreciated
Express is the same code as the other SQL editions (Workgroup, Standard, Enterprise/Developer and Data Center). The only different code base is the 'CE' edition, that is based on the mobile SQL CE code. Express has the restrictions you already enumerated (DB size, RAM) and also is using only one scheduler, so in effect will use only one CPU core. Also certain features are restricted in Express, like certain replication scenarios. The biggest advantage is that customers can start with Express and if they out-grow its capabilities they can swap in a higher edition without any application change, the database files are interchangeable between all editions, including Express.
Its the same engine, but I found you have to fight it all the way in making it anything but a desktop-environment database, from management to tcpip configuration, etc. And of course, it has built in limits on database size and resource usage. Once it is configured the way you want though, it runs fine. In real production settings I find the lack of SSIS quite the killer, though.
So the bottom line is that it is usable, but not great. You might also consider the Workgroup edition, which is reasonably priced and less limited, but of course it is more expensive than free.
Just to add to this SQL Express 2008 R2 can use multiple cores (but only 1 CPU).
You'll probably be fine with Express. It's the same basic engine. If you ever want to upgrade, the process should be rather painless.
you should be fine, performance should be similar to full version in your case since your databases are small

Logging ALL Queries on a SQL Server 2008 Express Database?

Is there a way to tell SQL Server 2008 Express to log every query (including each and every SELECT Query!) into a file?
It's a Development machine, so the negative side effects of logging Select-Queries are not an issue.
Before someone suggests using the SQL Profiler: This is not available in Express (does anyone know if it's available in the Web Edition?) and i'm looking for a way to log queries even when I am away.
SQL Server Profiler:
File → New Trace
The "General" Tab is displayed.
Here you can choose "Save to file:" so its logged to a file.
View the "Event Selection" Tab
Select the items you want to log.
TSQL → SQL:BatchStarting will get you sql selects
Stored Procedures → RPC:Completed will get you Stored Procedures.
More information from Microsoft: SQL Server 2008 Books Online - Using SQL Server Profiler
Update - SQL Express Edition:
A comment was made that MS SQL Server Profiler is not available for the express edition.
There does appear to be a free alternative: Profiler for Microsoft SQL Server 2005 Express Edition
There is one more way to get information about queries that has been executed on MS SQL Server Express described here.
Briefly, it runs smart query to system tables and gets info(text, time executed) about queries(or cached query plans if needed). Thus you can get info about executed queries without profiler in MSSQL 2008 Express edition.
SELECT deqs.last_execution_time AS [Time], dest.TEXT AS [Query]
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY deqs.last_execution_time DESC
…Late answer but I hope it would be useful to other readers here…
Using SQL Server Express with advanced auditing requirements such as this is not really optimal unless it’s only in development environment.
You can use traces (www.broes.nl/2011/10/profiling-on-sql-server-express/) to get the data you need but you’d have to parse these yourself.
There are third party tools that can do this but their cost will be quite high. Log explorer from ApexSQL can log everything but select and Idera’s compliance manager will log select statements as well but it’s cost is a lot higher.
You can log changes. SQL Server 2008 will make this especially easy with Change Data Capture. But SQL Server isn't very good at logging SELECTs.
It is theoretically possible with the profiler, but it will kill your performance. You might "get away with it" on your desktop, but I think you'll notice your machine acting slow enough to cause problems. And it definitely won't work after any kind of deployment.
One important point a couple others have missed already: unless they changed something for 2008 I didn't hear about, you can't trigger a SELECT.
Just for the record, I'm including the hints to use DataWizard's SQL Performance Profiler as a separate answer since it's really the opposite to the answer pointing at SQL Server Profiler.
There is a free trial for 14 days, but even if you need to buy it, it's only $20 for 3 servers (at the moment of writing, 2012-06-28). This seems more than fair to me considering the thousands everybody using SQL Server Express edition has saved.
I've only used the trial so far and it offers exactly what the OP was looking for: a way to trace all queries coming in to a specific database. It also offers to export a trace to an XML file. The paid version offers some more features but I haven't tried them yet.
Disclaimer: I'm just another developer messing with DBs from time to time and I'm in no way affiliated with DataWizard. I just so happened to like their tool and wanted to let people know it existed as it's helped me out with profiling my SQL Server Express installation.
I would either use triggers or use a third party software such as Red Gate to check out your SQL log files.
Seems that you can create traces using T-SQL
http://support.microsoft.com/kb/283790/
That might help.
The SQL query below can show simple query logs:
SELECT last_execution_time, text
FROM sys.dm_exec_query_stats stats
CROSS APPLY sys.dm_exec_sql_text(stats.sql_handle)
ORDER BY last_execution_time
This is how it looks like below: