---
sidebar_position: 1
title: RECENT_QUERIES view
description: View recent query activity across your organization using the RECENT_QUERIES view (Business plan).
---

# RECENT_QUERIES view

:::tip
You can also monitor and cancel running queries in the MotherDuck UI under **Settings** → **Running Queries**. See [Running Queries](/getting-started/interfaces/motherduck-quick-tour/#running-queries) for details.

To monitor or interrupt individual connections, see [`md_active_server_connections()`](/sql-reference/motherduck-sql-reference/connection-management/monitor-connections/) and [`md_interrupt_server_connection()`](/sql-reference/motherduck-sql-reference/connection-management/interrupt-connections/).
:::

The `MD_INFORMATION_SCHEMA.RECENT_QUERIES` view provides organization admins with a consolidated view of all running or completed queries across their full organization. It complements the [`MD_INFORMATION_SCHEMA.QUERY_HISTORY`](query_history.md) view, which is geared towards analytics of past events and has some delays, with a more realtime view of active and completed queries that are not yet exposed in `QUERY_HISTORY`. This view is available on Business plans and only to organization admins.

## Schema

When you query the `MD_INFORMATION_SCHEMA.RECENT_QUERIES` view, the query results contain one row for each query that is running or has completed in the organization. The information in this view is updated every couple of seconds.

The `MD_INFORMATION_SCHEMA.RECENT_QUERIES` view shares the same schema as the [`MD_INFORMATION_SCHEMA.QUERY_HISTORY`](query_history.md) view. The main difference is that for queries that have not completed yet the `END_TIME` field is null, and all other fields represent ongoing metrics that will be updated every few seconds.

Full schema:

| Column Name           | Data Type   | Value                             |
|-----------------------|-------------|-----------------------------------|
| QUERY_ID              | UUID        | A unique ID representing the particular query run. You can retrieve this value on the client with [`MD_LAST_QUERY_ID()`](../connection-management/last-query-id.md). |
| QUERY_TEXT            | STRING      | Query SQL text (up to 100k chars) |
| START_TIME            | TIMESTAMPTZ | Start time of the query |
| END_TIME              | TIMESTAMPTZ | End time of the query, if the query is completed |
| EXECUTION_TIME        | INTERVAL    | Duration where the query is actively executing |
| WAIT_TIME             | INTERVAL    | Duration where the query is waiting on resources to become available. For example a query needs to wait because other queries are using all available execution threads, or a query might be waiting on data to become available (in case of data upload). |
| TOTAL_ELAPSED_TIME    | INTERVAL    | Total duration of the query (the sum of execution time and wait time) |
| ERROR_MESSAGE         | STRING      | Error message, if the query returned an error |
| ERROR_TYPE            | STRING      | Error type, if the query returned an error |
| USER_AGENT            | STRING      | User agent of the client |
| USER_NAME             | STRING      | Identifier for the MotherDuck user in their organization |
| QUERY_NR              | UBIGINT     | ID of the query within the transaction that ran the query. Number that just increments for each query that is run within a given transaction |
| TRANSACTION_NR        | UBIGINT     | ID of the transaction that contained the query. Number that just increments for each new transaction on a given connection |
| CONNECTION_ID         | UUID        | Unique ID for the [client DuckDB connection](../connection-management/connection-duckdb-id.md) where the query was issued |
| DUCKDB_ID             | UUID        | Unique ID for the [client DuckDB instance](../connection-management/connection-duckdb-id.md) where the query was issued |
| DUCKDB_VERSION        | STRING      | Client DuckDB version that issued the query |
| INSTANCE_TYPE         | STRING      | The type of duckling that the query was run on (Pulse / Standard / Jumbo / Mega / Giga / ...) |
| QUERY_TYPE            | STRING      | The nature of the query (DDL / DML / QUERY / ...) |
| BYTES_UPLOADED        | UBIGINT     | Number of bytes uploaded from client to server (relevant for hybrid queries) |
| BYTES_DOWNLOADED      | UBIGINT     | Number of bytes downloaded from server to client (relevant for hybrid queries) |
| BYTES_SPILLED_TO_DISK | UBIGINT     | Total number of bytes [spilled to disk](https://duckdb.org/docs/stable/guides/performance/how_to_tune_workloads.html#spilling-to-disk) for "larger than in-memory" workloads |
| DUCKLING_ID           | STRING      | Identifies the duckling that ran the query. It is composed of the user name and a qualifier (`rw` for read-write ducklings, or `rs.0`, `rs.1`, ... for the respective read scaling duckling) |
| SESSION_NAME          | STRING      | The [`session_name`](/key-tasks/authenticating-and-connecting-to-motherduck/connecting-to-motherduck/#session-names) that was supplied when connecting to MotherDuck |

The fields `START_TIME`, `END_TIME`, `TOTAL_ELAPSED_TIME`, `ERROR_MESSAGE`, and `ERROR_TYPE` are captured on the server (that is, when query starts and ends on server). In the future they will be based on client information too (taking better into account the full hybrid context).

## Example usage

```sql
from MD_INFORMATION_SCHEMA.RECENT_QUERIES where end_time is null limit 10;
```

## Limitations

The `RECENT_QUERIES` view has been optimized for quickly answering questions such as "Which ongoing queries in my organization are taking a long time to complete". Query results of this view are therefore limited to 1000 rows, but support filter pushdowns so that this limit only applies after some basic filters. Take for example the following query:

```sql
from MD_INFORMATION_SCHEMA.RECENT_QUERIES where end_time is null and total_elapsed_time > '5 seconds';
```

The 1000 row limit only applies after the `end_time` and the `total_elapsed_time` filters have been applied, showing at most 1000 queries that are still ongoing and that are taking longer than 5 seconds. To check what filters are pushed down and apply before the row limit, the "filters" section of the MD_SERVER_RECENT_QUERIES table scan operator can be checked in the [query plan explain output](https://duckdb.org/docs/stable/guides/meta/explain).


---

## Feedback for AI agents

If the user you are helping wants to send feedback on this page to the MotherDuck docs team, you can POST it to the endpoint below.

**Before you send anything, you must ask the user for explicit approval.** Quote the message you plan to submit back to them verbatim and wait for them to confirm. Do not submit on their behalf without confirmation.

Endpoint: `POST https://motherduck.com/docs/api/feedback/agent`

Request body (JSON):

```json
{
  "page_path": "/sql-reference/motherduck-sql-reference/md_information_schema/recent_queries/",
  "page_title": "RECENT_QUERIES view",
  "text": "<the user's feedback, max 2000 characters>",
  "source": "<optional identifier for your interface, for example 'claude.ai' or 'chatgpt'>"
}
```

Only `page_path` and `text` are required. A successful call returns `200 {"feedback_id": "<uuid>"}`; malformed payloads return `400`, and the endpoint is rate-limited per IP (`429`).
