Skip to main content

Query activity

CamusDB can show the statements and client connections that are active right now. It can also cancel a running read query.

These statements are server-level. They do not need a selected database and they do not open a transaction:

SHOW QUERIES;
SHOW QUERIES LIKE '%FROM orders%';
SHOW CLUSTER QUERIES;

SHOW CONNECTIONS;
SHOW CLUSTER CONNECTIONS;

CANCEL QUERY 'b71a90e314-45';

SHOW QUERIES is useful when a query is slow, a client is reading rows slowly, or you need the id of a statement to cancel. SHOW CONNECTIONS shows the client-facing connections held by the node. The cluster forms ask every member and merge the rows.

Running queries​

SHOW QUERIES returns one row for each statement that is running on the node, oldest first. The SHOW QUERIES statement itself appears in the output.

Important columns:

ColumnMeaning
query_idThe id accepted by CANCEL QUERY. It is unique across the cluster.
nodeThe internal cluster address of the node running the statement.
connection_idThe connection that carried the statement, when there is one.
client_addressThe client's IP address.
transporthttp, grpc, grpc-stream, or embedded.
user_nameThe authenticated user, or NULL when authentication is off.
database_nameThe context database of the statement.
transaction_idThe explicit transaction handle, when the statement runs inside one.
kindThe parsed statement kind, such as select, update, or create_table.
phaseplanning before the first row is read, then executing.
started_atThe UTC start time.
elapsed_msHow long the statement has run.
rows_returnedRows the client has read so far.
cancellableWhether CANCEL QUERY can stop it now.
cancel_requestedWhether a cancel has already been requested.
sqlThe statement text, with credential literals masked and length-limited.
errorNULL for normal rows. Cluster forms use it when a node could not answer.

A row-returning statement stays listed until its cursor ends. If a client reads slowly, the query remains visible and rows_returned continues to grow as the client consumes rows.

Client connections​

SHOW CONNECTIONS returns one row for each client-facing TCP or QUIC connection accepted by the node. It tracks HTTP, HTTPS, and the gRPC client port. QUIC connections exist only when http3_enabled is on. It does not track the internal port that nodes use to talk to each other.

Important columns:

ColumnMeaning
connection_idThe id referenced by SHOW QUERIES.connection_id.
nodeThe node that holds the connection.
client_addressThe client's IP address.
protocolHTTP/1.1, HTTP/2, or HTTP/3. gRPC uses HTTP/2. HTTP/3 appears only on the HTTPS port when http3_enabled is on.
kindclient, or peer for another node calling an internal endpoint.
user_nameThe user of the last statement on the connection.
opened_atThe UTC time when the connection was accepted.
age_msHow long the connection has been open.
idle_msTime since the last request; 0 while a statement runs.
requestsRequests started on the connection.
active_queriesStatements currently running on the connection.
open_streamsOpen BatchExecute streams.
errorNULL for normal rows. Cluster forms use it when a node could not answer.

HTTP/2 can carry many concurrent calls on one connection, so one gRPC channel usually appears as one connection row.

Cancel a query​

CANCEL QUERY '<query_id>' asks CamusDB to stop one running query. You can send the cancel to any node; the id contains enough information for CamusDB to forward the request to the node that owns it.

Only read statements are cancellable. A SELECT, SHOW, or EXPLAIN ANALYZE stops at its next row boundary. A write or schema change runs to commit or rollback once it has started mutating state, so it shows cancellable = false.

The client of the cancelled statement receives CADB0554. Rows it already read before the cancel are real rows.

Cancel-related errors:

CodeMeaning
CADB0551No visible running query has that id. It may have ended, the id may be wrong, or it may belong to another user.
CADB0552The statement cannot be cancelled now, usually because it is a write, a schema change, or still parsing.
CADB0553The node that may own the query did not answer before the timeout. The query may still be running.
CADB0554The cancelled statement reports this code to its own client.

A cancel takes effect when the statement next checks for cancellation. If the server has already written rows into the network buffer, a slow client can still receive those buffered rows before it receives the cancellation error.

Visibility and permissions​

When authentication is off, every caller sees every row and can cancel any cancellable query.

When authentication is on:

  • A superuser sees every row and can cancel any cancellable query.
  • A regular user sees only their own statements and connections.
  • A regular user can cancel only their own queries.

A cancel attempt against another user's query returns the same error as an unknown query id, so query ids do not reveal other users' activity.

Cluster forms​

SHOW CLUSTER QUERIES and SHOW CLUSTER CONNECTIONS ask every cluster member for its local rows. A node that does not answer before cluster_activity_peer_timeout_ms contributes one row with node and error set, while the other columns are NULL.

This keeps the result useful during an outage: one unreachable node does not make the whole activity query fail.

One cluster request contacts all members. At most cluster_activity_max_concurrent_fan_outs requests run simultaneously on a node (default 8); excess requests fail with CADB0558 and HTTP 503. This protects peer connections and thread-pool work from excessive dashboard polling.

On a standalone node, the cluster forms return the same rows as the local forms.

Runtime settings​

These runtime cluster settings control the feature:

SettingDefaultPurpose
query_activity_enabledtrueLists running statements and allows CANCEL QUERY.
query_activity_max_sql_length1024Maximum statement-text characters shown in SHOW QUERIES.
cluster_activity_peer_timeout_ms2000Peer wait for cluster forms and forwarded cancels.
cluster_activity_max_concurrent_fan_outs8Concurrent cluster activity requests admitted per node. 0 or below disables the cap.

Change them with Runtime Cluster Settings:

SET CLUSTER SETTING query_activity_max_sql_length = 4096;
SET CLUSTER SETTING cluster_activity_peer_timeout_ms = 5000;

Turning query_activity_enabled off stops new statements from being listed and prevents CANCEL QUERY from finding them. Existing listed statements leave the activity list when they finish. SHOW CONNECTIONS still works.

Limits​

  • Typed row APIs, such as /query, /insert, /update, /delete, and the gRPC CamusRows service, are not listed because they do not send SQL text.
  • The scans that a distributed query runs on other nodes are not listed on those nodes. The statement on the coordinating node is listed.
  • An explicit transaction that is idle between statements does not appear in SHOW QUERIES; its connection appears in SHOW CONNECTIONS.
  • There is no KILL CONNECTION statement yet.