cockroachdb / cockroachdb/cockroach
sql: equivalent of slow query log for transactions
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Slow transactions (with long idle times between statements) can be a real problem for an OLTP database, especially if they're holding locks. We have a few ways to investigate slow transactions, but they all take some work from the investigator:
- in v25.4 we added [transaction diagnostics](https://www.cockroachlabs.com/docs/v26.2/transaction-diagnostics.html) but this requires knowing which transaction is slow
- the application could send `SET tracing = on;` before the transaction and `SHOW TRACE FOR SESSION;` after the transaction, but this also requires knowing which transaction is slow and modifying the application
- there's [probabilistic transaction tracing](https://www.cockroachlabs.com/docs/v26.2/query-behavior-troubleshooting.html#log-traces-for-transactions) using cluster settings `sql.trace.txn.sample_rate` and `sql.trace.txn.enable_threshold` which dumps traces to SQL_EXEC logs, but this is an entire trace for every statement, which is probably overkill
- we can set session variables `idle_in_transaction_session_timeout` and `transaction_timeout`, but these will kill transactions that surpass the timeouts
During an investigation, @cvansicklecrdb suggested a simpler idea: it would be nice if we had an equivalent to the slow query log (i.e. `sql.log.slow_query.latency_threshold`) but for entire transactions. It would only have to log the statements and metadata, so it wouldn't need full tracing.
Jira issue: CRDB-65021
Contributor guide
Research direction
Start by reading the existing slow query logging behavior around `sql.log.slow_query.latency_threshold`, then compare it with the transaction diagnostics and probabilistic transaction tracing described in the issue. Define what transaction metadata and statements should be logged when a transaction exceeds a latency threshold, while preserving the stated goal of avoiding full tracing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100