---
title: "Get Statistics"
url: "https://docs.ravendb.net/6.2/client-api/operations/maintenance/get-stats"
version: "6.2"
language: "csharp"
---

# Get Statistics

> Client language: C#. Also available for [Java](https://docs.ravendb.net/6.2/client-api/operations/maintenance/get-stats.java.md), [Python](https://docs.ravendb.net/6.2/client-api/operations/maintenance/get-stats.python.md), [PHP](https://docs.ravendb.net/6.2/client-api/operations/maintenance/get-stats.php.md), [Node.js](https://docs.ravendb.net/6.2/client-api/operations/maintenance/get-stats.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**
>
> - Statistics can be retrieved for the database and for collections.
>
> - By default, statistics are retrieved for the database defined in the Document Store.  
>   To get database and collection statistics for another database use [ForDatabase](#get-stats-for-another-database).
>
> - In this page:
>   - [Get collection statistics](#get-collection-statistics)
>   - [Get detailed collection statistics](#get-detailed-collection-statistics)
>   - [Get database statistics](#get-database-statistics)
>   - [Get detailed database statistics](#get-detailed-database-statistics)
>   - [Get statistics for another database](#get-statistics-for-another-database)

## Get collection statistics

To get **collection statistics**, use `GetCollectionStatisticsOperation`:

```csharp
// Pass an instance of class `GetCollectionStatisticsOperation` to the store 
CollectionStatistics stats =
  store.Maintenance.Send(new GetCollectionStatisticsOperation());
```

Statistics are returned in the `CollectionStatistics` object.

```csharp
// Collection stats results:
public class CollectionStatistics
{
  // Total # of documents in all collections
  public long CountOfDocuments { get; set; }
  // Total # of conflicts
  public long CountOfConflicts { get; set; }
  // Total # of documents per collection
  public Dictionary<string, long> Collections { get; set; }
}
```

## Get detailed collection statistics

To get **detailed collection statistics**, use `GetDetailedCollectionStatisticsOperation`:

```csharp
// Pass an instance of class `GetDetailedCollectionStatisticsOperation` to the store 
DetailedCollectionStatistics stats =
  store.Maintenance.Send(new GetDetailedCollectionStatisticsOperation());
```

Statistics are returned in the `DetailedCollectionStatistics` object.

```csharp
// Detailed collection stats results:
public class DetailedCollectionStatistics
{
  // Total # of documents in all collections
  public long CountOfDocuments { get; set; }
  // Total # of conflicts
  public long CountOfConflicts { get; set; }
  // Collection details per collection
  public Dictionary<string, CollectionDetails> Collections { get; set; }
}

// Details per collection
public class CollectionDetails
{        
  public string Name { get; set; }
  public long CountOfDocuments { get; set; }
  public Size Size { get; set; }
  public Size DocumentsSize { get; set; }
  public Size TombstonesSize { get; set; }
  public Size RevisionsSize { get; set; }
}
```

## Get database statistics

To get **database statistics**, use `GetStatisticsOperation`:

```csharp
// Pass an instance of class `GetStatisticsOperation` to the store 
DatabaseStatistics stats =
  store.Maintenance.Send(new GetStatisticsOperation());
```

Statistics are returned in the `DatabaseStatistics` object.

```csharp
// Database stats results:
public class DatabaseStatistics
{
  public long? LastDocEtag { get; set; }      // Last document etag in database
  public long? LastDatabaseEtag { get; set; } // Last database etag
  
  public int CountOfIndexes { get; set; }     // Total # of indexes in database
  public long CountOfDocuments { get; set; }  // Total # of documents in database
  public long CountOfRevisionDocuments { get; set; }  // Total # of revision documents in database
  public long CountOfDocumentsConflicts { get; set; } // Total # of documents conflicts in database
  public long CountOfTombstones { get; set; }         // Total # of tombstones in database
  public long CountOfConflicts { get; set; }          // Total # of conflicts in database
  public long CountOfAttachments { get; set; }        // Total # of attachments in database
  public long CountOfUniqueAttachments { get; set; }  // Total # of unique attachments in database
  public long CountOfCounterEntries { get; set; }     // Total # of counter-group entries in database
  public long CountOfTimeSeriesSegments { get; set; } // Total # of time-series segments in database
  
  // List of stale index names in database
  public string[] StaleIndexes => Indexes?.Where(x => x.IsStale).Select(x => x.Name).ToArray();
  // Statistics for each index in database
  public IndexInformation[] Indexes { get; set; }
  
  public string DatabaseChangeVector { get; set; } // Global change vector of the database
  public string DatabaseId { get; set; }           // Database identifier
  public bool Is64Bit { get; set; }                // Indicates if process is 64-bit
  public string Pager { get; set; }                // Component handling the memory-mapped files
  public DateTime? LastIndexingTime { get; set; }  // Last time of indexing an item
  public Size SizeOnDisk { get; set; }             // Database size on disk
  public Size TempBuffersSizeOnDisk { get; set; }  // Temp buffers size on disk
  public int NumberOfTransactionMergerQueueOperations { get; set; }
}
```

## Get detailed database statistics

To get **detailed database statistics**, use `GetDetailedStatisticsOperation`:

```csharp
// Pass an instance of class `GetDetailedStatisticsOperation` to the store 
DetailedDatabaseStatistics stats =
  store.Maintenance.Send(new GetDetailedStatisticsOperation());
```

Statistics are returned in the `DetailedDatabaseStatistics` object.

```csharp
// Detailed database stats results:
public class DetailedDatabaseStatistics : DatabaseStatistics
{
  // Total # of identities in database
  public long CountOfIdentities { get; set; }
  // Total # of compare-exchange items in database
  public long CountOfCompareExchange { get; set; }
  // Total # of cmpXchg tombstones in database
  public long CountOfCompareExchangeTombstones { get; set; }
  // Total # of TS deleted ranges values in database
  public long CountOfTimeSeriesDeletedRanges { get; set; }
}
```

## Get statistics for another database

- By default, you get statistics for the database defined in your Document Store.
- Use `ForDatabase` to get database and collection statistics for another database.
- `ForDatabase` can be used with **any** of the above statistics options.

```csharp
// Get stats for 'AnotherDatabase':
DatabaseStatistics stats =
  store.Maintenance.ForDatabase("AnotherDatabase").Send(new GetStatisticsOperation());
```

- Learn more about switching operations to another database [here](https://docs.ravendb.net/6.2/client-api/operations/how-to/switch-operations-to-a-different-database.md).

## See also

- [What are Operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.md)
- [Switch operation to another database](https://docs.ravendb.net/6.2/client-api/operations/how-to/switch-operations-to-a-different-database.md)
- [What is a Collection](https://docs.ravendb.net/6.2/client-api/faq/what-is-a-collection.md)
- [Get Query Statistics](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-get-query-statistics.md)
