4

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?

jseldess
  • 373
  • 1
  • 6

2 Answers2

4

The other answer is outdated. There are two mechanisms:

kena
  • 109
  • 4
1

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.

jseldess
  • 373
  • 1
  • 6
  • https://www.cockroachlabs.com/docs/stable/query-behavior-troubleshooting.html#per-node-execution-logs the answer is somewhat outdated. use: cockroach start --vmodule=exec_log=2 – wynemo Apr 24 '19 at 09:48
  • The previous answers are out of date. Please check my other answer with links to the CockroachDB docs on query logging. – kena May 21 '19 at 17:28