Skip to main content

Slow query log

CamusDB can record statements that take longer than a threshold and expose them as a SQL result set:

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

The log is off by default and bounded in memory. Use it as a diagnostic while a node is slow, not as an audit log.

Enable it​

Configure the node:

slow_query_log_enabled: true
slow_query_log_threshold_ms: 1000
slow_query_log_max_entries: 200
slow_query_log_max_sql_length: 4096
SettingDefaultMeaning
slow_query_log_enabledfalseMaster switch.
slow_query_log_threshold_ms1000Record statements at or above this duration. 0 records every statement.
slow_query_log_max_entries200Entries kept before the oldest is overwritten.
slow_query_log_max_sql_length4096Characters of SQL text stored per entry.

SHOW VARIABLES LIKE 'slow_query%' shows the effective values on the node you are inspecting.

What it records​

Each entry includes the facts that usually explain why a statement was slow:

  • full_scan: the plan read a whole relation instead of seeking through an index.
  • spilled: a sort, grouping, distinct, hash join, or row buffer wrote to disk.
  • rows_read and rows_returned: reading far more rows than returned usually means the predicate needs a better index.
  • outcome: completed, abandoned, or failed.
  • error_code: the CamusDB error code when the statement failed.

Rows come back newest first.

ColumnTypeMeaning
seqINT64Recording order on this node. It keeps increasing after the ring wraps.
started_atSTRINGStatement start time in UTC.
duration_msFLOAT64Wall-clock duration.
databaseSTRINGDatabase used by the statement.
userSTRINGAuthenticated user, or NULL when auth is disabled.
kindSTRINGStatement kind, such as select, insert, or create_table.
rows_returnedINT64Rows returned, or rows affected for a mutation.
rows_readINT64Rows fetched from storage before filtering.
full_scanBOOLWhether any part of the statement read a whole relation.
spilledBOOLWhether a blocking operator spilled to disk.
outcomeSTRINGcompleted, abandoned, or failed.
error_codeSTRINGError code for failed statements.
truncatedBOOLWhether the stored SQL was shortened.
sqlSTRINGStatement text, with password literals redacted, up to slow_query_log_max_sql_length.

Read the result​

SHOW SLOW QUERIES LIKE '%orders%';
seqduration_mskindrows_returnedrows_readfull_scanspilledoutcomesql
4124180.2select122400000truefalsecompletedSELECT * FROM orders WHERE region = 'emea'
4072210.7select500500falsetruecompletedSELECT * FROM orders ORDER BY total DESC

The first query read many rows to return a few, so it probably needs an index on region. The second query read only what it returned but spilled, so the issue is memory or an unbounded sort. Add a LIMIT, raise the spill threshold, or inspect the plan with EXPLAIN.

SHOW SLOW QUERIES is never recorded in the slow query log. A dashboard or SQL client that polls the log therefore does not erase the history it is reading.

Password literals in CREATE USER ... IDENTIFIED BY ... and ALTER USER ... IDENTIFIED BY ... REPLACE ... are replaced with '***' before an entry is stored. A password passed as a bound parameter never appears in the statement text in the first place.

Dashboard​

The operator dashboard has a Slow queries panel over the same data. It shows the newest entries, highlights full scans and spills, and refreshes independently from the rest of the page.

Permissions and limits​

SHOW SLOW QUERIES requires a superuser while authentication is enabled. The rows include literal SQL text from statements run by other users, so table-level grants cannot safely narrow the output.

Important limits:

  • Entries live in memory only and disappear on restart.
  • The result is node-local. Inspect each node separately in a cluster.
  • The ring is bounded. If seq advanced by more than the ring capacity between reads, entries were overwritten.
  • It is not an audit log. Statements below the threshold are never recorded.