Cloud Storage バケットから XEvent 出力ファイルを読み取るには、バケットから SQL Server インスタンスにファイルをダウンロードします。次のいずれかのインスタンスからダウンロードできます。
Compute Engine Windows インスタンス
Compute Engine Linux インスタンス
SQL Server を実行している別の種類のインスタンス
XEvent 出力ファイルをバケットから、インスタンスにアクセスできる場所(ローカル ディスクなど)に転送します。次に、XEvent 出力ファイルから情報を返すには、サーバーに対して VIEW SERVER STATE 権限を持つアカウントで sys.fn_xe_file_target_read_file 関数を実行します。権限について詳しくは、権限をご覧ください。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[],[],null,["# Analyze database performance with Extended Events\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis page describes how to use [Extended Events (XEvents)](https://learn.microsoft.com/en-us/sql/relational-databases/extended-events/extended-events?view=sql-server-ver16)\non your instances.\n\nCloud SQL supports using XEvents for monitoring, identifying, and troubleshooting the\nperformance of your database. To do this, you create XEvent sessions and read XEvent output files. You can read the XEvent output files either on the instance or by downloading the XEvent files from a Cloud Storage bucket.\n\nBefore you begin\n----------------\n\nIf you want to upload your XEvent files to a Cloud Storage bucket, then [create a bucket](/storage/docs/creating-buckets) in your Google Cloud account.\n| **Note:** You need to manage log retention in the Cloud Storage bucket. For information about adding a retention policy to specify a retention period, see [Retention policies and retention policy locks](/storage/docs/bucket-lock).\n\nBest practices\n--------------\n\n- To avoid transferring large files across regions, we recommend that you do one of the following:\n - Create multi-regional Cloud Storage buckets\n - Set up the destination Cloud Storage bucket in the same region as the instance\n- Before using XEvents, enable [automatic storage increases](/sql/docs/sqlserver/instance-settings#automatic-storage-increase-2ndgen). XEvent output files, depending on their total size and retention intervals, might need significant disk space.\n- To avoid retaining too many XEvent files for a long time, set up a data retention policy for your Cloud Storage bucket.\n- If you create an XEvent session by using the SSMS UI, but some boxes for input values don't appear, then resize the **Create XEvent Session** window.\n\nHow to create XEvent sessions\n-----------------------------\n\nXEvents is enabled on your instances automatically.\n\nUse the [`CREATE EVENT SESSION`](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-event-session-transact-sql?view=sql-server-ver16)\ncommand to define new XEvent sessions. You also can use the user interface of\n[SQL Server Management Studio (SSMS)](https://learn.microsoft.com/en-us/sql/ssms/sql-server-management-studio-ssms?view=sql-server-ver15) to create XEvent sessions.\n\nCloud SQL enforces the following parameters for all XEvent sessions:\n\n### XEvent session configuration parameters\n\nYou can configure XEvent sessions by using the following parameters as custom flags:\n\nFor more information about setting these flags, see [Configure database flags](/sql/docs/sqlserver/flags).\n\nHow to read XEvent session output files\n---------------------------------------\n\nYou can read XEvent session output files from either a Cloud SQL instance or a Cloud Storage bucket.\n\n### Read XEvent output files from an instance\n\nTo retrieve the data from an XEvent file that an XEvent session creates, use the [`sys.fn_xe_file_target_read_file`](https://learn.microsoft.com/en-us/sql/relational-databases/system-functions/sys-fn-xe-file-target-read-file-transact-sql?view=sql-server-ver16) function.\n\nHere's an example: \n\n SELECT * FROM sys.fn_xe_file_target_read_file('/var/opt/mssql/xevents/filename*, NULL, NULL, NULL);\n\n### Read XEvent output files from a bucket\n\nTo read XEvent output files from a Cloud Storage bucket, download the files from the bucket to a SQL Server instance. You can download from one of the following instances:\n\n- A Compute Engine Windows instance\n- A Compute Engine Linux instance\n- Another type of instance that runs SQL Server\n\nThen, transfer the XEvent output files from the bucket to a location accessible to\nthat instance, such as its local disk. Next, to return information from the XEvent\noutput file, run the [`sys.fn_xe_file_target_read_file`](https://learn.microsoft.com/en-us/sql/relational-databases/system-functions/sys-fn-xe-file-target-read-file-transact-sql?view=sql-server-ver16) function with an account that has the\n`VIEW SERVER STATE` permission on the server. For more information about permissions, see\n[Permissions](https://learn.microsoft.com/en-us/sql/relational-databases/security/permissions-database-engine?view=sql-server-ver16#sql-server-permissions.).\n\nMonitoring metrics\n------------------\n\nYou can monitor the following xevent-related operations as part of the\n[Cloud SQL metrics](/sql/docs/sqlserver/admin-api/metrics),\navailable through\n[Metrics Explorer](https://cloud.google.com/monitoring/charts/metrics-explorer):\n\n- **database/sqlserver/xevents_upload_count**: indicates the total of the successful and failed xevent file upload attempts. Check this metric to monitor if your uploads were successful.\n- **database/sqlserver/xevents_size.**: indicates how much disk space is used by xevent files stored on the instance, in bytes.\n\nMonitor XEvent sessions\n-----------------------\n\nYou can monitor XEvent session-related activities through the `xevents.log` file for the following operations:\n\n- The XEvent output files removed from the disk, which were not uploaded to Cloud Storage and were occupying disk space higher than the value associated with `cloud sql xe output total disk size (mb)`.\n- The XEvent output files removed from the disk, which were not uploaded to Cloud Storage and are older than the value associated with `cloud sql xe file retention`.\n\nConsiderations for read replicas\n--------------------------------\n\nThis section contains information about XEvent sessions for new and existing read replicas.\n\n### For new read replicas\n\n- All XEvent session configuration parameters that are passed through database flags on the original instance are available on the newly created read replica.\n- All XEvent sessions present on the original instance when the read replicas are created are available on the read replica. Note that XEvent sessions on the read replica need to be started manually, unless they're configured to start automatically. For more information, see [How to create XEvent sessions](#how_to_create_xevent_sessions).\n- If you clone a primary instance, then any database flags that appear on the primary instance are propagated to the cloned instance. Also, you must grant permissions to the service account of the cloned instance to access the Cloud Storage bucket again.\n\n### For existing read replicas\n\n- XEvent session configuration parameters passed through database flags to the original instance aren't propagated to read replicas.\n- XEvent sessions created on the original instance aren't propagated to read replicas.\n\n| **Note:** If an XEvent session is created on a read replica, but the replica is recreated after the session is created, then the session no longer appears on the replica."]]