---
title: "Data subscriptions: Maintenance operations"
description: "Manage existing data subscriptions from the client API: delete, enable or disable, drop a connection, list subscriptions, and read a subscription's state."
url: "https://docs.ravendb.net/7.2/data-subscriptions/maintenance-operations"
version: "7.2"
language: "csharp"
---

# Data subscriptions: Maintenance operations

> Client language: C#. Also available for [Java](https://docs.ravendb.net/7.2/data-subscriptions/maintenance-operations.java.md), [Node.js](https://docs.ravendb.net/7.2/data-subscriptions/maintenance-operations.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - After creating a subscription, your client can manage it using the document store's `Subscriptions` property, of type `DocumentSubscriptions`.
>
> - You can enable or disable a subscription, read its state, delete it, or drop worker connections.
>
> - In this article:
>   - [Deleting a subscription](#deleting-a-subscription)
>   - [Enabling and disabling a subscription](#enabling-and-disabling-a-subscription)
>   - [Dropping connections](#dropping-connections)
>     - [Dropping all connections](#dropping-all-connections)
>     - [Dropping a specific worker's connection](#dropping-a-specific-workers-connection)
>   - [Listing subscriptions](#listing-subscriptions)
>   - [Getting a subscription state](#getting-a-subscription-state)
>   - [Updating a subscription](#updating-a-subscription)

## Deleting a subscription {#deleting-a-subscription}

Removing subscriptions from the database can be helpful when, for example, many single-use subscriptions
have accumulated and managing them becomes hard.

```csharp
void Delete(string name, string database = null);
Task DeleteAsync(string name, string database = null, CancellationToken token = default);
```

Usage:

```csharp
store.Subscriptions.Delete(subscriptionName);
```

## Enabling and disabling a subscription {#enabling-and-disabling-a-subscription}

Disable a subscription to stop it from accepting worker connections, or enable it to resume.  
A disabled subscription keeps its definition and progress; only its ability to connect is shut down.

```csharp
void Disable(string name, string database = null);
Task DisableAsync(string name, string database = null, CancellationToken token = default);

void Enable(string name, string database = null);
Task EnableAsync(string name, string database = null, CancellationToken token = default);
```

Usage:

```csharp
store.Subscriptions.Disable(subscriptionName);
store.Subscriptions.Enable(subscriptionName);
```

## Dropping connections {#dropping-connections}

### Dropping all connections

Drop a subscription's active connections using `DropConnection`, passing the subscription name.

- Dropping a connection ends the worker's `Run` task, but leaves the subscription enabled.  
  Once dropped, the worker will not reconnect on its own.

- To resume, [create a new worker](https://docs.ravendb.net/7.2/data-subscriptions/consuming-subscription.md#creating-a-subscription-worker) and run it.  
  The new worker continues processing after the last batch the previous worker acknowledged.

  > **Note**
  >
  > If the connection was dropped before the previous worker acknowledged a batch, the server sends the batch again
  > to the next worker that connects to the subscription, so the batch's documents may be processed more than once
  > (see [At-least-once delivery](https://docs.ravendb.net/7.2/data-subscriptions/consuming-subscription.md#at-least-once-delivery)).

- To stop the subscription from accepting workers,
  [disable it](#enabling-and-disabling-a-subscription).

```csharp
void DropConnection(string name, string database = null);
Task DropConnectionAsync(string name, string database = null, CancellationToken token = default);
```

Usage:

```csharp
store.Subscriptions.DropConnection(subscriptionName);
```

### Dropping a specific worker's connection

To drop the connection of a specific worker, rather than all the subscription's connections, pass the worker object to `DropSubscriptionWorker`.  
This is useful with [concurrent subscriptions](https://docs.ravendb.net/7.2/data-subscriptions/concurrent-subscriptions.md#dropping-a-worker), where several workers are connected at the same time.  
When the subscription runs in single-worker mode, only one worker is connected at a time, so dropping this worker's connection has the same effect as dropping all connections.

## Listing subscriptions {#listing-subscriptions}

Retrieve the database's subscriptions using `GetSubscriptions`.  
The method returns a `List<SubscriptionState>`, one entry per subscription, each holding the state
described in [Getting a subscription state](#getting-a-subscription-state) below.  
Use `start` to set how many subscriptions to skip and `take` to set the maximum number to return.

```csharp
List<SubscriptionState> GetSubscriptions(int start, int take, string database = null);
Task<List<SubscriptionState>> GetSubscriptionsAsync(int start, int take,
    string database = null, CancellationToken token = default);
```

Usage:

```csharp
// List the first 10 subscriptions
List<SubscriptionState> firstSubscriptions = store.Subscriptions.GetSubscriptions(0, 10);

// List all subscriptions
List<SubscriptionState> allSubscriptions = store.Subscriptions.GetSubscriptions(0, int.MaxValue);
```

## Getting a subscription state {#getting-a-subscription-state}

To retrieve the state of a single subscription from the server use `GetSubscriptionState`, passing it the subscription's name.  
The returned `SubscriptionState` lets you inspect the subscription. For example, read
`LastBatchAckTime` for the time the server last acknowledged the worker's progress,
`ChangeVectorForNextBatchStartingPoint` for the point the next batch will start from, or `Disabled` to check
whether the subscription currently accepts workers.

```csharp
SubscriptionState GetSubscriptionState(string subscriptionName, string database = null);
Task<SubscriptionState> GetSubscriptionStateAsync(string subscriptionName,
    string database = null, CancellationToken token = default);
```

Usage:

```csharp
SubscriptionState subscriptionState = store.Subscriptions.GetSubscriptionState(subscriptionName);
```

The returned `SubscriptionState` object includes, among others, the following properties:

| Property | Type | Description |
| - | - | - |
| **Query** | `string` | The subscription's RQL query. |
| **SubscriptionName** | `string` | The subscription's name, which is also its unique identifier. |
| **SubscriptionId** | `long` | The subscription's internal identifier, assigned by the cluster at creation. |
| **MentorNode** | `string` | The mentor node, if one was set manually. |
| **PinToMentorNode** | `bool` | `true` when the subscription is pinned to the mentor node, so another node does not take it over. |
| **NodeTag** | `string` | The tag of the server node processing the subscription. |
| **ChangeVectorForNextBatchStartingPoint** | `string` | The change vector from which the subscription will begin sending documents to the worker. Updated on batch acknowledgment, and can also be set manually. |
| **LastBatchAckTime** | `DateTime?` | The last time the server acknowledged progress on the subscription's documents. |
| **LastClientConnectionTime** | `DateTime?` | The last time a client connected (retained after the connection ends). |
| **Disabled** | `bool` | When `true`, the subscription does not allow workers to connect. |
| **ArchivedDataProcessingBehavior** | `ArchivedDataProcessingBehavior?` | The subscription's handling of archived documents.<br />See [Archived documents](https://docs.ravendb.net/7.2/data-subscriptions/creating-subscription/creating-subscription_api.md#archived-documents). |
| **ShardingState** | `SubscriptionShardingState` | The subscription's state on each shard of a [sharded database](https://docs.ravendb.net/7.2/sharding/subscriptions.md) (e.g., the change vector from which each shard will start its next batch, and the node that processes the subscription on each shard).<br />`null` when the database is not sharded. |

If no subscription with the given name exists, `GetSubscriptionState` throws a `SubscriptionDoesNotExistException`.  
To check whether a subscription exists (e.g., before your application connects a worker to the subscription), call
`GetSubscriptionState` and catch this exception.

```csharp
try
{
    store.Subscriptions.GetSubscriptionState("OrdersShippedToUK");
    // The subscription exists
}
catch (SubscriptionDoesNotExistException)
{
    // No subscription named "OrdersShippedToUK" exists
}
```

## Updating a subscription {#updating-a-subscription}

Change the definition of an existing subscription using `Update` / `UpdateAsync`.  
See [Updating a subscription](https://docs.ravendb.net/7.2/data-subscriptions/creating-subscription/creating-subscription_api.md#updating-a-subscription)
on the Creating a data subscription page.
