Skip to content

MCP Database Activity Tool

get_database_activity shows what QIE's own database is doing at the moment of the call: each statement running on it, how long it has run, what it waits on, and whether the longest-running ones read whole tables. It helps when the whole engine is slow and the cause may be the database. It is for administrators only, takes no arguments, and changes nothing.

It reads only sessions working in QIE's own database, never a customer database that a channel connects to. A channel waiting on one of those shows in get_channel_threads instead (see MCP Thread Tools).

What it returns

engine names the database and its version. sessions lists each statement running now, other than the tool's own, longest-running first:

Member Holds
sessionId The database's id for the session
command and state What the session is doing, as the database reports it
runningSeconds How long the statement has run
waitingOn What the statement waits on, on SQL Server only
blockedBy The session that blocks it, when one does
sql or sqlShape The statement, as described below
sqlShapeUnavailable Why a statement's shape is left out, as described below
plan For a long-running statement, how it reads each table; see Query plans
planUnavailable Why a long-running statement has no plan

A blockedBy session that is not itself in sessions is not running a statement in QIE's database now; most often it holds locks from a transaction it left open.

notes says what the tool could not read and why, such as a permission the QIE database login lacks. The rest of the answer is still returned.

Statement text

A statement can carry message content in its values, such as a patient's name in a search. The tool returns a statement's text in sql only while Return message content is on (see Message Content and the MCP), and the MCP audit log records that it did. While it is off, sqlShape returns the statement with every string and number in it replaced by ? and its comments left out, so its shape shows and no value does. When a string or quoted name in the statement never closes, the tool cannot tell where its values end, so it leaves sqlShape out and sqlShapeUnavailable says why. It does the same on MySQL and MariaDB when a value holds an apostrophe, which the database driver normally writes as \', because that reads differently depending on whether the server's sql_mode holds NO_BACKSLASH_ESCAPES, and when a -- is followed by a character the database may not read as starting a comment. textReturned says which of the two the answer holds.

Query plans

For up to 10 statements that have run for 2 seconds or more, the tool reads the plan the database is running for each, in the same call, since a statement can finish before a second call. plan lists one line per table the plan reads:

Line Means
full scan of <table> The whole table is read
full index scan of <table> using <index> The whole of one index is read
index <index> on <table> (<access>) Only the rows the index finds are read

A full scan of a large table often points to a missing index, or to a query that cannot use one.

Each engine gives the plan its own way:

Engine Plan
MySQL EXPLAIN FOR CONNECTION on the session
MariaDB SHOW EXPLAIN FOR on the session
SQL Server 2019 and later The live plan of the running request, which needs lightweight query profiling; it is on by default from SQL Server 2019
SQL Server 2016 and 2017 No plans; a note says that query plans need SQL Server 2019 or later, and the rest of the answer is returned

On SQL Server 2019 and later, a statement with no live plan gets a planUnavailable that says lightweight query profiling may be turned off for the database.

What it reads, by engine

Engine Sessions Blocking sessions
MySQL performance_schema.processlist, or information_schema.PROCESSLIST where that cannot be read, as before MySQL 8.0.22 sys.innodb_lock_waits
MariaDB information_schema.PROCESSLIST information_schema.INNODB_LOCK_WAITS with information_schema.INNODB_TRX
SQL Server sys.dm_exec_requests with sys.dm_exec_sql_text The blocking session each request reports

On SQL Server, the QIE database login sees other sessions' requests only with VIEW SERVER STATE, or, on SQL Server 2022 and later, VIEW SERVER PERFORMANCE STATE. The tool checks for them, and without either a note says that other sessions are not visible.

On MySQL and MariaDB, when the login cannot read the blocking sessions, a note gives the database's own message and blockedBy is left out; the sessions are still listed. When the running statements themselves cannot be read, on any engine, sessions is empty and a note gives the database's message. When a plan cannot be read, planUnavailable gives the database's message.

Through the Hub

The Hub runs get_database_activity at one site per call. It takes site and never tag (see Site Tools on a Hub).