Cockorach DB log slow queries

In cockroach 2.0 is there a way to log slow queries? For example I want to log queries which are taking more than 2 seconds to finish.

Hi @tuk! I think the sql.trace.log_statement_execute cluster setting is what you’re looking for. You can see how to use them on https://www.cockroachlabs.com/docs/stable/cluster-settings.html

We’re also planning on adding a bunch more tooling and introspection for this in 2.1: https://github.com/cockroachdb/cockroach/issues/24109

1 Like

Thanks @dan for replying. But this will log all statements that are getting executed. I was looking for something which will only log queries whose execution time is more than x seconds.

It looks like this is going to be added in 2.1

Oh, my apologies. I meant sql.trace.txn.enable_threshold, which takes a duration.

1 Like

it looks like you could also use system.crdb_internal.node_statement_statistics to find statistics about the various queries.

@tuk You might also want to check out https://www.cockroachlabs.com/docs/v1.1/manage-long-running-queries.html