Skip to content

Commit fb70bc1

Browse files
committed
Add docs on INSPECT statement for v26.1
Fixes: - DOC-14957 - DOC-11405 - DOC-15189 - DOC-14628 - DOC-15695 - DOC-15046 Summary of changes: - Add docs for `INSPECT` statement - Add docs for `SHOW INSPECT ERRORS` statement - Add the above to the list of SQL statements - Update various privileges- and jobs-related docs
1 parent 2f74c6d commit fb70bc1

7 files changed

Lines changed: 260 additions & 2 deletions

File tree

src/current/_includes/v26.1/sidebar-data/sql.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,12 @@
484484
"/${VERSION}/insert.html"
485485
]
486486
},
487+
{
488+
"title": "<code>INSPECT</code>",
489+
"urls": [
490+
"/${VERSION}/inspect.html"
491+
]
492+
},
487493
{
488494
"title": "<code>JOIN</code>",
489495
"urls": [
@@ -700,6 +706,12 @@
700706
"/${VERSION}/show-index.html"
701707
]
702708
},
709+
{
710+
"title": "<code>SHOW INSPECT ERRORS</code>",
711+
"urls": [
712+
"/${VERSION}/show-inspect-errors.html"
713+
]
714+
},
703715
{
704716
"title": "<code>SHOW JOBS</code>",
705717
"urls": [

src/current/_includes/v26.1/sql/privileges.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Privilege | Levels | Description
1717
`EXTERNALCONNECTION` | System | Grants the ability to connect to external systems such as object stores, key management systems, Kafka feeds, or external file systems. Often used in conjunction with the `BACKUP`, `RESTORE`, and `CHANGEFEED` privilege.
1818
`EXTERNALIOIMPLICITACCESS` | System | Grants the ability to interact with external resources that require implicit access.
1919
`INSERT` | Table, Sequence | Grants the ability to insert objects at the table or sequence level.
20+
<a id="inspect"></a> `INSPECT` | System | Grants the ability to run the [`INSPECT`]({% link {{ page.version.version }}/inspect.md %}) statement and view results with [`SHOW INSPECT ERRORS`]({% link {{ page.version.version }}/show-inspect-errors.md %}).
2021
<a id="modifyclustersetting"></a>`MODIFYCLUSTERSETTING` | System | Grants the ability to modify [cluster settings]({% link {{ page.version.version }}/cluster-settings.md %}).
2122
`MODIFYSQLCLUSTERSETTING` | System | Grants the ability to modify SQL [cluster settings]({% link {{ page.version.version }}/cluster-settings.md %}) (cluster settings prefixed with `sql.`).
2223
`NOSQLLOGIN` | System | Prevents roles from connecting to the SQL interface of a cluster.

src/current/_includes/v26.1/ui/jobs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Column | Description
2828
----------|------------
2929
Description | SQL statement that created the job.
3030
Status | Current [job status](#job-status) or completion progress.
31-
Job ID | Unique job ID. This value is used to [pause]({{ link_prefix }}pause-job.html), [resume]({{ link_prefix }}resume-job.html), or [cancel]({{ link_prefix }}cancel-job.html) jobs.
31+
Job ID | Unique job ID. This value is used to [pause]({{ link_prefix }}pause-job.html), [resume]({{ link_prefix }}resume-job.html), or [cancel]({{ link_prefix }}cancel-job.html) jobs. For [`INSPECT`]({{ link_prefix }}inspect.html) jobs, you can use the Job ID with [`SHOW INSPECT ERRORS FOR JOB {id}`]({{ link_prefix }}show-inspect-errors.html).
3232
User Name | User that created the job.
3333
Creation Time (UTC) | Date and time the job was created.
3434
Last Modified Time (UTC) | Date and time the job was last modified.

src/current/v26.1/inspect.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: INSPECT
3+
summary: Use the INSPECT statement to run data consistency validation checks against tables or databases.
4+
toc: true
5+
docs_area: reference.sql
6+
---
7+
8+
The `INSPECT` [statement]({% link {{ page.version.version }}/sql-statements.md %}) runs a data consistency validation job against a table or database. The initial validation checks primary-to-secondary index consistency and records any errors. To display any errors recorded by the validation job, use [`SHOW INSPECT ERRORS`]({% link {{ page.version.version }}/show-inspect-errors.md %}).
9+
10+
{{site.data.alerts.callout_info}}
11+
`INSPECT` is used to verify data integrity. It does not automatically repair errors.
12+
{{site.data.alerts.end}}
13+
14+
## Required privileges
15+
16+
To run `INSPECT` and view its results, the user must have:
17+
18+
- The `INSPECT` system-level [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges) is required to run the `INSPECT` statement.
19+
- The `VIEWSYSTEMTABLE` system-level [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges), which is required to view the results of [`SHOW INSPECT ERRORS`]({% link {{ page.version.version }}/show-inspect-errors.md %})).
20+
21+
## Synopsis
22+
23+
<div>
24+
{% remote_include https://raw.githubusercontent.com/cockroachdb/generated-diagrams/{{ page.release_info.crdb_branch_name }}/grammar_svg/inspect_table.html %}
25+
</div>
26+
27+
<div>
28+
{% remote_include https://raw.githubusercontent.com/cockroachdb/generated-diagrams/{{ page.release_info.crdb_branch_name }}/grammar_svg/inspect_database.html %}
29+
</div>
30+
31+
## Parameters
32+
33+
Parameter | Description
34+
----------|------------
35+
`table_name` | The [table]({% link {{ page.version.version }}/create-table.md %}) to inspect.
36+
`db_name` | The [database]({% link {{ page.version.version }}/create-database.md %}) to inspect.
37+
`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`]({% link {{ page.version.version }}/as-of-system-time.md %}).
38+
`opt_inspect_options_clause` | Optional. Control which [indexes]({% link {{ page.version.version }}/indexes.md %}) are inspected using `INSPECT ... WITH OPTIONS (...)`. For an example, see [Inspect a table for specific indexes](#inspect-a-table-for-specific-indexes). See [Options](#options).
39+
40+
### Options
41+
42+
Option | Description
43+
-------|------------
44+
`INDEX ALL` | Inspect all supported index types in the target table or database. This is the default.
45+
`INDEX ({index_name} [, ...])` | Inspect only the specified indexes. Note that `INDEX ALL` and this option are mutually exclusive.
46+
47+
## Considerations
48+
49+
- `INSPECT` must be run in an [implicit transaction]({% link {{ page.version.version }}/transactions.md %}#individual-statements). It cannot be run inside a multi-statement transaction. For more information, see [Run Multi-Statement Transactions]({% link {{ page.version.version }}/run-multi-statement-transactions.md %}).
50+
- `INSPECT` always runs as a [background job]({% link {{ page.version.version }}/show-jobs.md %}).
51+
- `INSPECT` runs with low priority under the [admission control]({% link {{ page.version.version }}/admission-control.md %}) subsystem and may take time on large datasets. Plan to run it during periods of lower system load.
52+
- The following index types are unsupported:
53+
- [Vector indexes]({% link {{ page.version.version }}/vector-indexes.md %})
54+
- [Partial indexes]({% link {{ page.version.version }}/partial-indexes.md %})
55+
- [Expression indexes]({% link {{ page.version.version }}/expression-indexes.md %})
56+
- 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.
57+
58+
## Examples
59+
60+
### `INSPECT` a table (all supported indexes)
61+
62+
{% include_cached copy-clipboard.html %}
63+
~~~ sql
64+
INSPECT TABLE movr.public.users;
65+
~~~
66+
67+
~~~
68+
NOTICE: waiting for INSPECT job to complete: 1141477630617223169
69+
If the statement is canceled, the job will continue in the background.
70+
~~~
71+
72+
### `INSPECT` a table for specific indexes
73+
74+
{% include_cached copy-clipboard.html %}
75+
~~~ sql
76+
INSPECT TABLE movr.public.vehicles WITH OPTIONS INDEX (vehicles_auto_index_fk_city_ref_users);
77+
~~~
78+
79+
~~~
80+
NOTICE: waiting for INSPECT job to complete: 1141477560713150465
81+
If the statement is canceled, the job will continue in the background.
82+
~~~
83+
84+
### `INSPECT` at a specific timestamp
85+
86+
{% include_cached copy-clipboard.html %}
87+
~~~ sql
88+
INSPECT TABLE movr.public.users AS OF SYSTEM TIME '-10s';
89+
~~~
90+
91+
~~~
92+
NOTICE: waiting for INSPECT job to complete: 1141477013029322753
93+
If the statement is canceled, the job will continue in the background.
94+
~~~
95+
96+
### Checking `INSPECT` job status
97+
98+
When you issue the `INSPECT` statement, a `NOTICE` message is returned to the client showing the job ID:
99+
100+
~~~
101+
NOTICE: waiting for INSPECT job to complete: 1141477013029322753
102+
If the statement is canceled, the job will continue in the background.
103+
~~~
104+
105+
You can check the status of the `INSPECT` job using a statement like the following:
106+
107+
{% include_cached copy-clipboard.html %}
108+
~~~ sql
109+
SELECT * FROM [SHOW JOBS] WHERE job_id = 1141477013029322753;
110+
~~~
111+
~~~
112+
job_id | job_type | description | user_name | status | running_status | created | started | finished | modified | fraction_completed | error | coordinator_id
113+
----------------------+----------+---------------------------------+-----------+-----------+----------------+------------------------+------------------------+------------------------+------------------------+--------------------+-------+-----------------
114+
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
115+
~~~
116+
117+
### Viewing `INSPECT` results
118+
119+
To view errors found by an inspection job, use [`SHOW INSPECT ERRORS`]({% link {{ page.version.version }}/show-inspect-errors.md %}). Errors are stored in an internal system table and are subject to a 90 day retention policy.
120+
121+
## See also
122+
123+
- [`SHOW INSPECT ERRORS`]({% link {{ page.version.version }}/show-inspect-errors.md %})
124+
- [`SHOW JOBS`]({% link {{ page.version.version }}/show-jobs.md %})
125+
- [Jobs page in DB Console]({% link {{ page.version.version }}/ui-jobs-page.md %})
126+
- [`AS OF SYSTEM TIME`]({% link {{ page.version.version }}/as-of-system-time.md %})
127+
- [Supported privileges]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges)
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
title: SHOW INSPECT ERRORS
3+
summary: The SHOW INSPECT ERRORS statement lists issues detected by the INSPECT data consistency checker.
4+
toc: true
5+
docs_area: reference.sql
6+
---
7+
8+
The `SHOW INSPECT ERRORS` [statement]({% link {{ page.version.version }}/sql-statements.md %}) displays any issues detected by the data consistency validation jobs run by the [`INSPECT`]({% link {{ page.version.version }}/inspect.md %}) statement.
9+
10+
By default, `SHOW INSPECT ERRORS` returns errors from the most recent completed and successful `INSPECT` job for the specified table. To view errors from a specific inspection job, use its ID, e.g. `SHOW INSPECT ERRORS FOR JOB {id}`.
11+
12+
## Required privileges
13+
14+
To run `SHOW INSPECT ERRORS`, the user must have:
15+
16+
- The `INSPECT` system-level [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges), which is required to run the [`INSPECT` statement]({% link {{ page.version.version }}/inspect.md %}).
17+
- The `VIEWSYSTEMTABLE` system-level [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges), which is required to view the output of `SHOW INSPECT ERRORS`.
18+
19+
## Synopsis
20+
21+
<div>
22+
{% remote_include https://raw.githubusercontent.com/cockroachdb/generated-diagrams/{{ page.release_info.crdb_branch_name }}/grammar_svg/show_inspect_errors.html %}
23+
</div>
24+
25+
## Parameters
26+
27+
Parameter | Syntax | Description
28+
----------|----------|------------
29+
`opt_for_table_clause` | `FOR TABLE {table_name}` | Optional. Show errors for the specified [table]({% link {{ page.version.version }}/create-table.md %}).
30+
`opt_for_job_clause` | `FOR JOB {job_id}` | Optional. Show errors produced by the job ID returned by the [`INSPECT` statement]({% link {{ page.version.version }}/inspect.md %}).
31+
`opt_with_details` | `WITH DETAILS` | Optional. Include structured error metadata from the `details` column ([JSON]({% link {{ page.version.version }}/jsonb.md %})) in the results.
32+
33+
## Response
34+
35+
`SHOW INSPECT ERRORS` returns the following columns, with one row per issue detected.
36+
37+
Field | Description
38+
------|------------
39+
`job_id` | The ID of the [`INSPECT`]({% link {{ page.version.version }}/inspect.md %}) job that detected the issue.
40+
`error_type` | The type of inconsistency detected. For more information, see [Error types](#error-types).
41+
`aost` | The [`AS OF SYSTEM TIME`]({% link {{ page.version.version }}/as-of-system-time.md %}) timestamp used by the validation [job]({% link {{ page.version.version }}/show-jobs.md %}) (if any).
42+
`database_name` | The [database]({% link {{ page.version.version }}/create-database.md %}) containing the schema object with an issue.
43+
`schema_name` | The [schema]({% link {{ page.version.version }}/schema-design-overview.md %}) containing the object with an issue.
44+
`object_name` | The [table]({% link {{ page.version.version }}/create-table.md %}) or [index]({% link {{ page.version.version }}/indexes.md %}) with an issue.
45+
`primary_key` | The [primary key]({% link {{ page.version.version }}/primary-key.md %}) of the row involved in the issue, if applicable.
46+
`details` | This column is present only if `WITH DETAILS` is specified. It contains structured metadata ([JSON]({% link {{ page.version.version }}/jsonb.md %})) describing the issue.
47+
48+
### Error types
49+
50+
The `INSPECT` implementation reports the following `error_type` values:
51+
52+
Error type | Meaning
53+
----------|---------
54+
`secondary_index_missing` | A row in the [primary index]({% link {{ page.version.version }}/primary-key.md %}) is missing a corresponding entry in a [secondary index]({% link {{ page.version.version }}/indexes.md %}).
55+
`secondary_index_dangling` | A [secondary index]({% link {{ page.version.version }}/indexes.md %}) entry exists, but the referenced [primary index]({% link {{ page.version.version }}/primary-key.md %}) row does not.
56+
57+
## Examples
58+
59+
### Show the latest errors for a table
60+
61+
{% include_cached copy-clipboard.html %}
62+
~~~ sql
63+
SHOW INSPECT ERRORS FOR TABLE movr.public.users;
64+
~~~
65+
66+
### Show errors for a specific inspection job
67+
68+
When you issue the [`INSPECT` statement]({% link {{ page.version.version }}/inspect.md %}), a `NOTICE` message is returned to the client showing the job ID, e.g.,
69+
70+
{% include_cached copy-clipboard.html %}
71+
~~~ sql
72+
INSPECT TABLE movr.public.users AS OF SYSTEM TIME '-10s';
73+
~~~
74+
75+
~~~
76+
NOTICE: waiting for INSPECT job to complete: 1141477013029322753
77+
If the statement is canceled, the job will continue in the background.
78+
~~~
79+
80+
To show errors for a job, issue the following statement:
81+
82+
{% include_cached copy-clipboard.html %}
83+
~~~ sql
84+
SHOW INSPECT ERRORS FOR JOB 1141477013029322753;
85+
~~~
86+
87+
If there are no errors associated with that job ID, the output is:
88+
89+
~~~
90+
SHOW INSPECT ERRORS 0
91+
~~~
92+
93+
Note that if you issue a job ID for a nonexistent job, you will see the same output as for a job with no errors:
94+
95+
{% include_cached copy-clipboard.html %}
96+
~~~ sql
97+
SHOW INSPECT ERRORS FOR JOB 0;
98+
~~~
99+
100+
~~~
101+
SHOW INSPECT ERRORS 0
102+
~~~
103+
104+
### Show errors with details
105+
106+
{% include_cached copy-clipboard.html %}
107+
~~~ sql
108+
SHOW INSPECT ERRORS FOR TABLE movr.public.users WITH DETAILS;
109+
~~~
110+
111+
## See also
112+
113+
- [`INSPECT`]({% link {{ page.version.version }}/inspect.md %})
114+
- [`SHOW JOBS`]({% link {{ page.version.version }}/show-jobs.md %})
115+
- [Jobs page in DB Console]({% link {{ page.version.version }}/ui-jobs-page.md %})
116+
- [Authorization]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges)

src/current/v26.1/show-jobs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The following fields are returned for each job:
6161
Field | Description
6262
------|------------
6363
`job_id` | A unique ID to identify each job. This value is used if you want to control jobs (i.e., [pause]({% link {{ page.version.version }}/pause-job.md %}), [resume]({% link {{ page.version.version }}/resume-job.md %}), or [cancel]({% link {{ page.version.version }}/cancel-job.md %}) it).
64-
`job_type` | The type of job: [`SCHEMA CHANGE`]({% link {{ page.version.version }}/online-schema-changes.md %}), [`NEW SCHEMA CHANGE`]({% link {{ page.version.version }}/online-schema-changes.md %}), [`KEY VISUALIZER`]({% link {{ page.version.version }}/ui-key-visualizer.md %}), [`MIGRATION`]({% link {{ page.version.version }}/upgrade-cockroach-version.md %}#overview), [`BACKUP`]({% link {{ page.version.version }}/backup.md %}), [`RESTORE`]({% link {{ page.version.version }}/restore.md %}), [`IMPORT`]({% link {{ page.version.version }}/import-into.md %}), [`CHANGEFEED`](#show-changefeed-jobs), [`CREATE STATS`]({% link {{ page.version.version }}/create-statistics.md %}), [`ROW LEVEL TTL`]({% link {{ page.version.version }}/row-level-ttl.md %}), [`REPLICATION STREAM INGESTION`]({% link {{ page.version.version }}/physical-cluster-replication-monitoring.md %}), `REPLICATION STREAM PRODUCER`([physical cluster replication]({% link {{ page.version.version }}/physical-cluster-replication-monitoring.md %}) or [logical data replication]({% link {{ page.version.version }}/logical-data-replication-monitoring.md %})), [`LOGICAL REPLICATION`]({% link {{ page.version.version }}/logical-data-replication-monitoring.md %}). <br><br>For job types of automatic jobs, see [Show automatic jobs](#show-automatic-jobs).
64+
`job_type` | The type of job: [`SCHEMA CHANGE`]({% link {{ page.version.version }}/online-schema-changes.md %}), [`NEW SCHEMA CHANGE`]({% link {{ page.version.version }}/online-schema-changes.md %}), [`KEY VISUALIZER`]({% link {{ page.version.version }}/ui-key-visualizer.md %}), [`MIGRATION`]({% link {{ page.version.version }}/upgrade-cockroach-version.md %}#overview), [`BACKUP`]({% link {{ page.version.version }}/backup.md %}), [`RESTORE`]({% link {{ page.version.version }}/restore.md %}), [`IMPORT`]({% link {{ page.version.version }}/import-into.md %}), [`CHANGEFEED`](#show-changefeed-jobs), [`CREATE STATS`]({% link {{ page.version.version }}/create-statistics.md %}), [`INSPECT`]({% link {{ page.version.version }}/inspect.md %}), [`ROW LEVEL TTL`]({% link {{ page.version.version }}/row-level-ttl.md %}), [`REPLICATION STREAM INGESTION`]({% link {{ page.version.version }}/physical-cluster-replication-monitoring.md %}), `REPLICATION STREAM PRODUCER`([physical cluster replication]({% link {{ page.version.version }}/physical-cluster-replication-monitoring.md %}) or [logical data replication]({% link {{ page.version.version }}/logical-data-replication-monitoring.md %})), [`LOGICAL REPLICATION`]({% link {{ page.version.version }}/logical-data-replication-monitoring.md %}). <br><br>For `INSPECT` jobs, you can use the `job_id` value with [`SHOW INSPECT ERRORS FOR JOB {job_id}`]({% link {{ page.version.version }}/show-inspect-errors.md %}). <br><br>For job types of automatic jobs, see [Show automatic jobs](#show-automatic-jobs).
6565
`description` | The statement that started the job, or a textual description of the job. When you run `SHOW JOBS`, the `description` field is limited to 100 characters. To view the full description for a job, run `SHOW JOB {job ID}`.
6666
`statement` | When `description` is a textual description of the job, the statement that started the job is returned in this column. Currently, this field is populated only for the automatic table statistics jobs.
6767
`user_name` | The name of the [user]({% link {{ page.version.version }}/security-reference/authorization.md %}#create-and-manage-users) who started the job.

0 commit comments

Comments
 (0)