Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
MySQL | PostgreSQL | SQL Server
Halaman ini menjelaskan pengelolaan database tempdb di Cloud SQL.
Database tempdb adalah database sistem yang menyimpan banyak objek, termasuk
tabel sementara, prosedur tersimpan, dan lainnya. Dalam instance, Anda dapat
melakukan operasi umum pada database ini.
Database tempdb dibuat ulang setiap kali instance dimulai ulang. Untuk mencegah
hilangnya izin pengguna, Cloud SQL memberikan izin kepada pengguna sqlserver
setelah instance dimulai ulang.
Ringkasan
Penggunasqlserver
memiliki izin ALTER untuk mengelola opsi database tempdb.
Untuk mengetahui informasi selengkapnya tentang cara mengelola resource ini, lihat halaman database tempdb.
Mengelola file tempdb
Setelah Anda terhubung ke instance,
penggunasqlserver dapat mengelola file tempdb.
Jumlah file
Pengguna memiliki izin ALTER pada database tempdb, yang memungkinkan mereka mengontrol
setelan untuk jumlah file dan lainnya. Beberapa contoh operasi mencakup
berikut ini:
ALTER DATABASE [tempdb] ADD FILE
ALTER DATABASE [tempdb] REMOVE
Ukuran file
Bagian berikut menjelaskan metode yang digunakan untuk mengontrol ukuran file dalam database tempdb.
EMPTY_FILE_INT: nilai bilangan bulat yang berupa 0 atau 1. Jika 1,
maka EMPTYFILE diteruskan sebagai opsi. Opsi ini diprioritaskan daripada
parameter lainnya.
Perintah ini menjalankan perintah SQL Server berikut:
TARGET_SIZE_INT: bilangan bulat yang merepresentasikan ukuran target
file dalam megabyte. Meneruskan nilai apa pun yang lebih besar dari atau sama dengan nol ke perintah DBCC SHRINKFILE. Misalnya, 10.
Perintah ini menjalankan perintah SQL Server berikut. Bilangan bulat 10 disertakan sebagai contoh:
TRUNCATE_ONLY_INT: menerima nilai bilangan bulat 0 atau 1.
Jika disetel ke 1, TRUNCATEONLY akan diteruskan sebagai opsi. Ukuran target diabaikan jika TRUNCATEONLY diteruskan. Opsi ini lebih diprioritaskan daripada
NOTRUNCATE.
Perintah ini menjalankan perintah SQL Server berikut:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]