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

# INSPECT

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

The `INSPECT` <InternalLink path="sql-statements">statement</InternalLink> runs a data consistency validation job against a table or database and records any errors it finds. To display errors recorded by an inspection job, use <InternalLink path="show-inspect-errors">`SHOW INSPECT ERRORS`</InternalLink>.

`INSPECT` is the generally available replacement for the deprecated `EXPERIMENTAL SCRUB` command.

<Note>
  `INSPECT` is used to verify data integrity. It does not automatically repair errors.
</Note>

## Required privileges

To run `INSPECT` and view its results, the user must have:

* The `INSPECT` system-level <InternalLink path="security-reference/authorization#supported-privileges">privilege</InternalLink>, which is required to run the `INSPECT` statement.

## Synopsis

<img src="https://mintcdn.com/cockroachlabs/s4duaCBAbwxHbmt7/images/sql-diagrams/v26.3/inspect_table.svg?fit=max&auto=format&n=s4duaCBAbwxHbmt7&q=85&s=17db868cf94833c95df8fa81fad97d1b" alt="inspect_table syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="707" height="37" data-path="images/sql-diagrams/v26.3/inspect_table.svg" />

<img src="https://mintcdn.com/cockroachlabs/s4duaCBAbwxHbmt7/images/sql-diagrams/v26.3/inspect_database.svg?fit=max&auto=format&n=s4duaCBAbwxHbmt7&q=85&s=d9c916ed241320796a67c764ef28b1e3" alt="inspect_database syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="721" height="37" data-path="images/sql-diagrams/v26.3/inspect_database.svg" />

## Parameters

