|
| 1 | +--- |
| 2 | +title: Transaction Diagnostics |
| 3 | +summary: Use the built-in function `crdb_internal.request_transaction_bundle` to request a transaction diagnostics bundle for a specified transaction fingerprint ID. |
| 4 | +toc: true |
| 5 | +--- |
| 6 | + |
| 7 | +{% include_cached new-in.html version="v25.4" %} Transaction diagnostics allow operators and support engineers to investigate issues involving [transactions]({% link {{ page.version.version }}/transactions.md %}) in user workloads. Use the built-in function [`crdb_internal`]({% link {{ page.version.version }}/crdb-internal.md %})`.request_transaction_bundle` to request a transaction diagnostics bundle for a specified [transaction fingerprint ID]({% link {{ page.version.version }}/ui-transactions-page.md %}). |
| 8 | + |
| 9 | +{{site.data.alerts.callout_info}} |
| 10 | +Requesting a transaction diagnostics bundle introduces performance overhead. This feature is primarily intended for use under the guidance of [Cockroach Labs Support](https://support.cockroachlabs.com/). |
| 11 | +{{site.data.alerts.end}} |
| 12 | + |
| 13 | +## Required privileges |
| 14 | + |
| 15 | +To use this function on a [secure cluster]({% link {{ page.version.version }}/secure-a-cluster.md %}), you must be an [`admin` user]({% link {{ page.version.version }}/security-reference/authorization.md %}#admin-role) or a SQL user with the [`VIEWACTIVITY`]({% link {{ page.version.version }}/security-reference/authorization.md %}#viewactivity) or [`VIEWACTIVITYREDACTED`]({% link {{ page.version.version }}/security-reference/authorization.md %}#viewactivityredacted) [system privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges). If the user has only `VIEWACTIVITYREDACTED`, they can request only redacted bundles. |
| 16 | + |
| 17 | +## Function signature |
| 18 | + |
| 19 | +~~~ |
| 20 | +crdb_internal.request_transaction_bundle( |
| 21 | + transaction_fingerprint_id: string, |
| 22 | + sampling_probability: float, |
| 23 | + min_execution_latency: interval, |
| 24 | + expires_after: interval, |
| 25 | + redacted: bool |
| 26 | +) -> (request_id: int, created: bool) |
| 27 | +~~~ |
| 28 | + |
| 29 | +## Parameters |
| 30 | + |
| 31 | +- `transaction_fingerprint_id`: A hex-encoded ID of the [transaction fingerprint]({% link {{ page.version.version }}/ui-transactions-page.md %}#transaction_fingerprint) to capture. The fingerprint ID must exist in `crdb_internal.transaction_statistics`, which is the system of record for transaction fingerprints. |
| 32 | +- `sampling_probability`: A probability value (between 0 and 1) for sampling whether a transaction bundle should be recorded. If 0 is provided, there is no sampling; the next execution of the transaction will be captured. |
| 33 | +- `min_execution_latency`: The minimum execution time required for the transaction to be considered. If `sampling_probability` is non-zero, this value must also be non-zero. |
| 34 | +- `expires_after`: The duration for which the request remains active. A value of 0 keeps the request open until fulfilled or canceled. |
| 35 | +- `redacted`: Specifies whether the resulting bundle should be redacted. |
| 36 | + |
| 37 | +## Return values |
| 38 | + |
| 39 | +- `request_id`: The ID of the generated request, or `NULL` if the request could not be created. |
| 40 | +- `created`: Returns `true` if the request is successfully created, or `false` if the specified fingerprint ID does not exist. |
| 41 | + |
| 42 | +## Troubleshooting example |
| 43 | + |
| 44 | +To troubleshoot with a transaction diagnostics bundle, follow these steps: |
| 45 | + |
| 46 | +1. [Identify the transaction fingerprint ID](#step-1-identify-the-transaction-fingerprint-id) to generate a bundle for. |
| 47 | +1. [Create a bundle request](#step-2-create-a-bundle-request) for that fingerprint ID. |
| 48 | +1. [Download the bundle](#step-3-download-the-bundle) from [DB Console]({% link {{ page.version.version }}/ui-overview.md %}). |
| 49 | +1. [Inspect the bundle](#step-4-inspect-the-bundle). |
| 50 | + |
| 51 | +### Setup |
| 52 | + |
| 53 | +For this example, set the [`application_name`]({% link {{ page.version.version }}/map-sql-activity-to-app.md %}) to enable filtering: |
| 54 | + |
| 55 | +{% include_cached copy-clipboard.html %} |
| 56 | +~~~sql |
| 57 | +SET application_name = 'cockroachdb_test'; |
| 58 | +~~~ |
| 59 | + |
| 60 | +Run the following explicit transaction, which sleeps for 10 seconds: |
| 61 | + |
| 62 | +{% include_cached copy-clipboard.html %} |
| 63 | +~~~sql |
| 64 | +BEGIN; SELECT pg_sleep(10), 'cockroachdb_test' ; COMMIT; |
| 65 | +~~~ |
| 66 | + |
| 67 | +### Step 1. Identify the transaction fingerprint ID |
| 68 | + |
| 69 | +Identify the transaction fingerprint ID of the example transaction by navigating to the [**SQL Activity**]({% link {{ page.version.version }}/ui-overview.md %}#sql-activity) page in the [DB Console]({% link {{ page.version.version }}/ui-overview.md %}). On the [**Transactions**]({% link {{ page.version.version }}/ui-transactions-page.md %}) tab, search the Top `500` by `Transaction Time` in the `Past Hour` and click **Apply** to list transactions. Filter the transactions by **Application Name**: `cockroachdb_test`. |
| 70 | + |
| 71 | +In the **Transactions** column, click the transaction fingerprint `SELECT pg_sleep(_), _` to open the [**Transaction Details**]({% link {{ page.version.version }}/ui-transactions-page.md %}#transaction-details-page) page for that fingerprint. |
| 72 | + |
| 73 | +<img src="{{ 'images/v25.4/transaction-diagnostics-1.png' | relative_url }}" alt="Transactions tab" style="border:0px solid #eee;max-width:100%" /> |
| 74 | + |
| 75 | +From the **Transaction Details** page, copy the hexadecimal **Fingerprint ID** for this transaction, `afdd4059a899442e`. |
| 76 | + |
| 77 | +<img src="{{ 'images/v25.4/transaction-diagnostics-2.png' | relative_url }}" alt="Transactions Details page" style="border:0px solid #eee;max-width:100%" /> |
| 78 | + |
| 79 | +Note the decimal equivalent of the fingerprint ID in the browser's address bar. In this case, the URL may look like `https://127.0.0.1:29001/#/transaction/12672355680315327534?appNames=cockroachdb_test`. The decimal value of the fingerprint is `12672355680315327534`. |
| 80 | + |
| 81 | +### Step 2. Create a bundle request |
| 82 | + |
| 83 | +Create a transaction diagnostics request to be fulfilled the next time the relevant transaction is executed: |
| 84 | + |
| 85 | +{% include_cached copy-clipboard.html %} |
| 86 | +~~~sql |
| 87 | +SELECT * FROM crdb_internal.request_transaction_bundle('afdd4059a899442e', 0, '0', '0', false); |
| 88 | +~~~ |
| 89 | + |
| 90 | +The parameters to the call to `crdb_internal.request_transaction_bundle()` are: |
| 91 | + |
| 92 | +- `transaction_fingerprint_id`: `'afdd4059a899442e'`, the hexadecimal fingerprint ID from [Step 1](#step-1-identify-the-transaction-fingerprint-id). |
| 93 | +- `sampling_probability`: `0`, which disables sampling. |
| 94 | +- `min_execution_latency`: `'0'`, which sets no minimum execution time. |
| 95 | +- `expires_after`: `'0'`, which keeps the request open until fulfilled or canceled. |
| 96 | +- `redacted`: `false`, which does not redact the bundle. |
| 97 | + |
| 98 | +Calling the function will return a `request_id` and a `created` boolean flag. This will create an entry in the `system.transaction_diagnostics_request` table. |
| 99 | + |
| 100 | +~~~sql |
| 101 | +> SELECT * FROM crdb_internal.request_transaction_bundle('afdd4059a899442e', 0, '0', '0', false); |
| 102 | + request_id | created |
| 103 | +----------------------+---------- |
| 104 | + 1113728276333035521 | t |
| 105 | + |
| 106 | +> SELECT * FROM system.transaction_diagnostics_requests; |
| 107 | + id | completed | transaction_fingerprint_id | statement_fingerprint_ids | transaction_diagnostics_id | requested_at | min_execution_latency | expires_at | sampling_probability | redacted | username |
| 108 | +----------------------+-----------+----------------------------+---------------------------+----------------------------+-------------------------------+-----------------------+------------------------+----------------------+----------+------------ |
| 109 | + 1113386248552742913 | t | \xafdd4059a899442e | {"\\x00befd152e98f3f1"} | 1113386693458034689 | 2025-10-07 14:42:18.234632+00 | NULL | NULL | NULL | f | roachprod |
| 110 | +~~~ |
| 111 | + |
| 112 | +In the DB Console, go to [**Advanced Debug**]({% link {{ page.version.version }}/ui-debug-pages.md %}) > [**Diagnostics History**]({% link {{ page.version.version }}/ui-debug-pages.md %}#diagnostics-history). Under the **Transactions** tab, there will be a row for the bundle request. You could also use the URL `https://{host}:{port}/#/reports/diagnosticshistory?tab=Transactions`. The page initially displays the following information: |
| 113 | + |
| 114 | +- The date and time the request was **Activated on**. |
| 115 | +- `Transaction 12672355680315327534` (the decimal form of the transaction fingerprint ID from [Step 1](#step-1-identify-the-transaction-fingerprint-id)). |
| 116 | +- A **Status** of `WAITING`. |
| 117 | +- A button to **Cancel request** (Use this if a transaction diagnostics bundle is no longer needed). |
| 118 | + |
| 119 | +<img src="{{ 'images/v25.4/transaction-diagnostics-3.png' | relative_url }}" alt="Diagnostics History, Transactions, Status Waiting" style="border:0px solid #eee;max-width:100%" /> |
| 120 | + |
| 121 | +### Step 3. Download the bundle |
| 122 | + |
| 123 | +To fulfill the request, run the explicit transaction again. Note that the constant values in the transaction do not have to exactly match the original run. In the second execution of the transaction, the number of seconds differs from the original `10` and the string differs from the original `'cockroachdb_test'`. |
| 124 | + |
| 125 | +{% include_cached copy-clipboard.html %} |
| 126 | +~~~sql |
| 127 | +BEGIN; SELECT pg_sleep(12), 'cockroachdb_test_2' ; COMMIT; |
| 128 | +~~~ |
| 129 | + |
| 130 | +Navigate to the [**Advanced Debug**]({% link {{ page.version.version }}/ui-debug-pages.md %}) > [**Diagnostics History**]({% link {{ page.version.version }}/ui-debug-pages.md %}#diagnostics-history) page in the DB Console. Under the **Transactions** tab, the row for the bundle request now shows: |
| 131 | + |
| 132 | +- The date and time the request was **Activated on**. |
| 133 | +- The statements for the transaction fingerprint. |
| 134 | +- A **Status** of `READY`. |
| 135 | +- A **Bundle.zip** link. |
| 136 | + |
| 137 | +<img src="{{ 'images/v25.4/transaction-diagnostics-4.png' | relative_url }}" alt="Diagnostics History, Transactions, Status Ready" style="border:0px solid #eee;max-width:100%" /> |
| 138 | + |
| 139 | +Click the **Bundle.zip** link to download the completed bundle, which will be named `txn-bundle-1113386693458034689.zip` using the `transaction_diagnostics_id` from the `system.transaction_diagnostics_requests` table. |
| 140 | + |
| 141 | +### Step 4. Inspect the bundle |
| 142 | + |
| 143 | +Unzip the transaction diagnostic bundle and examine its contents. It contains [statement diagnostic bundle]({% link {{ page.version.version }}/ui-statements-page.md %}#diagnostics) `zip` files for each statement as well as a `zip` file of the transaction traces: |
| 144 | + |
| 145 | +``` |
| 146 | +1-SELECT.zip |
| 147 | +2-COMMIT.zip |
| 148 | +transaction-1113386693458034689.zip |
| 149 | +``` |
| 150 | + |
| 151 | +Unzip the `zip` file `transaction-1113386693458034689.zip`. It consists of transaction traces in various formats (including a JSON file that can be [imported to Jaeger]({% link {{ page.version.version }}/query-behavior-troubleshooting.md %}#visualize-statement-traces-in-jaeger)): |
| 152 | + |
| 153 | +``` |
| 154 | +trace-jaeger.json |
| 155 | +trace.json |
| 156 | +trace.txt |
| 157 | +``` |
| 158 | + |
| 159 | +## See also |
| 160 | + |
| 161 | +- [Transactions]({% link {{ page.version.version }}/transactions.md %}) |
| 162 | +- [DB Console Transactions page]({% link {{ page.version.version }}/ui-transactions-page.md %}) |
| 163 | +- [DB Console Statements page, Diagnostics]({% link {{ page.version.version }}/ui-statements-page.md %}#diagnostics) |
| 164 | +- [`cockroach statement-diag`]({% link {{ page.version.version }}/cockroach-statement-diag.md %}) |
| 165 | +- [Identify slow queries]({% link {{ page.version.version }}/query-behavior-troubleshooting.md %}#identify-slow-queries) |
| 166 | +- [Visualize statement traces in Jaeger]({% link {{ page.version.version }}/query-behavior-troubleshooting.md %}#visualize-statement-traces-in-jaeger) |
| 167 | +- [`crdb_internal`]({% link {{ page.version.version }}/crdb-internal.md %}) |
0 commit comments