1. CouchDB
  2. COUCHDB-1132

Track used space of database and view index files


    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Component/s: Database Core
    • Labels:


      Currently users have no reliable way to know if a database or view index compaction is needed.

      Both me, Adam and Robert Dionne have been working on a feature to compute and expose the current data size (in bytes) of databases and view indexes. These computations are exposed as a single field in the database info and view index info URIs.

      Comparing this new value with the disk_size value (the total space in bytes used by the database or view index file) would allow users to decide whether or not it's worth to trigger a compaction.

      Adam and Robert's work can be found at:

      Mine can be found at:

      After chatting with Adam on IRC, the main difference seems to be that they're work accounts only for user data (document bodies + attachments), while mine also accounts for the btree values (including all meta information, keys, rev trees, etc) and the data added by couch_file (4 bytes length prefix, md5s, block boundary markers).

      An example:

      $ curl http://localhost:5984/btree_db/_design/test/_info

      $ curl http://localhost:5984/btree_db


      This example was executed just after compacting the test database and view index. The new filed "data_size" has a value very close to the final file size.

      The only thing that my branch doesn't include in the data_size computation, for databases, are the size of the last header, the size of the _security object and purged revs list - in practice these are very small and insignificant that adding extra code to account them doesn't seem worth it.

      I'm sure we can merge the best from both branches.

      Adam, Robert, thoughts?



          • Assignee:
            Filipe Manana
          • Votes:
            1 Vote for this issue
            1 Start watching this issue


            • Created: