> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Transaction Diagnostics

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

Transaction diagnostics allow operators and support engineers to investigate issues involving <InternalLink path="transactions">transactions</InternalLink> in user workloads. Use the built-in function <InternalLink path="crdb-internal">`crdb_internal`</InternalLink>`.request_transaction_bundle` to request a transaction diagnostics bundle for a specified <InternalLink path="ui-transactions-page">transaction fingerprint ID</InternalLink>.

<Note>
  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/).
</Note>

<Note>
  Transaction diagnostics do not contain a <InternalLink path="explain-analyze#debug-option">statement diagnostic bundle</InternalLink> for statements executed inside <InternalLink path="user-defined-functions">user-defined functions</InternalLink> or <InternalLink path="stored-procedures">stored procedures</InternalLink>. However, they do contain a statement diagnostic bundle for the top-level invocation, or call, of the user-defined function or stored procedure.
</Note>

## Required privileges

To use this function on a <InternalLink path="secure-a-cluster">secure cluster</InternalLink>, you must be an <InternalLink path="security-reference/authorization#admin-role">`admin` user</InternalLink> or a SQL user with the <InternalLink path="security-reference/authorization">`VIEWACTIVITY`</InternalLink> or <InternalLink path="security-reference/authorization">`VIEWACTIVITYREDACTED`</InternalLink> <InternalLink path="security-reference/authorization#supported-privileges">system privilege</InternalLink>. If the user has only `VIEWACTIVITYREDACTED`, they can request only redacted bundles.

## Function signature

```
crdb_internal.request_transaction_bundle(
  transaction_fingerprint_id: string,
  sampling_probability: float,
  min_execution_latency: interval,
  expires_after: interval,
  redacted: bool
) -> (request_id: int, created: bool)
```

## Parameters

* `transaction_fingerprint_id`: A hex-encoded ID of the <InternalLink path="ui-transactions-page">transaction fingerprint</InternalLink> to capture. The fingerprint ID must exist in `crdb_internal.transaction_statistics`, which is the system of record for transaction fingerprints.
* `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.
* `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.
* `expires_after`: The duration for which the request remains active. A value of 0 keeps the request open until fulfilled or canceled.
* `redacted`: Specifies whether the resulting bundle should be redacted.

## Return values

* `request_id`: The ID of the generated request, or `NULL` if the request could not be created.
* `created`: Returns `true` if the request is successfully created, or `false` if the specified fingerprint ID does not exist.

## Troubleshooting example

To troubleshoot with a transaction diagnostics bundle, follow these steps:

