2025-06-01

Set Windows dump file

Investigating a memory leak we have to get a full memory dump under certain conditions. Setting the Windows pagefile is descriped in the post „Set Windows pagefile size“.

Dump File

  • Relocate; configuration, test
  • Registry (PS)
  • CIM/WMI (PS)

There are six differet levels of Windows debugging information, which can be viwed and set in Windows System Properties:

(Windows System Properties > Advanced > Startup and Recovery)

Windows Registry

The current path to the Windows dump file is in the Registry. This can be viewed and changed in Registry Editor (RegEdit):

(Registry Editor: Windows Dump File path)

The path to the registry keys is:
HKLM\SYSTEM\CurrentControlSet\Control\CrashControl\.

Get and Set

Get the Dump File with path:
$DumpFile = (Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CrashControl -Name DumpFile).DumpFile
The result is a simple string (System.String) with the default value „%SystemRoot%\MEMORY.DMP“.

Set the Dump File by a string with the complete value
[string]$DumpfileName = 'F:\MEMORY.DMP'
Set-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CrashControl -Name DumpFile -Value $DumpfileName

The new value will be effective with the next boot of the computer (host).

Generate dump

Get SysInternals NotMyFault.exe and start a console as administrator. Run notmyfault64.exe

... and click "Crash". This will create a "Blue Screen Of Death" (BSOD)

The collection will take several minutes.

When Windows start again and you log on there is a message from the Shutdown Event Tracker

It has no technical consequense so you can just click "Cansel".

The dump file is placed on the custom location given above. To analyze the dump file you should move it to a workstation with tools like WinDBG.

Reference

Microsoft: Overview of memory dump file options for Windows

SevenForums.com: Dump File – Change Default Location

2025-02-24

Set Windows pagefile

When troubleshooting memory issues it sometimes is necessary to change the Windows pagefile to something different that the default settings. In this case I would like the pagefile to have the same size as the amount of physical memory and be placed on another drive.

(Default Windows pagefile)

Add custom pagefile

To disable „Automatically manage paging file size for all drives“ WMI can be used with the Win32_ComputerSystem class. I use it with a WMI CmdLet and not a CIM CmdLet as the put-method does not work with a CIM CmdLet.

$PageFile = Get-WmiObject -Class Win32_ComputerSystem -EnableAllPrivileges
$PageFile.AutomaticManagedPagefile = $false
$PageFile.put() | Out-Null

When the automation is disabled then the pagefile can be configured. In this case I am setting Initial and Maximum size both to the amount of physical memory. It is recommend (1) that the max pagefile is set to the amount of physical memory plus 257 MB. All this can be done with CIM and WMI CmdLets. The memory size from Win32_PhysicalMemory is in Bytes where the properties to Win32_PageFileSetting are in MB and this is why I convert to MB in the script.

$PhysicalMemory = Get-CimInstance -ClassName Win32_PhysicalMemory
[int]$PageFileSize = 0
foreach ( $Device in $PhysicalMemory ) { $PageFileSize += $Device.Capacity/1MB }
$PageFileSize += 257
"Setting PageFile size to $PageFileSize MB..."

$PageFileSet = Get-WmiObject -Class Win32_PageFileSetting
#$PageFileSet | fl *
$PageFileSet.InitialSize = $PageFileSize
$PageFileSet.MaximumSize = $PageFileSize
$PageFileSet.Put() | Out-Null

(Windows pagefile custom configuration)

If the server is with NUMA configuration then Win32_PhysicalMemory will return an array of memory devices. This is why I traverse the output with foreach. In my case the computer is a virtual machine with eight vCores on eight vSockets and it looks like Windows Server (2016) split that in four vNUMA nodes as I get an array of four elements from Win32_PhysicalMemory. My workstation is the host and runs with one 12C/24T processor.

There must be enough free storage. If that is not available the Win32_PageFileSetting.Put() will fail with this not usefull message:

Exception calling "Put" with "0" argument(s): "Value out of range "
At line:12 char:1
+ $PageFileSet.Put() | Out-Null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

To activate the configuration the server needs a reboot.

(Windows pagefile custom configuration activated)

The custom pagefile is added in the right place. But the default pagefile still exist.

Remove default pagefile

The default pagefile is removed with the method Delete() to the specific selected default pagefile by a WQL statement.

$defaultPageFile = Get-WmiObject -Query "SELECT * FROM Win32_PageFileSetting WHERE Name = 'C:\\pagefile.sys'"
#$defaultPageFile | fl *
$defaultPageFile.Delete()

This takes effect with another reboot. This reboot also remove the file "pagefile.sys" from the root of the C-drive.


(Windows default pagefile deleted)

The methods to a WMI object like from Win32_PageFileSetting above does not show with Get-Member. But the documentation to the interface IWbemClassObject lists and describe the general methods to a WMI object.

Notes

(1) Microsoft: Overview of memory dump file options for Windows > Complete memory dump.

History

2025-06-01 : Custom pagefile and default pagefile are differelt.

2025-04-29 : 257 MB addition to pagefile size with reference to (1).

2025-02-24 : Post created

2025-01-05

The obscure star-database

To play around with some obscrure naming possibilities in SQL Server I create the star-database. The name has nothing to do with the data warehouse star-schema pattern. The name is because the database is named with the star character (*).

