Creating a high-performance SQL Server instance Stay organized with collections Save and categorize content based on your preferences.
This tutorial shows how to create a Compute Engine VM instance runningSQL Server that is optimized for performance. This tutorial guides you throughcreating the instance and then configuring SQL Server for optimal performance onGoogle Cloud. You will learn about a number of configuration options thatare available to help you adjust the performance of the system.
This tutorial uses SQL Server Standard Edition 2022, so not every configurationoption presented in this guide works for everyone, and not all of them providenoticeable performance benefits for every workload.
Objectives
- Setting up the Compute Engine instance and disks.
- Configuring the Windows operating system.
- Configuring SQL Server.
Costs
This tutorial uses billable components of Google Cloud,including:
- Compute Engine high-memory instance
- Compute Engine SSD Persistent Disk storage
- Compute Engine Local SSD disk storage
- SQL Server Standard preconfigured image
ThePricing Calculator can generate a costestimate based on your projected usage. The provided link shows the costestimate for the products used in this tutorial, which can cost over 4 dollars(US) per hour and over 3,000 dollars per month.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Make sure that billing is enabled for your Google Cloud project.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Make sure that billing is enabled for your Google Cloud project.
Creating the Compute Engine VM with disks
To create a high-performance SQL Server instance, you must first create a VMinstance with SQL Server and two Persistent Disk volumes.
Persistent Disk considerations
To select the type of Persistent Disk volumes for your VM, review thefollowing considerations:
ALocal SSD disk provides a high-performance location for
tempdb
and the Windows pagefile.There are some important considerations to note when using a Local SSD disk.When you shut down your instance from Windows or reset it by using the API,the Local SSD disk is removed. This action renders the instance unbootable.To get the machine running again, you would need to detach your persistentdisks, create a new instance with them, and then define a new Local SSD disk.After startup you would also need to format the new disk and reboot.Therefore, you shouldn't permanently store critical data on a Local SSD disk,or power off the instance, unless you are prepared to rebuild it.
AnSSD Persistent Disk provides high-performance storage for the database files.
Persistent Disk performance is based on a calculation that uses the number ofCPUs and the size of the disk. With 32 vCPUs and a 1 TB disk, theperformance peaks at 40,000 read operations per second (ops) and 30,000write ops. The total sustained throughput for reads and writes is 800 MB persecond and 400 MB per second respectively. These measurements represent asummation of all the Persistent Disk volumes attached to the virtual machine,including the
C:\
drive. To ensure consistent performance, create aLocal SSD disk and offload all the IOPS needed for the paging file,tempdb
, staging data, and backups.
To read more about disk performance, seeConfigure disks to meet performance requirements.
Creating Compute Engine VM with disks
To create a VM that has SQL Server 2022 Standard preinstalled on Windows Server2022, follow these steps:
In the Google Cloud console, go to theCreate an instance page.
ForName, enter
ms-sql-server
.In theMachine configuration section, selectGeneral Purpose, andthen do the following:
- In theSeries list, clickN2.
- In theMachine type list, clickn2-highmem-16(16vCPU, 128 GB memory).
In theBoot disk section, clickChange, and then do the following:
- On thePublic images tab, click theOperating system list, andthen selectSQL Server on Windows Server.
- In theVersion list, clickSQL Server 2022 Standard on WindowsServer 2022 Datacenter.
- In theBoot disk type list, clickStandard persistent disk.
- In theSize (GB) field, set the boot disk size to50 GB.
- To save the boot disk configuration, clickSelect.
Expand theAdvanced options section, and do the following:
- Expand theDisks section.
To create local disks, clickAdd Local SSD, and then do thefollowing:
- In theInterface list, select the protocol that meets yoursystem's performance requirements.
- In theDisk capacity list, select a disk capacity that supportsthe anticipated size of
tempdb
files. - To finish creating this disk, clickSave.
To create additional disks, clickAdd New Disk.
- Keep theName field unchanged.
- In theDisk source type list, selectBlank disk.
- In theDisk type list, selectSSD persistent disk.
- In theSize field, enter the disk size that can accommodate thedatabase size.
- To finish creating the second disk, clickSave.
To create the VM, clickCreate.
Configuring Windows
Now that you have a working instance running SQL Server, connect to yourinstance and configure the Windows operating system. After that, you learn toconfigure SQL Server in an upcoming section.
Connect to your instance
In the Google Cloud console, go to theVM instances page.
Under theName column, click the name of your instance,
ms-sql-server
.At the top of the instance's details page, click theSet Windows Password button.
Specify a username.
ClickSet to generate a new password for this Windows instance.
Note the username and password so you can log into the instance.
Connect to your instanceby using RDP.
Setting up disk volumes
Create and format the volumes:
- From theStart menu, search for "Computer Management" and then open it.
- UnderStorage section, selectDisk Management.
- When prompted to initialize disks, accept the default selections and clickOK.
Create partition for Local SSD disk(s):
To locate a Local SSD disk, right-click on a disk and selectProperties.The Local SSD disk properties name will be
Google EphemeralDisk
for a SCSIinterface ornvme_card
for an NVMe interface. Both Local SSD disks andpersistent SSDs are marked as havingUnallocated
partitions.If the VM contains only 1 Local SSD drive, follow these steps:
- Under the list of disk drives, right-click the 374.98 GB local SSDdisk and selectNew Simple Volume.
- On the Welcome screen, clickNext to start the disk volumewizard.
- In theSpecify Volume Size step, leave the volume size at thedefault value and clickNext to proceed.
- In theAssign Drive Letter or Path step, chooseP: for thedrive letter and clickNext to proceed.
In theFormat Volume step, change theAllocation unit sizeto 8192 and enter "pagefile" for theVolume label. ClickNext to proceed.
ClickFinish to complete the disk volume wizard.
If the VM contains multiple local SSD drives, follow these steps:
- Under the list of disk drives, right-click the first 374.98 GB localSSD disk and selectNew Striped Volume.
- On the Welcome screen, clickNext to start the disk volumewizard.
In theSelect Disks step, add all the available disks with thesize 383,982 MB to the Selected section. ClickNext to proceed.
In theAssign Drive Letter or Path step, chooseP: for thedrive letter and clickNext to proceed.
In theFormat Volume step, change theAllocation unit sizeto 8192 and enter "pagefile" for theVolume label. ClickNext to proceed.
ClickFinish to complete the disk volume wizard.
Repeat the previous steps to create aNew Simple Volume for the SSD disk,with the following three changes:
ChooseD: for the drive letter.
Set theAllocation unit size to
64k
.For details on selecting an allocation unit size, seeBest practices for SQL Server instances.
Enter
sqldata
for theVolume label.
Moving the Windows paging file
Now that the new volumes are created and mounted, move the Windows paging fileonto the Local SSD disk, which frees up Persistent Disk IOPS and improves the accesstime of your virtual memory.
- From theStart menu, search forView advanced system settings andthen open the dialog.
- Click theAdvanced tab, and in thePerformance section, clickSettings.
- In theVirtual memory section, click theChange button.
- Clear the checkboxAutomatically manage paging file size for all drives. Thesystem should have already set up your paging file on the
C:\
drive, and youneed to move it. - ClickC: and then click theNo paging file radio button.
- Click theSet button.
- To create the new paging file, click theP: drive, and then click theSystem managed size radio button.
- Click theSet button.
ClickOK three times to exit the advanced system properties.
Microsoft Support has publishedadditional tips for virtual memorysettings.
Setting the power profile
Set the power profile toHigh-Performance
instead ofBalanced
.
- From theStart menu, search for "Choose a Power Plan", and then open thepower options.
- Select theHigh Performance radio button.
- Exit the dialog.
Configuring SQL Server
Use SQL Server Management Studio to perform most administrative tasks. Thepreconfigured images for SQL Server come with Management Studio alreadyinstalled. Launch Management Studio and then clickConnect toconnect to the default database.
Moving the data and log files
The preconfigured image for SQL Server comes with everything installed ontheC:\
drive, including the system databases. To optimize your setup,move those files to the newD:\
drive you created. Also remember to createall new databases on theD:\
drive. Because you are using an SSD, you don'tneed to store the data files and log files on separate disk partitions.
There are two ways to move the installation to the secondary disk: using theinstaller or moving the files manually.
Using the installer
To use the installer, runc:\setup.exe
and select a new installation path onyour secondary disk.
Moving the files manually
Move the system databases and configure SQL Server to save the data and logfiles on the same volume:
- Create a new folder named
D:\SQLData
. - Open a Command Window.
Enter the following command to grant full access to
NT Service\MSSQLSERVER
:icaclsD:\SQLData/Grant"NT Service\MSSQLServer:(OI)(CI)F"
Use Management Studio and the following guides tomove your systemdatabasesandchange the default file locations for new databases.
If you plan on usingReport Server features, move theReportServerandReportServerTempDB files as well.
tempdb
files yet because you must first changesome permission settings and then move the DB to the Local SSD volume.After you move the primary configuration database files and restart, you need toconfigure the system to point to the new location for the model and MSDBdatabases. Here is a helper script to run in Management Studio:
ALTER DATABASE model MODIFY FILE ( NAME = modeldev , FILENAME = 'D:\SQLData\model.mdf' )ALTER DATABASE model MODIFY FILE ( NAME = modellog , FILENAME = 'D:\SQLData\modellog.ldf' )ALTER DATABASE msdb MODIFY FILE ( NAME = MSDBData , FILENAME = 'D:\SQLData\MSDBData.mdf' )ALTER DATABASE msdb MODIFY FILE ( NAME = MSDBlog , FILENAME = 'D:\SQLData\MSDBLog.ldf' )
After you execute these commands:
- Use the
services.msc
snap-in to stop the SQL Server database service. - Use the Windows file explorer to move the physical files from the
C:\
drivewhere themaster
database was located to theD:\SQLData
directory. - Start the SQL Server database service.
Setting system permissions
After moving the system databases, modify some additional settings, startingwith permissions for the Windows user account created to run your SQLServer process, which is namedNT Service\MSSQLSERVER
.
Granting theLock Pages in Memory
permission
The group policyLock Pages in Memory
permission prevents Windows frommoving pages in physical memory to virtual memory. To keep physicalmemory free and organized, Windows tries to swap old, rarely modified pages tothe virtual-memory paging file on disk.
SQL Server stores important information in memory, such as table structures,execution plans, and cached queries. Some of this information rarely changes, soit becomes a target for the paging file. If this information gets moved to thepaging file, SQL Server performance can degrade. Granting the group policyLockPages in Memory
permission for SQL Server's service account prevents thisswapping.
Follow these steps:
- ClickStart and then search forEdit Group Policy to open the console.
- ExpandLocal Computer Policy >Computer Configuration >Windows Settings > Security Settings >Local Policies >User Rights Assignment.
- Search for and then double-clickLock pages in memory.
- ClickAdd User or Group.
- Search for "NT Service\MSSQLSERVER".
- If you see multiple names, double-click theMSSQLSERVER name.
- ClickOK twice.
- Keep theGroup Policy Editor console open.
Granting thePerform volume maintenance tasks
permission
By default, when an application requests a slice of disk space from Windows, theoperating system locates an appropriately sized chunk of disk space, and thenzeroes out the entire chunk of disk, before handing it back to the application.Because SQL Server is good at growing files and filling disk space, thisbehavior is not optimal.
There is a separate API for allocating disk space to an application, oftenreferred to asinstant file initialization. Unfortunately, this setting onlyworks for data files, but you will learn in an upcoming section about log-filegrowth. Instant file initialization requires the service account running the SQLServer process to have another group policy permission, calledPerform volumemaintenance tasks
.
- In theGroup Policy Editor, search for "Perform volume maintenance tasks".
- Add the "NT Service\MSSQLSERVER" account as you did in the previous section.
- Restart the SQL Server process to activate both settings.
Setting uptempdb
It used to be a best practice to optimize the SQL ServerCPU usage by creating onetempdb
file per CPU. However, because CPU countshave grown over time, following this guideline can cause performance todecrease. As a good starting point, use 4tempdb
files. As you measure yoursystem's performance, in rare cases you might need to incrementally increase thenumber oftempdb
files to a maximum of 8.
You can run a Transact-SQL (T-SQL) script inside SQL Server Management Studio tomove thetempdb
files to a folder in the `p:` drive.
- Create the directory
p:\tempdb
. Grant full security access to the "NT Service\MSSQLSERVER" user account:
icaclsp:\tempdb/Grant"NT Service\MSSQLServer:(OI)(CI)F"
Run the following script inside SQL Server Management Studio, to move the
tempdb
data file and log file:USE masterGOALTER DATABASE [tempdb] MODIFY FILE (NAME = tempdev, FILENAME = 'p:\tempdb\tempdb.mdf')GOALTER DATABASE [tempdb] MODIFY FILE (NAME = templog, FILENAME = 'p:\tempdb\templog.ldf')GO
Restart SQL Server.
Run the following script to modify the file sizes and create three additional data files for the new
tempdb
.ALTER DATABASE [tempdb] MODIFY FILE (NAME = tempdev, FILENAME = 'p:\tempdb\tempdb.mdf', SIZE=8GB)ALTER DATABASE [tempdb] MODIFY FILE (NAME = templog, FILENAME = 'p:\tempdb\templog.ldf' , SIZE = 2GB)ALTER DATABASE [tempdb] ADD FILE (NAME = 'tempdev1', FILENAME = 'p:\tempdb\tempdev1.ndf' , SIZE = 8GB, FILEGROWTH = 0);ALTER DATABASE [tempdb] ADD FILE (NAME = 'tempdev2', FILENAME = 'p:\tempdb\tempdev2.ndf' , SIZE = 8GB, FILEGROWTH = 0);ALTER DATABASE [tempdb] ADD FILE (NAME = 'tempdev3', FILENAME = 'p:\tempdb\tempdev3.ndf' , SIZE = 8GB, FILEGROWTH = 0);GO
If you use SQL Server 2016, there are 3 additional
tempdb
files to removeafter you do the previous steps:ALTER DATABASE [tempdb] REMOVE FILE temp2;ALTER DATABASE [tempdb] REMOVE FILE temp3;ALTER DATABASE [tempdb] REMOVE FILE temp4;
Restart SQL Server again.
Delete the
model
,MSDB
,master
, andtempdb
files from the originallocation on theC:\
drive.
You successfully moved yourtempdb
files onto the Local SSD disk partition.This move carries some risks, mentioned earlier, but if they are lost for anyreason,SQL Server rebuilds thetempdb
files. Movingtempdb
gives you theadded performance of the Local SSD, and decreases the IOPS used on yourPersistent Disk volumes.
Settingmax degree of parallelism
The recommended default setting formax degree of parallelism
is to match itto the number of CPUs on the server. However, there is a point where executing aquery in 16 or 32 parallel chunks and merging the results is much slower thanrunning it in a single process. If you are using a 16- or 32-core instance, youcan set themax degree of parallelism
value to 8 using the following T-SQL:
USE masterGOEXEC sp_configure 'show advanced options', 1GORECONFIGURE WITH OVERRIDEGOEXEC sp_configure 'max degree of parallelism', 8GORECONFIGURE WITH OVERRIDEGO
Settingmax server memory
This setting defaults to a very high number, but you should set it to the numberof megabytes of available physical RAM, minus a couple gigabytes for operatingsystem and overhead. The following T-SQL example adjustsmax server memory
to100 GB. Modify it to adjust the value to match your instance. Review theServer memory server configuration options documentfor more information.
EXEC sp_configure 'show advanced options', 1GORECONFIGURE WITH OVERRIDEGOexec sp_configure 'max server memory', 100000GORECONFIGURE WITH OVERRIDEGO
Finishing up
Restart the instance one more time to make sure all of the new settings takeeffect. Your SQL Server system is configured and you are ready to create yourown databases and start testing your specific workloads. Review theSQL ServerBest Practices guide for more information on operational activities, other performanceconsiderations, and Enterprise Edition capabilities.
Clean up
After you finish the tutorial, you can clean up the resources that you created so that they stop using quota and incurring charges. The following sections describe how to delete or turn off these resources.
Deleting the project
The easiest way to eliminate billing is to delete the project that you created for the tutorial.
To delete the project:
Deleting instances
To delete a Compute Engine instance:
- In the Google Cloud console, go to theVM instances page.
- Select the checkbox for the instance that you want to delete.
- To delete the instance, click More actions, clickDelete, and then follow the instructions.
Deleting Persistent Disk volumes
To delete the Persistent Disk:
In the Google Cloud console, go to theDisks page.
Select the checkbox next to the name of the disk you want todelete.
Click theDelete button at the top of the page.
What's next
- Load test your SQL Server instance.
- Review theSQL ServerBest Practices guide.
- Explore reference architectures, diagrams, and best practices about Google Cloud.Take a look at ourCloud Architecture Center.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-09 UTC.