1. [Identify the transaction fingerprint ID](#step-1-identify-the-transaction-fingerprint-id) to generate a bundle for.
2. [Create a bundle request](#step-2-create-a-bundle-request) for that fingerprint ID.
3. [Download the bundle](#step-3-download-the-bundle) from <InternalLink path="ui-overview">DB Console</InternalLink>.
4. [Inspect the bundle](#step-4-inspect-the-bundle).

### Setup

For this example, set the <InternalLink path="map-sql-activity-to-app">`application_name`</InternalLink> to enable filtering:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET application_name = 'cockroachdb_test';
```

Run the following explicit transaction, which sleeps for 10 seconds:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
BEGIN; SELECT pg_sleep(10), 'cockroachdb_test' ; COMMIT;
```

### Step 1. Identify the transaction fingerprint ID

Identify the transaction fingerprint ID of the example transaction by navigating to the <InternalLink path="ui-overview#sql-activity">**SQL Activity**</InternalLink> page in the <InternalLink path="ui-overview">DB Console</InternalLink>. On the <InternalLink path="ui-transactions-page">**Transactions**</InternalLink> 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`.

In the **Transactions** column, click the transaction fingerprint `SELECT pg_sleep(_), _` to open the <InternalLink path="ui-transactions-page#transaction-details-page">**Transaction Details**</InternalLink> page for that fingerprint.

<img src="https://mintcdn.com/cockroachlabs/_APwzu9koAjny_GR/images/v26.3/transaction-diagnostics-1.png?fit=max&auto=format&n=_APwzu9koAjny_GR&q=85&s=77baaf3704189be82a573b4c7a2c0ed2" alt="Transactions tab" width="2702" height="1378" data-path="images/v26.3/transaction-diagnostics-1.png" />

From the **Transaction Details** page, copy the hexadecimal **Fingerprint ID** for this transaction, `afdd4059a899442e`.

<img src="https://mintcdn.com/cockroachlabs/_APwzu9koAjny_GR/images/v26.3/transaction-diagnostics-2.png?fit=max&auto=format&n=_APwzu9koAjny_GR&q=85&s=f6c1f41e444990b1f48e1ed880f907e2" alt="Transactions Details page" width="2210" height="1118" data-path="images/v26.3/transaction-diagnostics-2.png" />

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`.

### Step 2. Create a bundle request

Create a transaction diagnostics request to be fulfilled the next time the relevant transaction is executed:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT * FROM crdb_internal.request_transaction_bundle('afdd4059a899442e', 0, '0', '0', false);
```

The parameters to the call to `crdb_internal.request_transaction_bundle()` are:

* `transaction_fingerprint_id`: `'afdd4059a899442e'`, the hexadecimal fingerprint ID from [Step 1](#step-1-identify-the-transaction-fingerprint-id).
* `sampling_probability`: `0`, which disables sampling.
* `min_execution_latency`: `'0'`, which sets no minimum execution time.
* `expires_after`: `'0'`, which keeps the request open until fulfilled or canceled.
* `redacted`: `false`, which does not redact the bundle.

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.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SELECT * FROM crdb_internal.request_transaction_bundle('afdd4059a899442e', 0, '0', '0', false);
      request_id      | created
----------------------+----------
  1113728276333035521 |    t

> SELECT * FROM system.transaction_diagnostics_requests;
          id          | completed | transaction_fingerprint_id | statement_fingerprint_ids | transaction_diagnostics_id |         requested_at          | min_execution_latency |       expires_at       | sampling_probability | redacted | username
----------------------+-----------+----------------------------+---------------------------+----------------------------+-------------------------------+-----------------------+------------------------+----------------------+----------+------------
  1113386248552742913 |     t     | \xafdd4059a899442e         | {"\\x00befd152e98f3f1"}   |        1113386693458034689 | 2025-10-07 14:42:18.234632+00 | NULL                  | NULL                   |                 NULL |    f     | roachprod
```

In the DB Console, go to <InternalLink path="ui-debug-pages">**Advanced Debug**</InternalLink> > <InternalLink path="ui-debug-pages">**Diagnostics History**</InternalLink>. 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:

* The date and time the request was **Activated on**.
* `Transaction 12672355680315327534` (the decimal form of the transaction fingerprint ID from [Step 1](#step-1-identify-the-transaction-fingerprint-id)).
* A **Status** of `WAITING`.
* A button to **Cancel request** (Use this if a transaction diagnostics bundle is no longer needed).

<img src="https://mintcdn.com/cockroachlabs/_APwzu9koAjny_GR/images/v26.3/transaction-diagnostics-3.png?fit=max&auto=format&n=_APwzu9koAjny_GR&q=85&s=69dce918d98d14fd3bc61c112bcb0b26" alt="Diagnostics History, Transactions, Status Waiting" width="2152" height="754" data-path="images/v26.3/transaction-diagnostics-3.png" />

### Step 3. Download the bundle

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'`.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
BEGIN; SELECT pg_sleep(12), 'cockroachdb_test_2' ; COMMIT;
```

Navigate to the <InternalLink path="ui-debug-pages">**Advanced Debug**</InternalLink> > <InternalLink path="ui-debug-pages">**Diagnostics History**</InternalLink> page in the DB Console. Under the **Transactions** tab, the row for the bundle request now shows:

* The date and time the request was **Activated on**.
* The statements for the transaction fingerprint.
* A **Status** of `READY`.
* A **Bundle.zip** link.

<img src="https://mintcdn.com/cockroachlabs/_APwzu9koAjny_GR/images/v26.3/transaction-diagnostics-4.png?fit=max&auto=format&n=_APwzu9koAjny_GR&q=85&s=55ad9f5188664ec70b0f251e647ac8ea" alt="Diagnostics History, Transactions, Status Ready" width="2124" height="766" data-path="images/v26.3/transaction-diagnostics-4.png" />

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.

### Step 4. Inspect the bundle

Unzip the transaction diagnostic bundle and examine its contents. It contains <InternalLink path="ui-statements-page#diagnostics">statement diagnostic bundle</InternalLink> `zip` files for each statement as well as a `zip` file of the transaction traces:

```
1-SELECT.zip
2-COMMIT.zip
transaction-1113386693458034689.zip
```

Unzip the `zip` file `transaction-1113386693458034689.zip`. It consists of transaction traces in various formats (including a JSON file that can be <InternalLink path="query-behavior-troubleshooting#visualize-statement-traces-in-jaeger">imported to Jaeger</InternalLink>):

```
trace-jaeger.json
trace.json
trace.txt
```

## See also

* <InternalLink path="transactions">Transactions</InternalLink>
* <InternalLink path="ui-transactions-page">DB Console Transactions page</InternalLink>
* <InternalLink path="ui-statements-page#diagnostics">DB Console Statements page, Diagnostics</InternalLink>
* <InternalLink path="cockroach-statement-diag">`cockroach statement-diag`</InternalLink>
* <InternalLink path="query-behavior-troubleshooting#identify-slow-queries">Identify slow queries</InternalLink>
* <InternalLink path="query-behavior-troubleshooting#visualize-statement-traces-in-jaeger">Visualize statement traces in Jaeger</InternalLink>
* <InternalLink path="crdb-internal">`crdb_internal`</InternalLink>
