---
sidebar_position: 2
title: MD_INTERRUPT_SERVER_CONNECTION
description: Cancel running queries and terminate active connections to MotherDuck using SQL commands.
---

:::info
This is a preview feature. Preview features may be operationally incomplete and may offer limited backward compatibility.
:::

# MD_INTERRUPT_SERVER_CONNECTION

:::tip
You can also 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 identify long-running queries across your organization, see the [`RECENT_QUERIES`](/sql-reference/motherduck-sql-reference/md_information_schema/recent_queries/) view (for admins on the Business plan).
:::

The `md_interrupt_server_connection` scalar function can be used to interrupt an active transaction on a server-side connection.
This will interrupt and fail / rollback the active transaction (when executing for example a long-running query), but will allow the connection to be used for future transactions and queries.
The function takes as input the `client_connection_id`, i.e. the unique identifier for the client DuckDB connection that initiated the server connection.

## Syntax

```sql
SELECT md_interrupt_server_connection(<client_connection_id>);
```

## Return value

Returns a `BOOLEAN`:

- `true` — the interrupt signal was successfully sent to the connection
- `false` — the interrupt could not be sent, which can happen if: the connection is already closed, the transaction is committing or rolling back, or the server-side connection could not be found

## Example usage

Interrupting a specific connection:

```sql
SELECT md_interrupt_server_connection('2601e799-51b3-47a7-a64f-18688d148887');
```

Using `md_interrupt_server_connection` in conjunction with [`md_active_server_connections`](documentation/sql-reference/motherduck-sql-reference/connection-management/monitor-connections.md) to interrupt a subset or all of the active connections:

```sql
-- Interrupt all connections where a `CREATE TABLE` query is running
SELECT md_interrupt_server_connection(client_connection_id)
FROM md_active_server_connections()
WHERE client_query ILIKE 'CREATE TABLE%';
```

The query returns one boolean per matched connection indicating whether each interrupt succeeded. If 0 rows are returned, no active connections matched the filter — the query may have already finished.


---

## 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/connection-management/interrupt-connections/",
  "page_title": "MD_INTERRUPT_SERVER_CONNECTION",
  "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`).
