Cockroach Labs recommends against using the
--background flag when starting a cluster. In production, operators usually use a process manager like systemd to start and manage the cockroach process on each node. Refer to . When testing locally, starting nodes in the foreground is recommended so you can monitor the runtime closely.If you do use --background, you should also set --pid-file. To stop or restart a cluster, send SIGTERM or SIGHUP signal to the process ID in the PID file.start command to wait until the node has fully initialized and is able to start serving queries. In addition, to keep your data consistent, CockroachDB waits until a majority of nodes are running. This means that if only one node of a three-node cluster is running, that one node will not be operational.
As a result, starting nodes with the --background flag will cause cockroach start to hang until a majority of nodes are fully initialized.
To restart your cluster, you should either:
- Use multiple terminal windows to start multiple nodes in the foreground.
- Start each node in the background using your shell’s functionality (e.g.,
cockroach start &) instead of using the--backgroundflag.
8 KiB * 24 hours * 3600 seconds/hour * number of days
For the first 10 days of your cluster’s life, you can expect storage per node to increase by about the following amount:
8 * 24 * 3600 * 10 = 6912000
or about 6 GiB. With on-disk compression, the actual disk usage is likely to be about 4 GiB.
However, depending on your usage of time-series charts in the , you may prefer to reduce the amount of disk used by time-series data. To reduce the amount of time-series data stored, refer to Can I reduce the storage of time-series data?
There are several reasons why disk usage may not decrease right after deleting data:
For instructions on how to free up disk space as quickly as possible after dropping a table, see
The data could be preserved for MVCC history
CockroachDB implements , which means that it maintains a history of all mutations to a row. This history is used for a wide range of functionality: , historical queries, , , , and so on. The requirement to preserve history means that CockroachDB “soft deletes” data: The data is marked as deleted by a tombstone record so that CockroachDB will no longer surface the deleted rows to queries, but the old data is still present on disk. The length of history preserved by MVCC is determined by two things: the of the zone that contains the data, and whether any exist. You can check the range’s statistics to observe thekey_bytes, value_bytes, and live_bytes. The live_bytes metric reflects data that’s not garbage. The value of (key_bytes + value_bytes) - live_bytes will tell you how much MVCC garbage is resident within a range.
This information can be accessed in the following ways:
- Using the SQL statement, which lists the above values under the names
live_bytes,key_bytes, andval_bytes. - In the DB Console, under , click the Range Status link, which takes you to a page where the values are displayed in a tabular format like the following:
MVCC Live Bytes/Count | 2.5 KiB / 62 count.
The data could be in the process of being compacted
When MVCC garbage is deleted by garbage collection, the data is still not yet physically removed from the filesystem by the . Removing data from the filesystem requires rewriting the files containing the data using a process also known as , which can be expensive. The storage engine has heuristics to compact data and remove deleted rows when enough garbage has accumulated to warrant a compaction. It strives to always restrict the overhead of obsolete data (called the space amplification) to at most 10%. If a lot of data was just deleted, it may take the storage engine some time to compact the files and restore this property. For instructions on how to free up disk space as quickly as possible after dropping a table, see If you’ve noticed that your disk space is not freeing up quickly enough after dropping a table, you can take the following steps to free up disk space more quickly the next time you drop a table. This example assumes a tablet exists.
The procedure shown here only works if you get the range IDs from the table before running . If you are in an emergency situation due to running out of disk, see What happens when a node runs out of disk space?
-
Lower the to 10 minutes.
-
Find the IDs of the storing the table data using :
- Drop the table using :
- Visit the and click the link Run a range through an internal queue to visit the Manually enqueue range in a replica queue page. On this page, select mvccGC from the Queue dropdown and enter each range ID from the previous step. Check the SkipShouldQueue checkbox to speed up the MVCC process.
- Monitor GC progress in the DB Console by watching the and the overall disk space used as shown on the .
internal-delete-old-sql-stats process cleans up query execution statistics collected on system tables, including system.statement_statistics and system.transaction_statistics. These system tables have a default row limit of 1 million, set by the sql.stats.persisted_rows.max . When this limit is exceeded, there is an hourly cleanup job that deletes all of the data that surpasses the row limit, starting with the oldest data first. For more information about the cleanup job, use the following query:
internal-delete-old-sql-stats process is not expected to impact cluster performance. There are a few cases where there has been a spike in CPU due to an incredibly large amount of data being processed; however, those cases were resolved through and general improvements over time.
Yes, you can reduce the interval for time-series storage.
After reducing time-series storage, it can take up to 24 hours for time-series data to be deleted and for the change to be reflected in DB Console metrics.
Reduce the interval for time-series storage
To reduce the interval for storage of time-series data:- For data stored at 10-second resolution, reduce the
timeseries.storage.resolution_10s.ttlcluster setting to an value less than240h0m0s(10 days).
- For data stored at 30-minute resolution, reduce the
timeseries.storage.resolution_30m.ttlcluster setting to an value less than2160h0m0s(90 days).
Disable time-series storage
Disabling time-series storage is recommended only if you exclusively use a third-party tool such as for time-series monitoring. Prometheus and other such tools do not rely on CockroachDB-stored time-series data; instead, they ingest metrics exported by CockroachDB from memory and then store the data themselves. When storage of time-series metrics is disabled, the DB Console Metrics dashboards in the DB Console are still available, but their visualizations are blank. This is because the dashboards rely on data that is no longer available. To disable the storage of time-series data, run the following command:timeseries.storage.resolution_10s.ttl and timeseries.storage.resolution_30m.ttl cluster settings:
In addition to using ballast files, it is important to actively .
server.clock.forward_jump_check_enabled , you can be alerted when the CockroachDB clock jumps forward, indicating it had been running with a stale clock. To protect against this on vMotion, however, use the flag to specify a PTP hardware clock for CockroachDB to use when querying the current time. When doing so, you should not enable server.clock.forward_jump_check_enabled because forward jumps will be expected and harmless. For more information on how --clock-device interacts with vMotion, see this blog post.
Considerations
When setting up clock synchronization:- All nodes in the cluster must be synced to the same time source, or to different sources that implement leap second smearing in the same way. For example, Google and Amazon have time sources that are compatible with each other (they implement leap second smearing in the same way), but are incompatible with the default NTP pool (which does not implement leap second smearing).
- For nodes running in AWS, we recommend Amazon Time Sync Service. For nodes running in GCP, we recommend Google’s internal NTP service. For nodes running elsewhere, we recommend Google Public NTP. Note that the Google and Amazon time services can be mixed with each other, but they cannot be mixed with other time services (unless you have verified leap second behavior). Either all of your nodes should use the Google and Amazon services, or none of them should.
- If you do not want to use the Google or Amazon time sources, you can use
chronyand enable client-side leap smearing, unless the time source you’re using already does server-side smearing. In most cases, we recommend the Google Public NTP time source because it handles smearing the leap second. If you use a different NTP time source that doesn’t smear the leap second, you must configure client-side smearing manually and do so in the same way on each machine. - Do not run more than one clock sync service on VMs where
cockroachis running. - For new clusters using the , Cockroach Labs recommends lowering the setting to
250ms. This setting is especially helpful for lowering the write latency of . Nodes can run with different values for--max-offset, but only for the purpose of updating the setting across the cluster using a rolling upgrade.
Tutorials
For guidance on synchronizing clocks, see the tutorial for your deployment environment:| Environment | Featured Approach |
|---|---|
| Use NTP with Google’s external NTP service. | |
| Use the Amazon Time Sync Service. | |
| Disable Hyper-V time synchronization and use NTP with Google’s external NTP service. | |
| Use NTP with Google’s external NTP service. | |
| Use NTP with Google’s internal NTP service. |
http://<host:<http-port/_status/vars in the format used by the popular Prometheus timeseries database. Two of these metrics export how close each node’s clock is to the clock of all other nodes:
| Metric | Definition |
|---|---|
clock\_offset\_meannanos | The mean difference between the node’s clock and other nodes’ clocks in nanoseconds |
clock\_offset\_stddevnanos | The standard deviation of the difference between the node’s clock and other nodes’ clocks in nanoseconds |
clock_offset_meannanos metric and alert if it’s approaching the 80% threshold of your cluster’s configured max offset.
You can also see these metrics in on the DB Console.
Perform a to temporarily stop the cockroach process on the node. When maintenance is complete and you restart the cockroach process, the node will rejoin the cluster.

