How to Configure CockroachDB Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a cockroachdb audit log by turning on table logging or statement logging. This records who ran a query, what table it hit, and when it ran. Most teams start by turning on logging for tables that hold private user data. When database roles have broad permissions, logs grow fast and miss real user identities. Shared database accounts make it hard to see which person ran a bad query. How the native cockroachdb audit log works CockroachDB splits logging into distinct channels so teams

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up a cockroachdb audit log by turning on table logging or statement logging. This records who ran a query, what table it hit, and when it ran. Most teams start by turning on logging for tables that hold private user data. When database roles have broad permissions, logs grow fast and miss real user identities. Shared database accounts make it hard to see which person ran a bad query.

How the native cockroachdb audit log works

CockroachDB splits logging into distinct channels so teams can group events by type. One channel tracks table reads and writes on tables you mark for auditing. Another channel tracks login events, role changes, and schema updates across the cluster. When a user runs a query on an audited table, the node writes an event. Each node stores these log files on its own local disk or sends them out. You define where these files go and how much disk space they can use. Admins turn auditing on for one table at a time using standard database statements. You must pick each sensitive table and turn on read and write tracking for it. If someone creates a new table later, you must remember to turn on logging there too. For broader visibility, teams can turn on statement logging across the whole cluster. Still, logging every query on a busy cluster uses a lot of disk and CPU. Teams must balance full visibility against node speed and storage costs.

Collecting and storing log files across nodes

CockroachDB runs as a distributed system with many nodes working at the same time. Any node in the cluster can take a client query and write an audit event. Because of this design, your cockroachdb audit log lives in pieces across every node. You cannot read the full history from a single local file on one server. Security teams must run log forwarders on every node to gather these scattered files. The forwarders read local files and send the events to a central log store. Once the events reach the central store, analysts can search them and build alerts. You also need to watch disk space on every database node. If a log collector breaks, local log files can fill up the node disk. You must set clear file rotation and size limits so logs do not stop the database.

What native logging solves and where gaps remain

Native audit logs tell you what happened inside the database after a query finishes. They help teams pass security reviews and investigate data leaks after an incident. Native role settings decide who can log in and which tables they can read. Still, native logging and roles leave key gaps open during live operations. First, logs only show the database role name, not the human behind a shared role. If five engineers share one admin account, the log cannot tell them apart. Second, an audit log is passive and cannot stop a bad query in flight. It records that someone read a million phone numbers, but it still sends the data. Third, native logs do not mask private fields like emails or card numbers in results. Sometimes, query values themselves end up in log files, which puts raw data in another place.

Audit Log Integrity + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits inline in the protocol beside the service as an open-source proxy, a sidecar for your database or API. On every production query an agent or human runs, hoop.dev decides whether to pass, mask, block, or escalate it for review.

Before a query runs, hoop.dev guardrails check the statement against your rules, an AI Analyzer you configure can score intent or hold risky calls for human approval, and hoop.dev data masking rewrites sensitive fields in responses in memory. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Does turning on table auditing slow down the database?

Yes, logging every read and write on busy tables adds disk work to each node. Teams usually turn on table auditing only for tables that store private user records.

Where does CockroachDB write audit log files by default?

Each node writes its own log files to a local folder on its server disk. You can also set the node to send log output to standard system streams.

Can native audit logs hide sensitive data in query results?

No, an audit log only writes down a record of the query that ran. To rewrite emails or card numbers in results, you need dynamic data masking in flight.

The query runs. The emails stay hidden.