Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Creating tempdb Files

Updated on 2024-09-30 GMT+08:00

Scenarios

The tempdb system database is a global resource that is available to all users connected to an instance of SQL Server or SQL Database. It is a temporary database that cannot store data permanently. It is used to process intermediate data for various requests in the instance. Physical properties of tempdb in SQL Server are classified into the primary data files (.mdf), secondary data files (.ndf), and log files (.ldf). tempdb is re-created every time SQL Server is started.

There may be some issues or even service interruption if applications frequently create and drop tempdb files, especially in high-concurrency scenarios.

Microsoft recommends that the tempdb files be divided into multiple files. Generally, the number of files depends on the number of vCPUs (logical). If the number of vCPUs is greater than eight, use eight data files and then if contention continues, increase the number of data files by multiples of 4 until the contention is reduced to acceptable levels or make changes to the workload/code.

For more information, see tempdb Database in the Microsoft official website.

Constraints

  • By default, each RDS for SQL Server instance running SQL Server 2008, 2012, or 2014 Edition has one tempdb file, each instance running SQL Server 2016 Edition has four tempdb files, and each instance running SQL Server 2017 Edition has eight tempdb files.
  • Each RDS for SQL Server instance has only one log file no matter which SQL Server Edition they run.

Application Scenario

You need to determine the number of tempdb files to be created based on the instance specifications and scenarios. The following uses an example to show how to create 8 tempdb files for a SQL Server 2014 Enterprise Edition instance with 32 vCPUs.

Prerequisites

  • Visit the Microsoft website and obtain the installation package of SQL Server Management Studio. Double-click the installation package and complete the installation as instructed.
  • You have created an instance with 32 vCPUs running Microsoft SQL Server 2014 Enterprise Edition. For details, see Buy a DB Instance

Procedure

  1. Start SQL Server Management Studio.
  2. Choose Connect > Database Engine. In the displayed dialog box, enter login information.

    Figure 1 Connecting to the server
    Table 1 Parameter description

    Parameter

    Description

    Server name

    Indicates the IP address and database port of the DB instance. Use a comma (,) to separate them. For example: x.x.x.x,8080.
    • The IP address is the EIP that has been bound to the DB instance.
    • The database port is that displayed on the Connectivity & Security page.

    Authentication

    Indicates the authentication mode. Select SQL Server Authentication.

    Login

    Indicates the database account used for accessing the instance. The default administrator account is rdsuser.

    Password

    Indicates the password of the database account.

  3. View the tempdb information.

    • Choose Databases > System Databases> tempdb. Right-click tempdb and choose Database Properties. In the displayed dialog box, view the current tempdb information.
      Figure 2 Viewing current tempdb information
    • You can also run the following SQL statements to query the tempdb information:

      SELECT name AS FileName,

      size*1.0/128 AS FileSizeInMB,

      CASE max_size

      WHEN 0 THEN 'Autogrowth is off.'

      WHEN -1 THEN 'Autogrowth is on.'

      ELSE 'Log file grows to a maximum size of 2 TB.'

      END,

      growth AS 'GrowthValue',

      'GrowthIncrement' =

      CASE

      WHEN growth = 0 THEN 'Size is fixed.'

      WHEN growth > 0 AND is_percent_growth = 0

      THEN 'Growth value is in 8-KB pages.'

      ELSE 'Growth value is a percentage.'

      END

      FROM tempdb.sys.database_files;

      GO

  4. Run the following statements to query the tempdb file name of the current DB instance:

    SELECT name, physical_name

    FROM sys.master_files

    WHERE database_id = DB_ID('tempdb');

    Figure 3 Viewing tempdb file names

  5. On the Files tab in 3, view the paths of tempdb files.

    Figure 4 Viewing tempdb paths

  6. Run the following statements to migrate the tempdb files to D:\RDSDBDATA\DATA and specify the initial size and growth as required.

    USE master;

    GO

    ALTER DATABASE [tempdb] MODIFY FILE (NAME = tempdev, FILENAME = 'D:\RDSDBDATA\DATA\tempdb.mdf', SIZE = 8MB, FILEGROWTH = 64MB);

    GO

    ALTER DATABASE [tempdb] MODIFY FILE (NAME = templog, FILENAME = 'D:\RDSDBDATA\DATA\templog.ldf', SIZE = 8MB, FILEGROWTH = 64MB);

    GO

    Figure 5 Moving tempdb files

  7. On the Instances page of the RDS console, locate the target DB instance and choose More > Reboot in the Operation column to reboot the DB instance.

    You can also click the target DB instance. On the displayed page, click Reboot in the upper right corner of the page.

  8. Run the following SQL statements to check whether the tempdb files are successfully migrated:

    SELECT name, physical_name

    FROM sys.master_files

    WHERE database_id = DB_ID('tempdb');

    Figure 6 Viewing the migration results

  9. Configure the file name, initial size, and growth as required. Add tempdb files using either of the following methods:

    • Adding tempdb files through SQL statements

      Based on the number of vCPUs and tempdb files to be added, set the initial size to 8 MB and file growth to 64 MB.

      USE [master]

      GO

      ALTER DATABASE [tempdb] ADD FILE ( NAME = N'temp2', FILENAME = N'D:\RDSDBDATA\DATA\tempdb2.ndf', SIZE = 8MB, FILEGROWTH = 64MB)

      GO

      ALTER DATABASE [tempdb] ADD FILE ( NAME = N'temp3', FILENAME = N'D:\RDSDBDATA\DATA\tempdb3.ndf', SIZE = 8MB, FILEGROWTH = 64MB)

      GO

      ALTER DATABASE [tempdb] ADD FILE ( NAME = N'temp4', FILENAME = N'D:\RDSDBDATA\DATA\tempdb4.ndf', SIZE = 8MB, FILEGROWTH = 64MB)

      GO

      ALTER DATABASE [tempdb] ADD FILE ( NAME = N'temp5', FILENAME = N'D:\RDSDBDATA\DATA\tempdb5.ndf', SIZE = 8MB, FILEGROWTH = 64MB)

      GO

      ALTER DATABASE [tempdb] ADD FILE ( NAME = N'temp6', FILENAME = N'D:\RDSDBDATA\DATA\tempdb6.ndf', SIZE = 8MB, FILEGROWTH = 64MB)

      GO

      ALTER DATABASE [tempdb] ADD FILE ( NAME = N'temp7', FILENAME = N'D:\RDSDBDATA\DATA\tempdb7.ndf', SIZE = 8MB, FILEGROWTH = 64MB)

      GO

      ALTER DATABASE [tempdb] ADD FILE ( NAME = N'temp8', FILENAME = N'D:\RDSDBDATA\DATA\tempdb8.ndf', SIZE = 8MB, FILEGROWTH = 64MB)

      GO

    • Adding tempdb files through SQL Server Management Studio On the Files tab in 3, click Add.
      Figure 7 Adding tempdb files through the client

  10. After the configuration is complete, reboot the DB instance again by referring to 7.
  11. Repeat 8 to check whether the tempdb files are successfully added.

    Figure 8 Viewing the added tempdb files

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback