Stay organized with collections Save and categorize content based on your preferences.
MySQL | PostgreSQL | SQL ServerThis page describes management of the tempdb database in Cloud SQL.
The tempdb database is a system database that holds many objects, including temporary tables, stored procedures, and more. In your instances, you can perform common operations on this database.
A tempdb database is recreated each time an instance is restarted. To prevent the loss of user permissions, Cloud SQL provides permissions to the sqlserver
user after an instance is restarted.
The sqlserver
user has the ALTER permission for managing the tempdb database options.
For more information about managing this resource, see the tempdb database page.
Manage tempdb filesAfter you connect to an instance, the sqlserver
user can manage the tempdb files.
The user has ALTER permission on the tempdb database, which lets them control settings for the number of files and more. Some example operations include the following:
ALTER DATABASE [tempdb] ADD FILE
ALTER DATABASE [tempdb] REMOVE
The following sections describe methods used to control the size of files in the tempdb
database.
For more information about these methods, see Shrink the tempdb database.
Change file sizes in tempdbTo control the size of files in the tempdb database, use the ALTER DATABASE
statement. For more information, see ALTER DATABASE (Transact-SQL) File and Filegroup Options.
msdb.dbo.gcloudsql_tempdb_shrinkfile
is a stored procedure you can use to shrink an individual file in the tempdb
database.
This stored procedure provides all the same benefits of the DBCC SHRINKFILE
command.
DBCC SHRINKFILE
documentation.
The following are example uses of the msdb.dbo.gcloudsql_tempdb_shrinkfile
stored procedure and its parameters, executed from the Cloud SQL Studio:
Default option
msdb.dbo.gcloudsql_tempdb_shrinkfile @filename = 'FILENAME'
Where:
tempdev
.This command executes the following SQL Server commands:
USE tempdb
DBCC SHRINKFILE (@filename)
EMPTYFILE
msdb.dbo.gcloudsql_tempdb_shrinkfile @filename = 'FILENAME', @empty_file=EMPTY_FILE_INT
Where:
EMPTYFILE
is passed as an option. This option takes priority over other parameters.This command executes the following SQL Server commands:
USE tempdb
DBCC SHRINKFILE (@filename, EMPTYFILE)
Target size
msdb.dbo.gcloudsql_tempdb_shrinkfile @filename = 'FILENAME', @target_size=TARGET_SIZE_INT
Where:
DBCC SHRINKFILE
command any value that is greater than or equal to zero. For example, 10
.This command executes the following SQL Server commands. The integer 10 is included as an example:
USE tempdb
DBCC SHRINKFILE (@filename, 10)
Target size and truncate only
msdb.dbo.gcloudsql_tempdb_shrinkfile @filename = 'FILENAME', @target_size=10, @truncateonly=TRUNCATE_ONLY_INT
Where:
TRUNCATEONLY
is passed as an option. Target size is ignored if TRUNCATEONLY
is passed. This option takes priority over NOTRUNCATE
.This command executes the following SQL Server commands:
USE tempdb
DBCC SHRINKFILE (@filename, 10, TRUNCATEONLY)
Target size and no truncate option
msdb.dbo.gcloudsql_tempdb_shrinkfile @filename = 'FILENAME', @target_size=10, @no_truncate=NO_TRUNCATE_INT
Where:
NOTRUNCATE
is passed as an option.This command executes the following SQL Server commands:
USE tempdb
DBCC SHRINKFILE (@filename, 10, NOTRUNCATE)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4