|
| 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. |
| 9 | + |
| 10 | +{{site.data.alerts.callout_info}} |
| 11 | +`INSPECT` does not automatically repair errors. |
| 12 | +{{site.data.alerts.end}} |
| 13 | + |
| 14 | +## Considerations |
| 15 | + |
| 16 | +[XXX](XXX): DECIDE WHICH THINGS SHOULD GO IN KNOWN LIMITATIONS |
| 17 | + |
| 18 | +- `INSPECT` always runs as a [background job]({% link {{ page.version.version }}/show-jobs.md %}). |
| 19 | +- `INSPECT` must be run in an implicit transaction. 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 %}). |
| 20 | +- `INSPECT` runs with low priority admission control and may take time on large datasets. Plan to run during periods of lower load. |
| 21 | +- Unsupported indexes (such as vector, partial, or expression indexes) are skipped when using the default `INDEX ALL` behavior. If an unsupported index is explicitly requested using `INDEX (...)`, the statement fails before starting. |
| 22 | + |
| 23 | +## Required privileges |
| 24 | + |
| 25 | +To run `INSPECT` and view its results, the user must have: |
| 26 | + |
| 27 | +- The `INSPECT` system-level [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges). |
| 28 | +- The `VIEWSYSTEMTABLE` system-level [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges) (required to view results via [`SHOW INSPECT ERRORS`]({% link {{ page.version.version }}/show-inspect-errors.md %})). |
| 29 | + |
| 30 | +## Syntax |
| 31 | + |
| 32 | +[XXX](XXX): ADD SQL DIAGRAM |
| 33 | + |
| 34 | +~~~ sql |
| 35 | +INSPECT TABLE <table_name> [AS OF SYSTEM TIME <expr>] [WITH OPTIONS ( <option> [, ...] )] [DETACHED] |
| 36 | + |
| 37 | +INSPECT DATABASE <database_name> [AS OF SYSTEM TIME <expr>] [WITH OPTIONS ( <option> [, ...] )] [DETACHED] |
| 38 | +~~~ |
| 39 | + |
| 40 | +## Parameters |
| 41 | + |
| 42 | +Parameter | Description |
| 43 | +----------|------------ |
| 44 | +`table_name` | The table to inspect. |
| 45 | +`database_name` | The database to inspect. |
| 46 | +`AS OF SYSTEM TIME <expr>` | Optional. Run inspection against a historical read timestamp. For details, see [`AS OF SYSTEM TIME`]({% link {{ page.version.version }}/as-of-system-time.md %}). |
| 47 | +`WITH OPTIONS (...)` | Optional. Controls which indexes are inspected. See [Options](#options). |
| 48 | +`DETACHED` | Optional. Run the inspection job asynchronously and return the job ID without waiting for completion. To monitor progress, use [`SHOW JOBS`]({% link {{ page.version.version }}/show-jobs.md %}). |
| 49 | + |
| 50 | +### Options |
| 51 | + |
| 52 | +Option | Description |
| 53 | +-------|------------ |
| 54 | +`INDEX ALL` | Inspect all supported indexes in the target table or database. This is the default. |
| 55 | +`INDEX (<indexname> [, ...])` | Inspect only the specified indexes. `INDEX ALL` and `INDEX (...)` are mutually exclusive. |
| 56 | + |
| 57 | +## Viewing results |
| 58 | + |
| 59 | +To view errors found by an inspection job, use [`SHOW INSPECT ERRORS`]({% link {{ page.version.version }}/show-inspect-errors.md %}). Errors are stored internally and may be subject to retention policies. |
| 60 | + |
| 61 | +## Examples |
| 62 | + |
| 63 | +### Inspect a table (all supported indexes) |
| 64 | + |
| 65 | +{% include_cached copy-clipboard.html %} |
| 66 | +~~~ sql |
| 67 | +INSPECT TABLE movr.public.users; |
| 68 | +~~~ |
| 69 | + |
| 70 | +### Inspect a table for specific indexes |
| 71 | + |
| 72 | +{% include_cached copy-clipboard.html %} |
| 73 | +~~~ sql |
| 74 | +INSPECT TABLE movr.public.users WITH OPTIONS (INDEX (users_pkey, users_name_idx)); |
| 75 | +~~~ |
| 76 | + |
| 77 | +### Inspect at a specific timestamp |
| 78 | + |
| 79 | +{% include_cached copy-clipboard.html %} |
| 80 | +~~~ sql |
| 81 | +INSPECT TABLE movr.public.users AS OF SYSTEM TIME '-10s'; |
| 82 | +~~~ |
| 83 | + |
| 84 | +### Run an inspection job asynchronously |
| 85 | + |
| 86 | +{% include_cached copy-clipboard.html %} |
| 87 | +~~~ sql |
| 88 | +INSPECT TABLE movr.public.users DETACHED; |
| 89 | +~~~ |
| 90 | + |
| 91 | +The job ID is returned after job creation completes: |
| 92 | + |
| 93 | +~~~ |
| 94 | + job_id |
| 95 | +---------------------- |
| 96 | + 592786066399264769 |
| 97 | +(1 row) |
| 98 | +~~~ |
| 99 | + |
| 100 | +## Known limitations |
| 101 | + |
| 102 | +[XXX](XXX): FILL IN KNOWN LIMITATIONS SECTION |
| 103 | + |
| 104 | +## See also |
| 105 | + |
| 106 | +- [`SHOW INSPECT ERRORS`]({% link {{ page.version.version }}/show-inspect-errors.md %}) |
| 107 | +- [`SHOW JOBS`]({% link {{ page.version.version }}/show-jobs.md %}) |
| 108 | +- [Jobs page in DB Console]({% link {{ page.version.version }}/ui-jobs-page.md %}) |
| 109 | +- [`AS OF SYSTEM TIME`]({% link {{ page.version.version }}/as-of-system-time.md %}) |
| 110 | +- [Authorization]({% link {{ page.version.version }}/security-reference/authorization.md %}) |
| 111 | +- [INSPECT privilege](XXX) |
0 commit comments