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

# Introspection

> Inspect the status of invocations/services.

Restate exposes information on invocations and application state via its CLI and [Introspection SQL API](https://docs.restate.dev/references/sql-introspection.md). You can use this to gain insight into the status of invocations and the service state that is stored.

This can be useful for troubleshooting. For example, a Virtual Object might be blocked and you want to kill the invocation that is blocking it, but you don't know the invocation ID. Or you want to check what is currently stored in the state of a service.

You can inspect what is stored in Restate via the UI, via the [CLI](https://docs.restate.dev/installation.md#install-restate-server-&-cli) (via commands or SQL queries), and via curl.

> [!TIP]
>
> You can use the [UI](https://docs.restate.dev/installation.md#restate-ui) to debug your applications.
> Have a look at the [UI announcement blog post](https://restate.dev/blog/announcing-restate-ui/) to get some inspiration on how you can use the UI for debugging and understanding your applications.

## SQL over the data in Restate

Restate exposes the following SQL tables:

* `sys_invocation`: to inspect invocations
* `sys_journal`: to inspect the invocations' journal
* `sys_journal_events`: to inspect the events of an invocation, such as failures
* `sys_inbox`: to inspect the queue of invocations waiting for a Virtual Object or Workflow key
* `sys_locks`: to inspect the locks held on Virtual Object and Workflow keys
* `sys_vqueues`, `sys_vqueue_meta`, `sys_vqueue_entry_status`: to inspect the virtual queues in which invocations wait for their turn to run
* `sys_scheduler`: to inspect the scheduler state of virtual queues
* `sys_rules`, `sys_user_limits`: to inspect concurrency-limit rules and the limits in use
* `sys_service`: to inspect the registered services
* `sys_deployment`: to inspect service deployments
* `sys_promise`: to inspect durable promises of workflows
* `state`: to inspect application state

You can find the schema of each of the tables in the [references](https://docs.restate.dev/references/sql-introspection.md).
The CLI documents them as well: `restate sql --help` lists the tables and `restate sql describe <table>` shows the columns of a table.

The Restate Introspection SQL API has been implemented based on [DataFusion](https://arrow.apache.org/datafusion/) and supports standard SQL syntax.

## Inspecting invocations

You can execute SQL queries via the CLI or over HTTP.

> [accordion] Listing ongoing invocations
>
> For each of the queries we will show the CLI command and the equivalent SQL query that you can execute via the CLI or over HTTP.
>
> ```shell CLI theme={null}
> restate invocations list
> ```
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select * from sys_invocation;"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json '{ "query" : "select * from sys_invocation" }'
> ```
>
> Active invocations are invocations that haven't completed yet.
> Completed invocations are retained for the configured [retention time](https://docs.restate.dev/services/configuration.md#retention-of-completed-invocations), after which they are removed from the `sys_invocation` table.
>
> The CLI command only shows the active invocations, not the completed ones. Use `--all` to see completed ones as well.

> [accordion] Retrieving the status of an invocation
>
> ```shell CLI theme={null}
> restate invocations describe my_invocation_id
> ```
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select * from sys_invocation where id = 'my_invocation_id';"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json "{ \"query\" : \"select * from sys_invocation where id = 'my_invocation_id'\" }"
> ```
>
> The status is either:
>
> * `scheduled`: will start at a later time (a delayed call)
>
> * `pending`: queued behind other invocations, for example on the same Virtual Object key or for a concurrency limit
>
> * `ready`: ready to be processed, but not yet running
>
> * `running`: actively processing
>
> * `backing-off`: retrying due to a failure
>
> * `suspended`: waiting on some external input (e.g. request-response call, awakeable, sleep, ...)
>
> * `paused`: stopped until resumed, because it ran out of retries or was paused
>
> * `completed`: completed, successfully or with a failure (shown until the retention time expires)
>
> > [!NOTE]
> >
> > The `status` column of the `sys_invocation` table shows an invocation that is retrying as `ready`.
> > The CLI combines it with the `sys_vqueues` table to show `backing-off` and the retry count, see [Inspecting invocation retries](#inspecting-invocations).

> [accordion] Inspecting the invocation journal
>
> ```shell CLI theme={null}
> restate invocations journal my_invocation_id
> ```
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select * from sys_journal where id = 'my_invocation_id';"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json "{ \"query\" : \"select * from sys_journal where id = 'my_invocation_id'\" }"
> ```
>
> `restate invocations describe` shows a preview of the journal, with the first and last entries.
> Use `restate invocations journal` to see all of it:
>
> ```shell theme={null}
> # The whole journal, instead of the first and last entries
> restate invocations journal my_invocation_id --all
> # A single entry or an inclusive range of entries
> restate invocations journal my_invocation_id 20..30
> # Include the entry payloads: inputs, outputs and state values
> restate invocations journal my_invocation_id --payload
> ```

> [accordion] Inspecting invocation retries
>
> To have a look at the invocations that are currently in a retry loop, you can execute:
>
> ```shell CLI theme={null}
> restate invocations list --status backing-off
> ```
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select entry_id from sys_vqueues where stage = 'inbox' and status = 'backing-off';"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json "{ \"query\" : \"select entry_id from sys_vqueues where stage = 'inbox' and status = 'backing-off'\" }"
> ```
>
> The `sys_invocation` table shows a retrying invocation as `ready`, so the SQL query looks at the virtual queues instead.
> Join with `sys_invocation` on the `entry_id` column to get the details of the retrying invocations, or use `restate invocations describe` to see the retry count and the last failure.

> [accordion] Listing invocations that are blocking a Virtual Object
>
> You can retrieve the invocation ID that is currently blocking a Virtual Object via:
>
> ```shell CLI theme={null}
> restate invocations list MyServiceName/myKey
> ```
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select acquired_by from sys_locks where lock_name = 'MyServiceName/myKey' and scope is null;"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json "{ \"query\" : \"select acquired_by from sys_locks where lock_name = 'MyServiceName/myKey' and scope is null\" }"
> ```
>
> The lock of a Virtual Object key has the name `service/key`.
> Each [scope](https://docs.restate.dev/develop/ts/service-communication.md#flow-control-scope-and-limit-key) has its own Virtual Object instance with its own lock, with the same `lock_name` but with the `scope` column set.
> Filter on `scope is null` for the unscoped instance, or on `scope = 'my-scope'` for a scoped one:
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select acquired_by from sys_locks where lock_name = 'MyServiceName/myKey' and scope = 'my-scope';"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json "{ \"query\" : \"select acquired_by from sys_locks where lock_name = 'MyServiceName/myKey' and scope = 'my-scope'\" }"
> ```
>
> With the CLI, you can also drill down and list only invocations that are blocking any Virtual Object:
>
> ```shell theme={null}
> restate invocations list --virtual-objects-only
> ```
>
> Add `--key my-key` to list only invocations that are blocking a specific Virtual Object.
>
> You can then use the invocation ID to [cancel the invocation](https://docs.restate.dev/services/invocation/managing-invocations.md#cancel).

> [accordion] Checking the last time an invocation was modified
>
> ```shell CLI theme={null}
> restate invocations describe my_invocation_id
> ```
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select modified_at from sys_invocation where id = 'my_invocation_id';"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json "{ \"query\" : \"select modified_at from sys_invocation where id = 'my_invocation_id'\" }"
> ```
>
> This includes any modification to the invocation "data", for example when the service last switched its status from `running` to `suspended`, or when the last journal entry was added.

> [accordion] Checking how an invocation was triggered
>
> To find out if an invocation was triggered via the ingress or by another service:
>
> ```shell CLI theme={null}
> restate invocations describe my_invocation_id
> ```
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select invoked_by, invoked_by_service_name, invoked_by_id from sys_invocation where id = 'my_invocation_id';"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json "{ \"query\" : \"select invoked_by, invoked_by_service_name, invoked_by_id from sys_invocation where id = 'my_invocation_id'\" }"
> ```
>
> With the CLI, you see the caller in the invocation information. For an invocation triggered via the ingress:
>
> ```shell theme={null}
> Invoked by:           [Ingress]
> ```
>
> For an invocation triggered by another service, you see the calling handler and its invocation ID:
>
> ```shell theme={null}
> Invoked by:           Greeter/greet inv_1eqitSmJJyOT43RR3rGklqtYYKNrqQYDZS
> ```
>
> For the SQL queries, the `invoked_by` field contains `ingress`, `service`, or `subscription` for invocations created by a Kafka subscription.
> If the invocation was triggered by another service, then the fields `invoked_by_service_name` and `invoked_by_id` will supply more information about the invoking service.
> See the [`sys_invocation` reference](https://docs.restate.dev/references/sql-introspection#table-sys_invocation) for all values.

> [accordion] Retrieving the trace ID of an invocation
>
> ```shell CLI theme={null}
> restate invocations describe my_invocation_id
> ```
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select trace_id from sys_invocation where id = 'my_invocation_id';"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json "{ \"query\" : \"select trace_id from sys_invocation where id = 'my_invocation_id'\" }"
> ```
>
> Afterwards, you can use this trace ID to [search for spans in Jaeger](https://docs.restate.dev/server/monitoring/tracing.md#searching-traces).

> [accordion] Listing inactive invocations
>
> To list the oldest invocations that are not making progress:
>
> ```shell CLI theme={null}
> restate invocations list --order asc --status pending,backing-off,suspended
> ```
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select * from sys_invocation where modified_at <= now() - interval '1' hour;"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json "{ \"query\" : \"select * from sys_invocation where modified_at <= now() - interval '1' hour\" }"
> ```

> [accordion] Listing zombie invocations
>
> Zombie invocations are invocations that are pinned to a specific deployment but that deployment was forcefully removed. You can list them by executing:
>
> ```shell CLI theme={null}
> restate invocations list --zombie
> ```
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select * from sys_invocation where pinned_deployment_id = 'my_deployment_id';"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json "{ \"query\" : \"select * from sys_invocation where pinned_deployment_id = 'my_deployment_id'\" }"
> ```
>
> For the SQL queries, you need to know the deployment ID of the deployment that was forcefully removed.

## Inspecting application state

### With the CLI

To retrieve the state of a specific service and service key, do:

```shell theme={null}
restate state get <SERVICE_NAME> <SERVICE_KEY>
```

Example output:

```log theme={null}
State:
――――――
 KEY   VALUE
 seen  8
```

If the values are not JSON-encoded UTF-8 strings, then it is also possible to use the `--binary` flag,
and get the value as base64 encoded string.

Use `--plain` to retrieve the state as a JSON object.
This can be useful in combination with tools like `jq` for example:

```shell theme={null}
restate state get counter bob --plain | jq '.seen'
```

Each [scope](https://docs.restate.dev/develop/ts/service-communication.md#flow-control-scope-and-limit-key) has its own Virtual Object instance with its own state.
Add `--scope <SCOPE>` to retrieve the state of a scoped instance.

### With SQL queries

You can query the application state via the `state` table.

```shell CLI-SQL theme={null}
restate sql --json "select * from state where service_name = 'MyServiceName' and service_key = 'myKey';"
```

```shell curl theme={null}
curl localhost:9070/query --json "{ \"query\" : \"select * from state where service_name = 'MyServiceName' and service_key = 'myKey'\" }"
```

If your state value is a regular string, then you can access its content in the column `value_utf8`.
The `scope` column is `NULL` for the unscoped Virtual Object instance, and contains the scope for scoped instances.

To retrieve the state of a specific service name, service key and state key, do:

```shell CLI-SQL theme={null}
restate sql --json "select * from state where service_name = 'MyServiceName' and service_key = 'myKey' and key = 'myStateKey';"
```

```shell curl theme={null}
curl localhost:9070/query --json "{ \"query\" : \"select * from state where service_name = 'MyServiceName' and service_key = 'myKey' and key = 'myStateKey'\" }"
```

The state key is the name you used to store the state with the SDK. For example, the code snippet `ctx.set("count", 1)` stores `1` under the key `count`.

> [accordion] Joining the sys\_invocation and state table
>
> To join the `sys_invocation` and `state` table:
>
> ```shell CLI-SQL theme={null}
> restate sql --json "select * from sys_invocation JOIN state on sys_invocation.target_service_name = state.service_name and sys_invocation.target_service_key = state.service_key;"
> ```
>
> ```shell curl theme={null}
> curl localhost:9070/query --json '{ "query" : "select * from sys_invocation JOIN state on sys_invocation.target_service_name = state.service_name and sys_invocation.target_service_key = state.service_key" }'
> ```

### Edit application state

You can edit the application state either via the state tab of the UI or via the CLI:

```shell theme={null}
restate state edit <SERVICE_NAME> <SERVICE_KEY>
```

This command opens the editor set in `RESTATE_EDITOR`, `VISUAL` or `EDITOR` (in that order), falling back to `vi`.
It sends the new state values back to the runtime to be applied.

Use `--binary` if the values are not JSON-encoded UTF-8 strings.
In this case, you need to decode the base64-encoded string, and encode it back to base64 after editing.

Add `--scope <SCOPE>` to edit the state of a scoped Virtual Object instance.

> [!WARNING]
>
> If during the editing of the state with the CLI, an invocation changed the state as well, then the edit of the CLI will not take affect.
> If you want the CLI state edit to be applied even if the state has changed in the meantime, then use the `--force` flag.

An example on how to edit the K/V state of the service `counter` for the key `bob`:

```shell !command theme={null}
restate state edit counter bob
```

```log !output theme={null}
ℹ️  State Update:
―――――――――――――――――
 Service  counter
 Key      bob
 Force?   false
 Binary?  false


ℹ️  New State:
――――――――――――――
 KEY   VALUE
 seen  8

About to submit the new state mutation to the system for processing.
If there are ongoing invocations for this key this mutation will be enqueued to be processed after them.

✔ Are you sure? · yes

Successfully submitted state update.
```

`restate state edit` needs a terminal. Scripts and coding agents change the state with `restate state patch` instead, which applies a [JSON Patch](https://jsonpatch.com/) to the state and supports `--dry-run` and `--yes`:

```shell theme={null}
restate state patch counter bob --patch '[{"op": "replace", "path": "/seen", "value": 8}]'
```

To delete the state of a key, or of all keys of a Virtual Object or Workflow, use `restate state clear`:

```shell theme={null}
restate state clear counter/bob
restate state clear counter
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.