Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
MySQL | PostgreSQL | SQL Server
Nesta página, descrevemos o gerenciamento do banco de dados tempdb no Cloud SQL.
O banco de dados tempdb é um banco de dados do sistema que tem muitos objetos, incluindo
tabelas temporárias, procedimentos armazenados e muito mais. Nas instâncias, é possível
executar operações comuns nesse banco de dados.
Um banco de dados temporário será recriado sempre que uma instância for reiniciada. Para evitar
a perda das permissões do usuário, o Cloud SQL fornece permissões ao usuário do
sqlserver depois que uma instância é reiniciada.
Visão geral
O usuário do sqlserver
tem a permissão ALTER para gerenciar as opções de banco de dados tempdb.
Para mais informações sobre como gerenciar esse recurso, consulte a página banco de dados tempdb.
Gerenciar arquivos tempdb
Depois de se conectar a uma instância, o
usuário do sqlserver pode gerenciar os arquivos tempdb.
Número de arquivos
O usuário tem permissão ALTER no banco de dados tempdb, o que permite controlar
as configurações do número de arquivos e muito mais. Alguns exemplos de operações incluem o seguinte:
ALTER DATABASE [tempdb] ADD FILE
ALTER DATABASE [tempdb] REMOVE
Tamanho do arquivo
As seções a seguir descrevem os métodos usados para controlar o tamanho dos arquivos no
banco de dados tempdb.
msdb.dbo.gcloudsql_tempdb_shrinkfile é um procedimento armazenado
que pode ser usado para reduzir um arquivo individual no banco de dados tempdb.
Esse procedimento armazenado oferece todos os mesmos benefícios do comando
DBCC SHRINKFILE.
Confira a seguir exemplos de uso do procedimento armazenado msdb.dbo.gcloudsql_tempdb_shrinkfile e dos parâmetros dele, executados no Cloud SQL Studio:
TARGET_SIZE_INT: um número inteiro que representa o tamanho de destino do arquivo em megabytes. Transmite ao comando DBCC SHRINKFILE qualquer valor
maior ou igual a zero. Por exemplo, 10.
Esse comando executa os seguintes comandos do SQL Server. O número inteiro 10 é incluído como um exemplo:
TRUNCATE_ONLY_INT: aceita um valor inteiro de 0 ou 1.
Se definido como 1, TRUNCATEONLY será transmitido como uma opção. O tamanho de destino é ignorado se TRUNCATEONLY for transmitido. Essa opção tem prioridade sobre NOTRUNCATE.
Esse comando executa os seguintes comandos do SQL Server:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[],[],null,["# Manage a tempdb database\n\n\u003cbr /\u003e\n\nMySQL \\| PostgreSQL \\| SQL Server\n\n\u003cbr /\u003e\n\nThis page describes management of the tempdb database in Cloud SQL.\n\nThe tempdb database is a system database that holds many objects, including\ntemporary tables, stored procedures, and more. In your instances, you can\nperform common operations on this database.\n\nA tempdb database is recreated each time an instance is restarted. To prevent\nthe loss of user permissions, Cloud SQL provides permissions to the `sqlserver`\nuser after an instance is restarted.\n\nOverview\n--------\n\nThe `sqlserver` [user](/sql/docs/sqlserver/users)\nhas the ALTER permission for managing the tempdb database options.\n\nFor more information about managing this resource, see the [tempdb database](https://docs.microsoft.com/en-us/sql/relational-databases/databases/tempdb-database)\npage.\n\nManage tempdb files\n-------------------\n\nAfter you [connect](/sql/docs/sqlserver/connect-overview) to an instance, the\n`sqlserver` [user](/sql/docs/sqlserver/users) can manage the tempdb files.\n\nNumber of files\n---------------\n\nThe user has ALTER permission on the tempdb database, which lets them control\nsettings for the number of files and more. Some example operations include the\nfollowing:\n\n- `ALTER DATABASE [tempdb] ADD FILE`\n- `ALTER DATABASE [tempdb] REMOVE`\n\n| **Note:** See [Physical properties of tempdb in SQL Server](https://docs.microsoft.com/en-us/sql/relational-databases/databases/tempdb-database?view=sql-server-ver15#physical-properties-of-tempdb-in-sql-server), which includes recommendations related to these settings. Review the information about the number of tempdb data files that would correspond to a given number of logical processors. By default, Cloud SQL creates a minimum of eight files for instances that have greater than or equal to eight logical processors. As included in those recommendations, if the number of logical processors is fewer than or equal to eight, the number of files created is equal to the number of logical processors.\n\nFile size\n---------\n\nThe following sections describe methods used to control the size of files in the\n`tempdb` database.\n\nFor more information about these methods, see\n[Shrink the tempdb database](https://learn.microsoft.com/en-us/sql/relational-databases/databases/shrink-tempdb-database?view=sql-server-ver16).\n\n### Change file sizes in tempdb\n\nTo control the size of files in the tempdb database, use the `ALTER DATABASE`\nstatement. For more information, see\n[ALTER DATABASE (Transact-SQL) File and Filegroup Options](https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-database-transact-sql-file-and-filegroup-options?redirectedfrom=MSDN&view=sql-server-ver15).\n\n### Shrink individual file size\n\n`msdb.dbo.gcloudsql_tempdb_shrinkfile` is a [stored procedure](https://learn.microsoft.com/en-us/sql/relational-databases/stored-procedures/stored-procedures-database-engine?view=sql-server-ver16)\nyou can use to shrink an individual file in the `tempdb` database.\n\nThis stored procedure provides all the same benefits of the\n[`DBCC SHRINKFILE`](https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-shrinkfile-transact-sql?view=sql-server-ver16)\ncommand.\n| **Caution:** Avoid using shrinkfile operations as a part of regular maintenance; only use when necessary. For more information, see [`DBCC SHRINKFILE`](https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-shrinkfile-transact-sql?view=sql-server-ver16) documentation.\n\nThe following are example uses of the `msdb.dbo.gcloudsql_tempdb_shrinkfile`\nstored procedure and its parameters, executed from the [Cloud SQL Studio](/sql/docs/sqlserver/manage-data-using-studio):\n\n1. Default option\n\n ```sql\n msdb.dbo.gcloudsql_tempdb_shrinkfile @filename = '\u003cvar translate=\"no\"\u003eFILENAME\u003c/var\u003e'\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eFILENAME\u003c/var\u003e: the name of the file to be shrunk. For example, `tempdev`.\n\n This command executes the following SQL Server commands:\n - `USE tempdb`\n - `DBCC SHRINKFILE (@filename)`\n2. `EMPTYFILE`\n\n ```sql\n msdb.dbo.gcloudsql_tempdb_shrinkfile @filename = '\u003cvar translate=\"no\"\u003eFILENAME\u003c/var\u003e', @empty_file=EMPTY_FILE_INT\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eEMPTY_FILE_INT\u003c/var\u003e: an integer value that is either 0 or 1. If 1, then `EMPTYFILE` is passed as an option. This option takes priority over other parameters.\n\n This command executes the following SQL Server commands:\n - `USE tempdb`\n - `DBCC SHRINKFILE (@filename, EMPTYFILE)`\n3. Target size\n\n ```sql\n msdb.dbo.gcloudsql_tempdb_shrinkfile @filename = '\u003cvar translate=\"no\"\u003eFILENAME\u003c/var\u003e', @target_size=TARGET_SIZE_INT\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eTARGET_SIZE_INT\u003c/var\u003e: an integer that represents the target size of the file in megabytes. Passes to the `DBCC SHRINKFILE` command any value that is greater than or equal to zero. For example, `10`.\n\n This command executes the following SQL Server commands. The integer 10 is\n included as an example:\n - `USE tempdb`\n - `DBCC SHRINKFILE (@filename, 10)`\n4. Target size and truncate only\n\n ```sql\n msdb.dbo.gcloudsql_tempdb_shrinkfile @filename = '\u003cvar translate=\"no\"\u003eFILENAME\u003c/var\u003e', @target_size=10, @truncateonly=TRUNCATE_ONLY_INT\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eTRUNCATE_ONLY_INT\u003c/var\u003e: accepts an integer value of either 0 or 1. If set to 1, then `TRUNCATEONLY` is passed as an option. Target size is ignored if `TRUNCATEONLY` is passed. This option takes priority over `NOTRUNCATE`.\n\n This command executes the following SQL Server commands:\n - `USE tempdb`\n - `DBCC SHRINKFILE (@filename, 10, TRUNCATEONLY)`\n5. Target size and no truncate option\n\n ```sql\n msdb.dbo.gcloudsql_tempdb_shrinkfile @filename = '\u003cvar translate=\"no\"\u003eFILENAME\u003c/var\u003e', @target_size=10, @no_truncate=NO_TRUNCATE_INT\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eNO_TRUNCATE_INT\u003c/var\u003e: accepts an integer value of either 0 or 1. If set to 1, then `NOTRUNCATE` is passed as an option.\n\n This command executes the following SQL Server commands:\n - `USE tempdb`\n - `DBCC SHRINKFILE (@filename, 10, NOTRUNCATE)`\n\nWhat's next\n-----------\n\n- Learn about [Instance settings](/sql/docs/sqlserver/instance-settings).\n- Learn about [Monitoring Cloud SQL instances](/sql/docs/sqlserver/monitor-instance)."]]