Skip to main content
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 SettingsRunning Queries. See Running Queries for details.

To identify long-running queries across your organization, see the 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

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:

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

Using md_interrupt_server_connection in conjunction with md_active_server_connections to interrupt a subset or all of the active connections:

-- 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.