4
votes

I have an application running CockroachDB on AWS and want to log all of the queries it executes. However, I can’t find anything in my cluster’s logs that seems to contain the queries. I tried grepping through them for my application’s SELECT statements but can’t find them.

Is there a way to enable query logging?

2

2 Answers

4
votes

The other answer is outdated. There are two mechanisms:

1
votes

When starting a node with cockroach start, include the --vmodule=executor=2 flag to log all SQL queries. For example:

cockroach start --background --vmodule=executor=2

You can access the logs then from the log files stored in cockroach-data/logs

If you’re curious about logging queries that run “too long”, set the env var COCKROACH_TRACE_SQL to a duration to log all queries longer than that duration.

One can also activate this logging after starting the server by accessing the URL http://[admin UI URL]/debug/vmodule/executor=2 using the same host/port as the admin UI.