Take Database Offline/Online

      +

      How to take a Sync Gateway database offline and bring back online.

      Sync Gateway enables a database to be taken offline and brought back online without stopping the Sync Gateway instance and without affecting other databases served by it.

      The change of status (online or offline) of a database occurs only in the specific Sync Gateway instance addressed. It is not reflected by other Sync Gateway instances using that database. If you want to make changes in multiple Sync Gateway instances, you need to coordinate individual change operations in each instance.

      When To Take a Database Offline/Online

      You may need to take a database offline or bring it back online in the following scenarios:

      • You need to take a single database offline without affecting other databases.

      • You need to change the configuration properties for a database without restarting Sync Gateway.

      • You need to resynchronize a database while it is offline.

      • You are responding to a lost DCP or TAP feed. Sync Gateway does this automatically.

      • You created a database in an offline state, so that the start of service delivery for the database can be postponed or coordinated across Sync Gateway instances.

      • You need to run a Couchbase Server upgrade.

      State Diagram

      The state diagram in Figure 1 represents the states for Sync Gateway and the connection between it and a Couchbase Server database.

      state diagram offline 12
      Figure 1. State Change Diagram

      The state diagram illustrates two types of operations:

      • Instance-level operations: Starting or stopping a Sync Gateway instance affects the connections to all of the databases that the instance serves.

      • Database-level operations: You can perform operations on specific databases independently. For example, two databases could be online, while a third database could be taken offline, resynchronized, and then brought back online.

      Sync Gateway Configuration Mode Considerations

      The workflow for taking databases offline/online differs depending on your configuration mode:

      Persistent Configuration

      If you use the Persistent Configuration mode for Sync Gateway, your configuration is stored in Couchbase Server.

      Any changes made to your configuration propagate automatically to all Sync Gateway nodes. You can take advantage of using a Load Balancer for your configuration changes. For more information on Load Balancers, see Load Balancer.

      With this configuration mode, you cannot use the /{db}/_offline and /{db}/_online endpoints to take your databases offline or bring them back online. These endpoints are node-local only.

      To take your database online and offline, use POST /{db}/_config with {"offline": true/false}, instead.

      Non-Persistent Configuration (Legacy)

      If you use the Non-Persistent Configuration mode for Sync Gateway, your configuration is stored in local config files.

      You must coordinate any changes to your configuration across all Sync Gateway nodes manually. You cannot use a Load Balancer for configuration changes.

      With this configuration mode, you must use the /{db}/_offline and /{db}/_online endpoints on each individual node you want to take offline or bring online.

      Automatically Taking a Database Offline

      Sync Gateway will automatically take a database offline if it loses the database’s DCP or TAP feed. This enables the cause to be investigated and rectified.

      To bring the database back online after the cause is addressed and the feed(s) restored, use the appropriate Admin REST API endpoint for your configuration mode:

      Take a Database Offline Manually

      This section describes how to manually take a database offline.

      • Persistent Configuration

      • Non-Persistent Configuration

      Use this method when your Sync Gateway configuration is stored in Couchbase Server (recommended).

      1. Make a POST request to /{db}/_config with {"offline": true}.

        You can use a Load Balancer for this operation.

      Use this method when your Sync Gateway configuration is stored in local config files (legacy mode).

      1. Make a POST request to /{db}/_offline on each node individually.

        Do not use a Load Balancer.

      Take a Database Online Manually

      This section describes how to manually bring a database online.

      • Persistent Configuration

      • Non-Persistent Configuration

      Use this method when your Sync Gateway configuration is stored in Couchbase Server (recommended).

      1. Make a POST request to /{db}/_config with {"offline": false}.

        You can use a Load Balancer for this operation.

      Use this method when your Sync Gateway configuration is stored in local config files (legacy mode).

      1. Make a POST request to /{db}/_online on each node individually.

        Do not use a Load Balancer.

      Starting with a Database Offline

      By default, when Sync Gateway starts, it brings all databases that are defined in the configuration file online.

      To keep a database offline when Sync Gateway starts, you can add the offline configuration property to the database configuration properties. For more information, see Database Configuration.

      Later, to bring the database online, use the appropriate method for your configuration mode as described in Take a Database Online Manually.