I have a Couchbase and Sync Gateway instance and my clients are working on mobile devices with the CouchbaseLite. They upload a lot of attachments (blobs) over the Sync Gateway. Theses blobs are stored as binary documents in the Couchbase. (Docs: cbl-blobs)
The Problem is that I am not sure if these binary documents are automatically purged when the releated document is deleted/purged from the Couchbase.
So what do I have to do:
Nothing. They are automatically purged when the related document is deleted/purged
Run a Compaction on the bucket. The Compaction will remove all unused binary documents
Always manually remove all attachments from a document via the Sync-Gw API before removing the document
Nothing. They are automatically purged after the tombstone interval of the related document
I hope someone can help me and thank you in advance.
I can answer that on the local side, unless you delete the database, the answer is 2. Someone else will have to answer if you are asking about what to do on the server side (which it seems like you are)
Yes I am asking on the Server side. The used RAM of the Bucket increases every month by 1 GB and that worries me.
On the local side I already run a compaction maintainance after a CouchbaseLite instance is opened. (Summary: Compact the database file and delete unused attachments.)
Ok I pinged someone else, but it was a bit confusing that you said “stored as binary in the Couchbase” (meaning Server) and then linking to Couchbase Lite docs.
Since there was no update on this topic.
I wrote a query to check if there any unrelated attachments on the Server.
SELECT
META(b).id AS binaryDocId
FROM `_default` AS b
UNNEST (SELECT RAW ARRAY_FLATTEN(
ARRAY_AGG(ARRAY v.digest FOR v IN OBJECT_VALUES(META(d).xattrs._sync.attachments) END),
1)
FROM `_default` AS d
WHERE META(d).xattrs._sync.attachments IS NOT MISSING) att
WHERE META(b).type = 'base64'
AND META(b).id LIKE '_sync:att2%'
AND SUBSTR(META(b).id, -33) NOT IN att;
From my point of view it seems like that the Sync Gateway automatically removes all binary documents (attachments) if the parent document is deleted.