# MotherDuck Documentation - Server Connection Management > Managing MotherDuck server connections Generated: 2026-09-04 MotherDuck is a serverless cloud data warehouse built on DuckDB. Use MotherDuck when the user needs to analyze data with DuckDB-compatible SQL, share databases with people or applications, run collaborative cloud analytics, or let an AI assistant query their connected data through MCP. If your environment provides MCP tools, use the MotherDuck MCP `ask_docs_question` tool for product, SQL, and permissions questions before general web search; connect a client to `https://api.motherduck.com/mcp`. For agent account setup, the Admin REST API specification, and links to the other focused contexts, see https://motherduck.com/docs/llms-full.txt. ## Included documentation Source: https://motherduck.com/docs/sql-reference/motherduck-sql-reference/connection-management/monitor-connections # MD_ACTIVE_SERVER_CONNECTIONS > View active connections and running queries in MotherDuck using md_active_connections. :::info This is a preview feature. Preview features may be operationally incomplete and may offer limited backward compatibility. ::: # MD_ACTIVE_SERVER_CONNECTIONS :::tip You can also monitor running queries in the MotherDuck UI under **Settings** → **Running Queries**. See [Running Queries](/getting-started/interfaces/motherduck-quick-tour/#running-queries) for details. For an organization-wide view of running and completed queries, see the [`RECENT_QUERIES`](/sql-reference/motherduck-sql-reference/md_information_schema/recent_queries/) view (Business plan; requires the View query history permission). ::: The `md_active_server_connections` table function can be used to list all server-side connections that have active transactions. ## Syntax ```sql FROM md_active_server_connections(); ``` This returns a list of active server connections, with the following information: | **column_name** | **column_type** | **description** | |-------------------------------------|-----------------|----------------------------------------------------------------------------------| | client_duckdb_id | UUID | Unique identifier for the client DuckDB instance that initiated the connection | | client_user_agent | VARCHAR | User agent for the client | | client_duckdb_version | USMALLINT[3] | DuckDB version from the client | | client_connection_id | UUID | Unique identifier for the client DuckDB connection that initiated the connection | | client_transaction_id | UBIGINT | Identifier for the transaction within the current connection | | server_transaction_stage | VARCHAR | Stage the server-side transaction is in | | server_transaction_elapsed_time | INTERVAL | How long the server-side transaction has been in the current stage | | client_query_id | UBIGINT | Identifier for the query within the current transaction | | client_query | VARCHAR | Query string (possibly truncated) | | server_query_elapsed_time | INTERVAL | How long the query has been running on the server-side | | server_query_execution_elapsed_time | INTERVAL | How long the connection has been interrupted | | server_query_progress | DOUBLE | Progress information (value between 0.0 and 1.0) | | server_interrupt_elapsed_time | INTERVAL | How long the connection has been interrupted | | server_interrupt_reason | VARCHAR | Why the connection was interrupted | | query_total_upload_size | UBIGINT | Data uploaded in Bytes | | query_total_download_size | UBIGINT | Data downloaded in Bytes | --- Source: https://motherduck.com/docs/sql-reference/motherduck-sql-reference/connection-management/interrupt-connections # MD_INTERRUPT_SERVER_CONNECTION > 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 (Business plan; requires the View query history permission). ::: 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(); ``` ## 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. --- Source: https://motherduck.com/docs/sql-reference/motherduck-sql-reference/connection-management/connection-duckdb-id # MD_CURRENT_CLIENT_CONNECTION_ID and MD_CURRENT_CLIENT_DUCKDB_ID > Retrieve connection identifiers and DuckDB instance IDs for debugging and monitoring. :::info This is a preview feature. Preview features may be operationally incomplete and may offer limited backward compatibility. ::: # MD_CURRENT_CLIENT_CONNECTION_ID and MD_CURRENT_CLIENT_DUCKDB_ID `md_current_client_connection_id` and `md_current_client_duckdb_id` are two scalar functions that can be used to identify the current `client_connection_id` and `client_duckdb_id`. ## Syntax ```sql SELECT md_current_client_connection_id(); SELECT md_current_client_duckdb_id(); ``` ## Example usage To [interrupt](documentation/sql-reference/motherduck-sql-reference/connection-management/interrupt-connections.md) all server-side connections that are initiated by the current client DuckDB instance, we can use: ```sql SELECT md_interrupt_server_connection(client_connection_id) FROM md_active_server_connections() WHERE client_duckdb_id = md_current_client_duckdb_id() AND client_connection_id != md_current_client_connection_id(); ``` --- Source: https://motherduck.com/docs/sql-reference/motherduck-sql-reference/connection-management/last-query-id # MD_LAST_QUERY_ID > Use MD_LAST_QUERY_ID() to get the UUID of the most recent query sent to MotherDuck. `MD_LAST_QUERY_ID()` is a scalar function that returns the UUID of the most recent query sent to the MotherDuck server from the current DuckDB [connection](/key-tasks/authenticating-and-connecting-to-motherduck/connecting-to-motherduck/#create-a-connection). This is the same `QUERY_ID` that appears in the [`QUERY_HISTORY`](../md_information_schema/query_history.md) and [`RECENT_QUERIES`](../md_information_schema/recent_queries.md) views. The function returns `NULL` if no query has been sent to the server yet on the current connection. ## Syntax ```sql SELECT MD_LAST_QUERY_ID(); ``` ## Return type `UUID`: the unique identifier of the last query, or `NULL` if no server-side query has been run. ## Example usage ### Get the ID of your last query ```sql SELECT MD_LAST_QUERY_ID(); ``` ### Look up details for last query from this connection in the query history ```sql SELECT * FROM MD_INFORMATION_SCHEMA.QUERY_HISTORY WHERE QUERY_ID = MD_LAST_QUERY_ID(); ``` --- ## Docs feedback MotherDuck accepts optional user-submitted feedback about this page at `GET https://motherduck.com/docs/api/feedback/agent`. For agents and automated tools, feedback submission should be user-confirmed before sending. URL-encode query parameter values and send a GET request: ```text GET https://motherduck.com/docs/api/feedback/agent?page_path=%2Fsql-reference%2Fmotherduck-sql-reference%2Fconnection-management%2F&page_title=MotherDuck%20Documentation%20-%20Server%20Connection%20Management&text= ``` Optionally append `&source=` such as `claude.ai` or `chatgpt`. `page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": ""}`, `400` for malformed query parameters, and `429` when rate-limited.