CREATE DATABASE [*]
    ON PRIMARY ( NAME = N'star_data', FILENAME = N'L:\SSDB2019\Data\star_data.mdf', SIZE = 8MB, FILEGROWTH = 8MB )
    LOG ON ( NAME = N'star_log', FILENAME = N'L:\SSDB2019\TransLog\star_log.ldf', SIZE = 8MB, FILEGROWTH = 8MB );

The database is created on specific directory as inplicit default path using only the database name does not work. This was expected. Using the star-character as name requires me to wrap the name in [].

In the star-database I then create a star-schema.

USE [*];
GO
CREATE SCHEMA [*] AUTHORIZATION [dbo];

... and then a star-table.

CREATE TABLE [*].[*]
(
    [*] bigint NOT NULL IDENTITY (0, 2),
    [%] nvarchar(42) NULL,
    [<] int null,
    [>] int null
);
GO
ALTER TABLE [*].[*] ADD CONSTRAINT
    [PK_star] PRIMARY KEY CLUSTERED 
    ([*]) ON [PRIMARY];

The column names are are almost as obscure as the other names. And then I insert a few rows.

INSERT INTO [*].[*] ([%],[<],[>])
VALUES
    (N'række0', 1000, -1000),
    (N'rÆkke1', 10, -100),
    (N'räkke2', 237, 7);

Then I can select the table in different ways, where the syntax is quite important to the output.

SELECT [*] FROM [*].[*];
SELECT * FROM [*].[*];
SELECT COUNT(*) AS [**] FROM [*].[*];

The first two statements visually looks similar, but the [] makes quite a difference. Adding some WHERE-clauses also adds to the fun.

SELECT * FROM [*].[*] WHERE [%] LIKE '%ä%';
SELECT * FROM [*].[*] WHERE [<]<500;
SELECT * FROM [*].[*] WHERE [>]<0;

The script is in SQLAdmin Github (star_database.sql). Next round could be adding more fun with unicode...

The obscure master-database

The master database is well known. And creating a database with a similar name can make things obscure or unexpected. Playing with adding space before or after "master" is only partly possible. Adding a space after the name as [master ] does not work and gives the error "Msg 1801, Level 16, State 3, Line 8 Database 'master ' already exists. Choose a different database name.". But adding a space before like [ master] does work.

CREATE DATABASE [ master] ON  PRIMARY 
( NAME = N'master0_data', FILENAME = N'L:\SSDB2019\Data\master0_data.mdf', SIZE = 8MB, FILEGROWTH = 8MB )
LOG ON 
( NAME = N'master0_log', FILENAME = N'L:\SSDB2019\TransLog\master0_log.ldf', SIZE = 8MB, FILEGROWTH = 8MB );

Adding other characters known from other parts of a database can add to the obscure situation.

CREATE DATABASE [master.] ON  PRIMARY 
( NAME = N'master_dot_data', FILENAME = N'L:\SSDB2019\Data\master_dot_data.mdf', SIZE = 8MB, FILEGROWTH = 8MB )
 LOG ON 
( NAME = N'master_dot_log', FILENAME = N'L:\SSDB2019\TransLog\master_dot_log.ldf', SIZE = 8MB, FILEGROWTH = 8MB );
GO

CREATE DATABASE [master.dbo] ON  PRIMARY 
( NAME = N'master_dbo_data', FILENAME = N'L:\SSDB2019\Data\master_dbo_data.mdf', SIZE = 8MB, FILEGROWTH = 8MB )
 LOG ON 
( NAME = N'master_dbo_log', FILENAME = N'L:\SSDB2019\TransLog\master_dbo_log.ldf', SIZE = 8MB, FILEGROWTH = 8MB );

The script file with the obscure master databases is also in SQLAdmin Github in obscure_master_database.sql.

2025-01-01

Top-ten posts 2024

2024 was a year with fewer posts than planned - again. As each post is like a personal refined note on a specific situation this signals that I am working less with specific technical incidents. My day is more filled with long-term considerations and actions.

This is the top-ten list of my posts on the 2024 statistics.

RankMoveRank 2023TitleViewsCreated
101 SqlBulkCopy with PowerShell18502017-07-30
2+13 ISO 8601 date formatting using PowerShell3342008-08-14
3+710 Audit Log for Analysis Services2842014-01-08
4+48 Start shared HTA with PowerShell2582012-09-13
5> 6> 10 Add SQL Agent job step with tokens in output file name2382023-02-14
6+17 DBCC CHECKDB with PowerShell2102014-10-09
7> 4> 10 MSDTC Operations1172022-11-29
8> 3> 10 xp_instance_regwrite syntax1752010-09-15
9> 2> 10 Database version1242009-09-26
10-55 SQL Server Agent schedule owner982010-02-08

With a total of 39500 views in 2024 the top-ten posts is with 3748 views about 9 % of the views this year. The all time number of views is 402741.

This year there are both repeats and new posts on the top-ten. The number one post on SqlBulkCopy with PowerShell is sovereign again this year. There must be a link somewhere… I am surprised to see the post Database version as it is both rather old and on a very specific and rare subject.

Former Top-ten

My first post on this blog was published 2008-08-13, and many posts are irrelevant today. But I still think it is a good exercise to write each post as it gives me a option to review, refine and improve a description or solution.

Pages

TitleViews
DBA SQL Server Tools184
DBA Security64
DBA Litterature52
Microsoft Resources45

I think that the blog pages should be migrated to the SQLAdmin DK site. I am rewriting the entire site, and might take this migration into the rewrite.