views:

20

answers:

1

I need to create a single trace file that spans several days for one of my databases. This server also restarts every night.

I was told that I should create a script to start the trace every time the server starts but i've been having trouble finding information on just what my script should look like to accomplish what it needs to do. This is the only resource I've come across for the sp_trace_create stored proc.

Can anyone help me come up with a script that will create a trace file that spans several days with the server restarting? My end goal is to pass this trace file to the DTA to get some suggestions for indexing.

+2  A: 

Define the trace in SQL Profiler, then script out the trace definition (File/Export/Script Trace Definition), see How to: Create a Transact-SQL Script for Running a Trace (SQL Server Profiler).

the server restart part is a bit trickier though. You can either modify the default trace (I would strongly recommend against it), you can create a SQL Agent job to create the script, or you could start the trace from a auto-start-up procedure, see Automatic Execution of Stored Procedures. I would use auto-start-up procedures

Remus Rusanu
So if i run my script on day2 with the same filename, it will append to the end of yesterdays results, not create a new trace file?
Abe Miessler
Afaik you need to manage the filename part yourself, using the same file name will overwrite.
Remus Rusanu
Hmmm, do you know if it's possible to pass multiple trace files to DTA for analysis?
Abe Miessler
Not sure. I think it is, but you better verify it. DTA also supports trace *tables*, and those you can build from multiple trace files.
Remus Rusanu
As part of your "start a trace on SQL Server startup", you may need to include code to manage the output files "left behind" when the service stopped. Appending a datetime (such as MyTraceFile_20100222-1302, where that was when the file name was modified) might be simplest.
Philip Kelley