You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何删除数据库后_dbs.couch文件仍保留信息且大小未变?

Why doesn't /var/lib/couchdb/_dbs.couch shrink after deleting databases in Fauxton 2.1.1?

Great question! Let's break down why this behavior happens with CouchDB and its system database file:

1. CouchDB uses an append-only storage model

At its core, CouchDB relies on an append-only storage pattern for all its databases—including system databases like _dbs that track your instance's database metadata. When you delete a database, CouchDB doesn't erase the existing metadata entries from _dbs.couch directly. Instead, it appends a special "tombstone" marker to the file that flags those entries as deleted.

This design is intentional: it guarantees data consistency and simplifies crash recovery. If the system crashes mid-deletion, there's no risk of partial data corruption—CouchDB can just scan the file on restart and use the tombstone markers to identify which entries are no longer valid.

2. Disk space isn't reclaimed until compaction

Since deletions only add tombstone markers rather than removing data, the _dbs.couch file's size won't decrease automatically after deleting databases. Think of it like editing a printed book: you can cross out a section, but the page stays in the book, so the total thickness doesn't change.

To actually reclaim that unused disk space, you need to run a database compaction on the _dbs system database. Compaction works by rewriting the entire database file, only including valid (non-deleted) entries, and discarding all tombstoned old data.

3. Why you can still find the deleted database names

The old metadata entries for your deleted test databases are still physically present in the _dbs.couch file—they're just marked as invalid with tombstones. Until compaction runs, those old strings (like your database names) remain in the file's raw bytes, which is why you can still search for them.

How to trigger compaction

If you want to shrink the file and remove those leftover entries, you can trigger compaction either through Fauxton or via the API:

  • Fauxton: Navigate to the _dbs system database, go to the "Settings" tab, and click the "Compact Database" button.
  • API: Use a curl command (adjust credentials/host as needed):
    curl -X POST http://localhost:5984/_dbs/_compact
    

Just note that compaction can be resource-intensive, so it's best to run it during low-traffic periods for your CouchDB instance.

内容的提问来源于stack exchange,提问作者jAndy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:54:45