Accessing the tempdb database on Microsoft SQL Server DB instances on Amazon RDS
You can access the tempdb
database on your Microsoft SQL Server DB instances on
Amazon RDS. You can run code on tempdb
by using Transact-SQL through Microsoft SQL
Server Management Studio (SSMS), or any other standard SQL client application. For more
information about connecting to your DB instance, see Connecting to a DB instance running the Microsoft SQL Server database engine.
The master user for your DB instance is granted CONTROL
access to
tempdb
so that this user can modify the tempdb
database
options. The master user isn't the database owner of the tempdb
database. If
necessary, the master user can grant CONTROL
access to other users so that they
can also modify the tempdb
database options.
Note
You can't run Database Console Commands (DBCC) on the tempdb
database.
Modifying tempdb database options
You can modify the database options on the tempdb
database on your Amazon RDS DB
instances. For more information about which options can be modified, see tempdb
database
Database options such as the maximum file size options are persistent after you restart your DB instance. You can modify the database options to optimize performance when importing data, and to prevent running out of storage.
Optimizing performance when importing data
To optimize performance when importing large amounts of data into your DB instance, set the
SIZE
and FILEGROWTH
properties of the tempdb database
to large numbers. For more information about how to optimize tempdb
,
see Optimizing tempdb performance
The following example demonstrates setting the size to 100 GB and file growth to 10 percent.
alter database[tempdb] modify file (NAME = N'
templog
', SIZE=100GB
, FILEGROWTH =10%
)
Preventing storage problems
To prevent the tempdb
database from using all available disk space, set the
MAXSIZE
property. The following example demonstrates setting the
property to 2048 MB.
alter database [tempdb] modify file (NAME = N'
templog
', MAXSIZE =2048MB
)
Shrinking the tempdb database
There are two ways to shrink the tempdb
database on your Amazon RDS DB instance. You
can use the rds_shrink_tempdbfile
procedure, or you can set the
SIZE
property,
Using the rds_shrink_tempdbfile procedure
You can use the Amazon RDS procedure msdb.dbo.rds_shrink_tempdbfile
to shrink the
tempdb
database. You can only call
rds_shrink_tempdbfile
if you have CONTROL
access to
tempdb
. When you call rds_shrink_tempdbfile
, there is
no downtime for your DB instance.
The rds_shrink_tempdbfile
procedure has the following parameters.
Parameter name | Data type | Default | Required | Description |
---|---|---|---|---|
|
SYSNAME |
— |
required |
The logical name of the file to shrink. |
|
int |
null |
optional |
The new size for the file, in megabytes. |
The following example gets the names of the files for the tempdb
database.
use tempdb; GO select name, * from sys.sysfiles; GO
The following example shrinks a tempdb
database file named
test_file
, and requests a new size of 10
megabytes:
exec msdb.dbo.rds_shrink_tempdbfile @temp_filename = N'
test_file
', @target_size =10
;
Setting the SIZE property
You can also shrink the tempdb
database by setting the SIZE
property and then restarting your DB instance. For more information about restarting
your DB instance, see Rebooting a DB instance.
The following example demonstrates setting the SIZE
property to 1024
MB.
alter database [tempdb] modify file (NAME = N'
templog
', SIZE =1024MB
)
Considerations for Multi-AZ deployments
If your Amazon RDS DB instance is in a Multi-AZ Deployment for Microsoft SQL Server with Database Mirroring (DBM) or Always On Availability Groups (AGs), there are some things to consider.
The tempdb
database can't be replicated. No data that you store on your primary
instance is replicated to your secondary instance.
If you modify any database options on the tempdb
database, you can capture
those changes on the secondary by using one of the following methods:
-
First modify your DB instance and turn Multi-AZ off, then modify tempdb, and finally turn Multi-AZ back on. This method doesn't involve any downtime.
For more information, see Modifying an Amazon RDS DB instance.
-
First modify
tempdb
in the original primary instance, then fail over manually, and finally modifytempdb
in the new primary instance. This method involves downtime.For more information, see Rebooting a DB instance.