---
title: "Clean Change Vector"
description: "* A database's change vector contains entries from each instance of the database"
url: "https://docs.ravendb.net/6.2/client-api/operations/maintenance/clean-change-vector"
version: "6.2"
---

# Clean Change Vector

> 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."

## Clean Change Vector

> **Note**
>
> - A database's [change vector](https://docs.ravendb.net/6.2/server/clustering/replication/change-vector.md) contains entries from each instance of the database
>   in the database group. However, even when an instance no longer exists (because it was removed or replaced) its entry will remain in the
>   database change vector. These entries can build up over time, leading to longer change vectors that take up unnecessary space.
>
> - **`UpdateUnusedDatabasesOperation`** lets you specify the IDs of database instances that no longer exist so that their entries can be
>   removed from the database change vector.
>
> - This operation does not affect any documents' *current* change vectors, but from now on when documents are modified or created their
>   change vector will not include the obsolete entries.

## Syntax

```csharp
public UpdateUnusedDatabasesOperation(string database, HashSet<string> unusedDatabaseIds)
```

| Parameter | Type | Description |
| - | - | - |
| **database** | `string` | Name of the database |
| **unusedDatabaseIds** | `HashSet<string>` | The database IDs to be removed from the change vector |

## Example

In the 'General Stats' view in the [management studio](https://docs.ravendb.net/6.2/studio/overview.md), you can see your database's current change vector (it's
the same as the change vector of the database's most recently updated/created document).

Below we see the change vector of an [example database](https://docs.ravendb.net/6.2/start/about-examples.md) "NorthWind". It includes three entries: one of the
NorthWind instance currently housed on cluster node A (whose ID begins with `N79J...`), and two of instances that were also previously
housed on node A but which no longer exist.

![Fig. 1](https://docs.ravendb.net/assets/images/clean-change-vector-6ed561388a738db08131220df5b697f5.png)

This code removes the obsolete entries specified by their database instance IDs:

### Sync

```csharp
documentStore.Maintenance.Server.Send(
              new UpdateUnusedDatabasesOperation(documentStore.Database, new HashSet<string>
{
  "0N64iiIdYUKcO+yq1V0cPA",
  "xwmnvG1KBkSNXfl7/0yJ1A"
}));
```

### Async

```csharp
await documentStore.Maintenance.Server.SendAsync(
              new UpdateUnusedDatabasesOperation(documentStore.Database, new HashSet<string>
{
  "0N64iiIdYUKcO+yq1V0cPA",
  "xwmnvG1KBkSNXfl7/0yJ1A"
}));
```

Next time a document is modified, you will see that the database change vector has been cleaned.

![Fig. 2](https://docs.ravendb.net/assets/images/clean-change-vector-after-68504b309e38ac59acd938b3122bea01.png)
