Migrate Metadata to System Collection
Opt in to migrating Sync Gateway internal metadata from the default collection to the system collection in Sync Gateway 4.1.
Related Application Deployment topics: Release Notes | Compatibility Matrix
Overview
Sync Gateway stores internal metadata, including user documents, role documents, session documents, replication state, and DCP checkpoints, in the default collection (_default._default).
This couples Sync Gateway’s internal bookkeeping with customer document data in the same collection.
Sync Gateway 4.1 introduces an opt-in migration that relocates this metadata to the system collection (_system._mobile).
Migrating provides the following benefits:
-
Metadata is isolated from user application data.
-
Sync Gateway metadata no longer appears alongside user-modifiable documents in the Capella UI.
-
Eventing functions and SQL++ queries running against the default collection no longer process Sync Gateway internal documents.
|
This migration is opt-in and is never applied automatically at upgrade. Your existing deployment is unaffected until you enable the feature. This feature is only supported when all nodes in the cluster have been upgraded to Sync Gateway 4.1 and the cluster compatibility version is running at 4.1. If you are using Cluster Compatibility Version to stage your upgrade, ensure the freeze has been cleared and the compatibility version has advanced to 4.1 before enabling this migration. The opt-in configuration flags are one-way.
Once enabled, the migration cannot be reversed.
There is no supported path to move metadata back to |
|
The migration runs in the background and does not impact your workloads.
Databases remain fully available for reads and writes throughout the migration.
New databases created after opting in have their Sync Gateway metadata stored in |
Prerequisites
-
Sync Gateway 4.1 or later on all nodes in the cluster.
-
Couchbase Server version that supports the
_system._mobilecollection. -
The
_system._mobilecollection must be available on the target bucket. Sync Gateway rejects the opt-in configuration if this collection is unavailable.
How the Migration Works
The migration uses a two-level opt-in: one at the cluster level and one per database.
Cluster-level flag
The bootstrap configuration flag use_system_metadata_collection acts as the cluster-wide feature gate.
Enabling it allows individual databases to opt in and enables the dual-collection read behaviour at bootstrap.
By itself, enabling the cluster flag does not migrate any data.
Per-database opt-in
The database configuration field use_system_metadata_collection opts an individual database into the migration.
You can opt in a database even if the cluster flag is not set.
Once you apply the opt-in configuration to a database, Sync Gateway waits until the configuration is confirmed applied on all nodes in the cluster, then starts the migration automatically. You do not need to call any API to trigger the migration.
What migrates
The migration relocates the following internal Sync Gateway metadata from _default._default to _system._mobile:
-
User, role, and email index documents
-
Session documents (TTL is preserved)
-
Replication state and status documents
-
DCP checkpoint documents
-
Background process heartbeat and status documents
-
Database state documents
-
Sync Gateway configuration documents
The following are not migrated and remain in their existing locations:
-
Collection-scoped document data (
_sync:rev:*,_sync:att*:*) -
Metadata belonging to other databases on the same bucket (sibling databases)
Bucket-level bootstrap documents (_sync:registry, database config docs) migrate only after every database on the bucket has completed its migration.
Database availability during migration
Databases remain fully available for reads and writes throughout the migration.
Sync Gateway uses a dual-collection read strategy during migration: reads go to _system._mobile first and fall back to _default._default only for keys not yet migrated.
Writes always go to _system._mobile from the moment opt-in is applied.
Once the migration is complete, the fallback read path is disabled.
Reads consult only _system._mobile.
New databases with no existing metadata skip the migration entirely and are marked complete immediately.
Enable the Migration
Step 1: Enable the cluster-level flag
Add the following to your Sync Gateway bootstrap configuration:
{
"bootstrap": {
"use_system_metadata_collection": true
}
}
This is a one-way change.
Once set to true, the flag cannot be set back to false.
Step 2: Opt in each database
Add the following to the database configuration for each database you want to migrate:
{
"use_system_metadata_collection": true
}
This is also a one-way change per database.
After you apply the database configuration, Sync Gateway starts the migration automatically once the configuration is confirmed on all nodes. No further action is required to start the migration.
Monitor Migration Progress
Use the GET /{db}/_metadata_migration endpoint on the Admin REST API to check the status of a migration.
This endpoint is available on the Admin port (:4985) only.
|
Example request:
GET /{db}/_metadata_migration
Example response:
{
"status": "running",
"migration_id": "a1b2c3d4-...",
"docs_processed": 45200,
"docs_attempted": 45200,
"docs_failed": 0,
"docs_out_of_scope": 12,
"passes": 2
}
| Field | Description |
|---|---|
|
Current migration status: |
|
Unique identifier for this migration run. |
|
Number of metadata documents successfully moved to |
|
Total number of documents the migrator has attempted to process. |
|
Number of documents that encountered an error during migration.
A non-zero value means some keys may not have migrated.
Check |
|
Number of keys observed in the fallback collection that belong to other databases or to bucket-level bootstrap documents. These are left in place. |
|
Number of scan passes the migrator has completed. The migration is complete when a pass finds no remaining in-scope keys. |
Manual Migration Controls
The migration starts automatically after opt-in.
Use the POST /{db}/_metadata_migration endpoint to intervene manually if needed.
Required RBAC role: Sync Gateway Architect
| Query parameter | Description |
|---|---|
|
|
|
Set to |
Retry after an error:
POST /{db}/_metadata_migration?action=start
Stop a running migration:
POST /{db}/_metadata_migration?action=stop
|
A |
For the full API reference, see GET /{db}/_metadata_migration.
Prometheus Statistics
Sync Gateway 4.1 adds seven Prometheus metrics under the sgw_metadata_migration subsystem, each labelled per database.
| Metric | Type | Description |
|---|---|---|
|
Counter |
Total fallback keys observed across all scan passes. |
|
Counter |
Documents successfully moved or removed from the fallback collection. |
|
Gauge |
Keys in the fallback collection belonging to other databases or bucket-level bootstrap documents on the most recent pass. This is a snapshot of the last pass, not a cumulative total. |
|
Gauge |
Unrecognized keys in the fallback collection on the most recent pass. A persistently non-zero value indicates the migration will not complete without intervention. Contact Couchbase Support if this value remains non-zero. |
|
Counter |
Per-document errors during move or delete operations. |
|
Counter |
Number of times this node applied the sequence counter handoff during migration.
Typically |
|
Counter |
Number of scan passes executed. |
For general Prometheus monitoring, see Prometheus Monitoring.
Troubleshooting
Migration stops without completing
If status shows error or docs_unknown_prefix is persistently non-zero, the migration encountered keys it could not process.
Use POST /{db}/_metadata_migration?action=start to retry.
If the issue persists, contact Couchbase Support with the output of GET /{db}/_metadata_migration and your SGCollect bundle.