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

# cockroach statement-diag

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>;
};

Use the `cockroach statement-diag` <InternalLink path="cockroach-commands">command</InternalLink> to manage and download statement diagnostics bundles generated from the <InternalLink path="ui-statements-page#diagnostics">DB Console</InternalLink> or <InternalLink path="explain-analyze#explain-analyze-debug">`EXPLAIN ANALYZE (DEBUG)`</InternalLink>.

## Required privileges

Only members of the `admin` role and users with the `VIEWSYSTEMTABLE` <InternalLink path="security-reference/authorization#privileges">system privilege</InternalLink>, which provides read-only access to system tables, can run `cockroach statement-diag`. By default, the `root` user belongs to the `admin` role.

## Subcommands

| Subcommand | Usage                                                                             |
| ---------- | --------------------------------------------------------------------------------- |
| `list`     | List available statement diagnostics bundles and outstanding activation requests. |
| `download` | Download a specified diagnostics bundle into a `.zip` file.                       |
| `delete`   | Delete a statement diagnostics bundle(s).                                         |
| `cancel`   | Cancel an outstanding activation request(s).                                      |

## Synopsis

List available statement diagnostics bundles and outstanding activation requests:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach statement-diag list <flags>
```

Download a specified diagnostics bundle into a `.zip` file:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach statement-diag download <diagnostics ID> [<bundle filename] <flags>
```

Delete a statement diagnostics bundle:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach statement-diag delete <diagnostics ID> <flags>
```

Delete all statement diagnostics bundles:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach statement-diag delete --all <flags>
```

Cancel an outstanding activation request:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach statement-diag cancel <diagnostics ID> <flags>
```

Cancel all outstanding activation requests:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach statement-diag cancel --all <flags>
```

## Flags

* The `delete` and `cancel` subcommands support one [general-use](#general) flag.
* All `statement-diag` subcommands support several [client connection](#client-connection) and [logging](#logging) flags.

### General

| Flag    | Description                                  |
| ------- | -------------------------------------------- |
| `--all` | Apply to all bundles or activation requests. |

### Client connection

| Flag                                                       | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--url`                                                    | A <InternalLink path="connection-parameters#connect-using-a-url">connection URL</InternalLink> to use instead of the other arguments. To convert a connection URL to the syntax that works with your client driver, run <InternalLink path="connection-parameters#convert-a-url-for-different-drivers">`cockroach convert-url`</InternalLink>.<br /><br />**Env Variable:** `COCKROACH_URL`<br />**Default:** no URL                                                                                                                                                                                                                                                                                                                                                                                 |
| `--host`                                                   | The server host and port number to connect to. This can be the address of any node in the cluster. <br /><br />**Env Variable:** `COCKROACH_HOST`<br />**Default:** `localhost:26257`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `--port`<br /><br />`-p`                                   | The server port to connect to. Note: The port number can also be specified via `--host`. <br /><br />**Env Variable:** `COCKROACH_PORT`<br />**Default:** `26257`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `--user`<br /><br />`-u`                                   | The <InternalLink path="create-user">SQL user</InternalLink> that will own the client session.<br /><br />**Env Variable:** `COCKROACH_USER`<br />**Default:** `root`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `--insecure`                                               | Use an insecure connection.<br /><br />**Env Variable:** `COCKROACH_INSECURE`<br />**Default:** `false`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| <a id="flags-cert-principal-map" /> `--cert-principal-map` | A comma-separated list of `<cert-principal:<db-principal` mappings. This allows mapping the principal in a cert to a DB principal such as `node` or `root` or any SQL user. This is intended for use in situations where the certificate management system places restrictions on the `Subject.CommonName` or `SubjectAlternateName` fields in the certificate (e.g., disallowing a `CommonName` like `node` or `root`). If multiple mappings are provided for the same `<cert-principal`, the last one specified in the list takes precedence. A principal not specified in the map is passed through as-is via the identity function. A cert is allowed to authenticate a DB principal if the DB principal name is contained in the mapped `CommonName` or DNS-type `SubjectAlternateName` fields. |
| `--certs-dir`                                              | The path to the <InternalLink path="cockroach-cert">certificate directory</InternalLink> containing the CA and client certificates and client key.<br /><br />**Env Variable:** `COCKROACH_CERTS_DIR`<br />**Default:** `${HOME}/.cockroach-certs/`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |

See <InternalLink path="connection-parameters">Client Connection Parameters</InternalLink> for more details.

### Logging

By default, this command logs messages to `stderr`. This includes events with `WARNING` <InternalLink path="logging#logging-levels-severities">severity</InternalLink> and higher.

If you need to troubleshoot this command's behavior, you can <InternalLink path="configure-logs">customize its logging behavior</InternalLink>.

## Examples

### Setup

These examples assume you are running <InternalLink path="start-a-local-cluster">an insecure cluster</InternalLink> and have requested and/or generated statement diagnostics bundles using the <InternalLink path="ui-statements-page#diagnostics">DB Console</InternalLink> or <InternalLink path="explain-analyze#explain-analyze-debug">`EXPLAIN ANALYZE (DEBUG)`</InternalLink>.

### Download a statement diagnostics bundle

List statement diagnostics bundles and/or activation requests:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach statement-diag list --insecure
```

```
Statement diagnostics bundles:
  ID                  Collection time          Statement
  603820372518502401  2020-11-02 18:29:13 UTC  CREATE DATABASE bank

Outstanding activation requests:
  ID                  Activation time          Statement
  603811900498804737  2020-11-02 17:46:08 UTC  SELECT * FROM bank.accounts
```

Download a statement diagnostics bundle to `bundle.zip`:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach statement-diag download 603820372518502401 bundle.zip --insecure
```

### Delete all statement diagnostics bundles

Delete all statement diagnostics bundles:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach statement-diag delete --all --insecure
```

### Cancel an activation request

List statement diagnostics bundles and/or activation requests:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach statement-diag list --insecure
```

```
Outstanding activation requests:
  ID                  Activation time          Statement
  603811900498804737  2020-11-02 17:46:08 UTC  SELECT * FROM bank.accounts
```

### Delete an activation request

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach statement-diag cancel 603811900498804737 --insecure
```

## See also

* <InternalLink path="ui-statements-page#diagnostics">DB Console statement diagnostics</InternalLink>
* <InternalLink path="explain-analyze#explain-analyze-debug">`EXPLAIN ANALYZE (DEBUG)`</InternalLink>
* <InternalLink path="cockroach-commands">`cockroach` Commands Overview</InternalLink>