| Parameter                    | Description                                                                                                                                                                                                                                                                                                                           |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `table_name`                 | The <InternalLink path="create-table">table</InternalLink> to inspect.                                                                                                                                                                                                                                                                |
| `db_name`                    | The <InternalLink path="create-database">database</InternalLink> to inspect.                                                                                                                                                                                                                                                          |
| `opt_as_of_clause`           | Optional. Run the inspection against a historical read timestamp using `INSPECT ... AS OF SYSTEM TIME {expr}`. For an example, see [`INSPECT` at a specific timestamp](#inspect-at-a-specific-timestamp). For more information about historical reads, see <InternalLink path="as-of-system-time">`AS OF SYSTEM TIME`</InternalLink>. |
| `opt_inspect_options_clause` | Optional. Control which <InternalLink path="indexes">indexes</InternalLink> are used to plan `INSPECT` checks with `INSPECT ... WITH OPTIONS (...)`. For an example, see [`INSPECT` a table for specific indexes](#inspect-a-table-for-specific-indexes). See [Options](#options).                                                    |

### Options

| Option                         | Description                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `INDEX ALL`                    | Run all supported `INSPECT` checks for the target table or database. This is the default.                                                                                                                                                                                                                                                                                                                                |
| `INDEX ({index_name} [, ...])` | Run checks only for the specified indexes. On supported <InternalLink path="alter-table">`REGIONAL BY ROW`</InternalLink> tables, naming the primary index can also trigger a uniqueness check. Note that `INDEX ALL` and this option are mutually exclusive.                                                                                                                                                            |
| `DETACHED`                     | Run `INSPECT` in detached mode so the statement returns to the SQL client after the job is created (instead of waiting for the job to complete). For an example, see [`INSPECT` a table without waiting for completion](#inspect-a-table-without-waiting-for-completion). This option allows `INSPECT` to run inside a <InternalLink path="run-multi-statement-transactions">multi-statement transaction</InternalLink>. |

## Considerations

* `INSPECT` always runs as a <InternalLink path="show-jobs">background job</InternalLink>.
* By default, `INSPECT` causes the SQL client to wait for the background job to complete and returns a `NOTICE` with the job ID. To return to the client as soon as the job is created (without waiting for it to finish), use the [`DETACHED` option](#options).
* `INSPECT` can be run inside a <InternalLink path="run-multi-statement-transactions">multi-statement transaction</InternalLink> if the `DETACHED` option is used. Otherwise, it needs to be run in an <InternalLink path="transactions#individual-statements">implicit transaction</InternalLink>.
* `INSPECT` runs with low priority under the <InternalLink path="admission-control">admission control</InternalLink> subsystem and may take time on large datasets. Plan to run it during periods of lower system load.
* `INSPECT` runs secondary-index consistency checks on supported secondary indexes. On supported <InternalLink path="alter-table">`REGIONAL BY ROW`</InternalLink> tables, it can also run uniqueness checks on the primary index to detect duplicate unique values across regions.
* The following index types are unsupported:
  * <InternalLink path="vector-indexes">Vector indexes</InternalLink>
  * <InternalLink path="partial-indexes">Partial indexes</InternalLink>
  * <InternalLink path="expression-indexes">Expression indexes</InternalLink>
  * <InternalLink path="hash-sharded-indexes">Hash-sharded indexes</InternalLink>
  * <InternalLink path="inverted-indexes">Inverted indexes</InternalLink>
* Unsupported index types are automatically skipped when using the default `INDEX ALL` behavior. If an unsupported index type is directly requested using `INDEX {index_name}`, the statement will fail before starting.

## Examples

### `INSPECT` a table (all supported checks)

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
INSPECT TABLE movr.public.users;
```

```
NOTICE: waiting for INSPECT job to complete: 1141477630617223169
If the statement is canceled, the job will continue in the background.
```

### `INSPECT` a table for specific indexes

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
INSPECT TABLE movr.public.vehicles WITH OPTIONS INDEX (vehicles_auto_index_fk_city_ref_users);
```

```
NOTICE: waiting for INSPECT job to complete: 1141477560713150465
If the statement is canceled, the job will continue in the background.
```

### Run a uniqueness check on a `REGIONAL BY ROW` primary index

On supported <InternalLink path="alter-table">`REGIONAL BY ROW`</InternalLink> tables, `INSPECT` will run uniqueness checks on the primary index to detect duplicate unique values across regions. This will also run any other checks supported by `INSPECT`:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
INSPECT TABLE movr.public.users;
```

### `INSPECT` a table without waiting for completion

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
INSPECT TABLE movr.public.vehicles WITH OPTIONS DETACHED;
```

```
NOTICE:  INSPECT job 1141773037670301697 running in the background
```

### `INSPECT` at a specific timestamp

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
INSPECT TABLE movr.public.users AS OF SYSTEM TIME '-10s';
```

```
NOTICE:  waiting for INSPECT job to complete: 1141477013029322753
If the statement is canceled, the job will continue in the background.
```

### Checking `INSPECT` job status

When you issue the `INSPECT` statement, a `NOTICE` message is returned to the client showing the job ID:

```
NOTICE:  waiting for INSPECT job to complete: 1141477013029322753
If the statement is canceled, the job will continue in the background.
```

You can check the status of the `INSPECT` <InternalLink path="show-jobs">job</InternalLink> using a statement like the following:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT * FROM [SHOW JOBS] WHERE job_id = 1141477013029322753;
```

```
        job_id        | job_type |           description           | user_name |  status   | running_status |        created         |        started         |        finished        |        modified        | fraction_completed | error | coordinator_id
----------------------+----------+---------------------------------+-----------+-----------+----------------+------------------------+------------------------+------------------------+------------------------+--------------------+-------+-----------------
  1141477013029322753 | INSPECT  | INSPECT TABLE movr.public.users | node      | succeeded | NULL           | 2026-01-14 20:12:19+00 | 2026-01-14 20:12:19+00 | 2026-01-14 20:12:19+00 | 2026-01-14 20:12:19+00 |                  1 |       |              1
```

### Viewing `INSPECT` results

To view errors found by an inspection job, use <InternalLink path="show-inspect-errors">`SHOW INSPECT ERRORS`</InternalLink>. Errors are stored in an internal system table and are subject to a 90 day retention policy.

## See also

* <InternalLink path="show-inspect-errors">`SHOW INSPECT ERRORS`</InternalLink>
* <InternalLink path="show-jobs">`SHOW JOBS`</InternalLink>
* <InternalLink path="ui-jobs-page">Jobs page in DB Console</InternalLink>
* <InternalLink path="as-of-system-time">`AS OF SYSTEM TIME`</InternalLink>
* <InternalLink path="security-reference/authorization#supported-privileges">Supported privileges</InternalLink>
