POST /{db}/_compact
This request compacts the database. Compaction compresses the disk database file by performing the following operations:
Writes a new, optimized version of the database file. Unused sections are removed from the new version during write. Because a new file is temporarily created for this purpose, up to twice the current storage space of the specified database is required for the compaction routine to complete.
Removes old revisions of documents from the database, up to the per-database limit specified by the
_revs_limitdatabase parameter.
The compaction process runs as a background process.
Request
Request headers
This request does not have any required headers.
Query parameters
This request does not use query parameters.
Message body
This request does not use a message body.
Response
Status codes
- 202 Accepted – Compaction request has been accepted
- 400 Bad Request – Invalid database name
- 401 Unauthorized – Administrator privileges required
- 415 Unsupported Media Type – Bad Content-Type value
Response headers
This response uses only standard HTTP headers.
Message body
The response contains a JSON document that contains some of the following objects:
| Name | Type | Description |
|---|---|---|
error | String | Error message |
ok | Boolean | Indicates whether the operation was successful |
status | Integer | HTTP error code |
Example
The following example requests the database named cookbook to
be compacted.
Request
POST /cookbook/_compact HTTP/1.1
Host: localhost:59840
Response
HTTP/1.1 202 Accepted
Accept-Ranges: bytes
Content-Length: 18
Content-Type: application/json
Date: Mon, 16 Dec 2013 17:22:34 GMT
Server: CouchbaseLite 1.486
{
"ok" : true
}