Original article: http://blogs.msdn.com/ B /askjay/archive/2010/02/05/how-can-i-create-a-dump-of-sql-server.aspx
You can create a memory dump of the SQL Server process space in several ways. there are using external tools that can help you accomplish this such as userdump.exe, debugdiag.exe, and adplus.exe. in this post, I'll cover 3 common ways to accomplish this for SQL Server: The most common way (sqldumper), using the debugger, and three methods from within SQL server itself.
First, two of these methods will require that you get the process ID (PID) of SQL Server. Here are a few simple ways to do that:
1. From a command window, execute --> Tasklist | find/I "sqlservr"Or from the debugging tools directory execute-> Tlist | find/I "sqlservr"
2. Open Task Manager, and find sqlservr.exe and get the PID from the PID column. If you don't see this column, then select View-> select columns to add it.
3. In a query window inside of SSMs on the instance you wish to dump, execute-> "select serverproperty ('processid ')
4. Get the process ID from the SQL Server errorlog.
Now that you have the PID, you can use one of the following ways to create the dump:
Method 1 (using sqldumper)
TheMost common way(And the way used internally by SQL Server) is to run sqldumper.exe. You will find sqldumper.exe in the following directory for a default installation of SQL Server:
C: \ Program Files \ Microsoft SQL Server \ 100 \ shared
The syntax of sqldumper is as follows:
Sqldumper<Process ID (PID)> <thread ID (TID)> <flags: minidump flags> <sqlinfoptr> <dump directory>
More parameters can be seen with sqldumper /?
The common flags are as follows:
Zero X 0120-Minidump (this is a dump of just the stacks and loaded modules-this is the smallest of the dump types-this is normally the type of dump created automatically by SQL Server during AVS and other exceptions)
Zero X 01100-Full dump (This dumps the entire process space-this can be very large on a 64 bit system or any system with a large amount of memory assigned to SQL Server)
Zero X 8100-Filtered dump (a filtered dump is a dump of all of stolen memory plus certain areas of the buffer pool)
Notice: sqldumper can be used to dump any user mode process-not just SQL Server.
Some examples for sqlserver running under spid 4024 to c: \ Temp:
Minidump: sqldumper 4024 0 0x0120 0 C: \ Temp
Full dump: sqldumper 4024 0 0x01100 0 C: \ Temp
Filtered dump: sqldumper 4024 0 0x8100 0 C: \ Temp
The dump file will have the naming convention of: sqldmip ####. MDMP (I. e. sqldmpr0001.mdmp)
Method 2 (using a debugger)
To dump SQL Server from windbg or other debugger, attach the debugger to the process using the PID:
Once connected, just use the. Dump command which has the following syntax:
Options are:
/A-create dumps for all processes (requires-U)
/B [a]-package dump in a cab and delete dump
/C <comment>-add a comment (not supported in all formats)
/J <ADDR>-provide a jit_debug_info address
/F-create a legacy style full dump
/M [acdffhiprrtuw]-create a minidump (default)
/O-overwrite any existing file
/U-append unique identifier to dump name
". Dump/Ma" is the recommend method of creating a complete memory dump of a user mode process.
So, to create a complete memory dump of the SQL Server to c: \ Temp, execute the following:
. Dump/Ma c: \ temp \ sqldump. dmp
Method 3 (from within SQL Server)
From inside SQL Server, you can create a dump using two different methods. First, to create a manual dump immediately, use the following unmarshented command:
DBCC stackdump
This will create a memory dump in the log directory of your SQL server instance installation. To enable this method to create a full dump, you must turn on trace flags 2544 and 2546:
DBCC traceon (2544,-1)
Go
DBCC traceon (2546,-1)
Go
DBCC stackdump
To create only a minidump, enable trace flag 2546. To create a full-filtered dump, use trace flag 2551.
You can use the unauthenticated ented DBCC dumptrigger command to enable SQL Server to create a dump on the occurrence of an error. you can use the following to enable a full dump on error 802 (there is insufficient memory available in the buffer pool ):
-- Turn On TFs for full dump
DBCC traceon (2544,-1)
Go
DBCC traceon (2546,-1)
Go
-- Set dump trigger for exception 802.
DBCC dumptrigger ('set', 802)
Go
-- View exceptions set for dump trigger
DBCC traceon (3604,-1)
Go
DBCC dumptrigger ('display ')
Go
DBCC traceoff (3604,-1)
Go
-- Turn off dumptrigger for exception 802
DBCC dumptrigger ('clear', 802)
Go
Finally, you can also use the-y parameter on SQL server startup to achieve the same functionality as SQL Server's DBCC dumptrigger. For more information refer:
Http://blogs.msdn.com/psssql/archive/2008/01/10/how-it-works-sql-server-engine-error-messages.aspx
One method not covered in this post is to create the dump from within Task Manager as seen here:
I am not a big fan of this method since you have little control over it. it will create a full dump inside your user profile by default. it is also only available on Windows 2008 and Windows 2008 R2 (or Vista and Windows 7 ). however, it is yet another way to dump the SQL server process.
-Jay