Database is currently being compacted error in database writer component
0 reputation · 17 Jun 2021, 13:20 UTC
0 reputation · 17 Jun 2021, 13:20 UTC
Goal: Determine whether the "database is currently being compacted" error observed in the database writer component leads to measurable write latency increases under concurrent load.
Constraints: The error may appear only when compaction contends for disk I/O and file descriptors, and its impact varies with automatic versus manual compaction scheduling and across CouchDB 3.x versions where stats names and defaults differ.
Uncertainty: It is unclear what latency threshold constitutes an unacceptable spike, how to isolate compaction‑induced queuing from other I/O bottlenecks, and whether automatic compaction should be throttled or disabled during sustained write workloads.
Questions: What latency increase signals problematic compaction contention? How can administrators distinguish compaction‑related queuing from general disk saturation? Should automatic compaction be adjusted based on real‑time I/O headroom?
34775 reputation · 18 Jun 2021, 00:48 UTC
The "database is currently being compacted" error in the CouchDB database writer is a busy/contention signal, not evidence of database corruption. Compaction rewrites the database file in the background and can contend for disk I/O, page cache, and file descriptors, which raises fsync/commit latency and p99 write latency for some requests. There is no universal latency threshold that applies to every deployment. Treat the contention as problematic when sustained p95 or p99 write latency rises above your service SLO, or when write timeouts and request queue buildup coincide with compaction periods.
| Item | Status | Notes |
|---|---|---|
| Writer error means all writes are blocked for the whole compaction | Not confirmed | CouchDB generally keeps databases available by writing to a new file and swapping at the end; the error indicates contention, not a total write stop. |
| Compaction can increase write latency and queue depth | Established behavior | Impact varies by disk, write rate, scheduling, and CouchDB 3.x minor version. |
| Automatic compaction should be disabled permanently during writes | Not recommended | Indefinite disabling risks unbounded database and view file growth. |
iostat -x or an equivalent during idle and compaction periods. Compare device percent util, await, queue length, and file-descriptor usage. If these rise only during compaction and return to baseline afterward, the bottleneck is compaction-related rather than general disk saturation.For sustained write workloads, do not disable compaction permanently. Schedule compaction in low-write windows, limit concurrent compactions, and use OS I/O priority where available. Re-enable automatic compaction afterward to prevent unbounded file growth. Adjust based on real-time I/O headroom only after correlating latency spikes with compaction windows in your own environment.
Missing diagnostic detail: What is your exact CouchDB 3.x minor version? Stat names, compaction defaults, and auto-compaction behavior differ across 3.x releases, so this determines which metrics to inspect before changing scheduling.
Verify these steps in staging before applying to production, because compaction can temporarily add I/O during active writes.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.