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

# INSPECT

The `INSPECT` [statement](/docs/stable/sql-statements.md) 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 [`SHOW INSPECT ERRORS`](/docs/stable/show-inspect-errors).

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

## Required privileges

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

* The `INSPECT` system-level [privilege](/docs/stable/security-reference/authorization.md#supported-privileges), which is required to run the `INSPECT` statement.

## Synopsis

![inspect\_table syntax diagram](https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/inspect_table.svg?fit=max\&auto=format\&n=UZNSFbmU2EwEm6G5\&q=85\&s=c4aa751dc5f91b5f58565ca483a502c7)

![inspect\_database syntax diagram](https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/inspect_database.svg?fit=max\&auto=format\&n=UZNSFbmU2EwEm6G5\&q=85\&s=6abba63935cfceb23868dd271ca0dc59)

## Parameters

| Parameter | Description |
| - | - |
| `table_name` | The [table](/docs/stable/create-table.md) to inspect. |
| `db_name` | The [database](/docs/stable/create-database.md) 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 [`AS OF SYSTEM TIME`](/docs/stable/as-of-system-time). |
| `opt_inspect_options_clause` | Optional. Control which [indexes](/docs/stable/indexes.md) 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 [`REGIONAL BY ROW`](/docs/stable/alter-table) 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 [multi-statement transaction](/docs/stable/run-multi-statement-transactions). |

## Considerations

* `INSPECT` always runs as a [background job](/docs/stable/show-jobs.md).
* 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 [multi-statement transaction](/docs/stable/run-multi-statement-transactions) if the `DETACHED` option is used. Otherwise, it needs to be run in an [implicit transaction](/docs/stable/transactions.md#individual-statements).
* `INSPECT` runs with low priority under the [admission control](/docs/stable/admission-control.md) 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 [`REGIONAL BY ROW`](/docs/stable/alter-table) tables, it can also run uniqueness checks on the primary index to detect duplicate unique values across regions.
* The following index types are unsupported:
  * [Vector indexes](/docs/stable/vector-indexes.md)
  * [Partial indexes](/docs/stable/partial-indexes.md)
  * [Expression indexes](/docs/stable/expression-indexes.md)
  * [Hash-sharded indexes](/docs/stable/hash-sharded-indexes.md)
  * [Inverted indexes](/docs/stable/inverted-indexes.md)
* 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 [`REGIONAL BY ROW`](/docs/stable/alter-table) 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` [job](/docs/stable/show-jobs.md) 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 [`SHOW INSPECT ERRORS`](/docs/stable/show-inspect-errors). Errors are stored in an internal system table and are subject to a 90 day retention policy.

## See also

* [`SHOW INSPECT ERRORS`](/docs/stable/show-inspect-errors)
* [`SHOW JOBS`](/docs/stable/show-jobs)
* [Jobs page in DB Console](/docs/stable/ui-jobs-page.md)
* [`AS OF SYSTEM TIME`](/docs/stable/as-of-system-time)
* [Supported privileges](/docs/stable/security-reference/authorization.md#supported-privileges)
