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

# Get Statistics

> Client language: PHP. Also available for [C#](https://docs.ravendb.net/6.2/client-api/operations/maintenance/get-stats.md), [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), [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`:

```php
// Pass an instance of class `GetCollectionStatisticsOperation` to the store
/** @var  CollectionStatistics $stats */
$stats = $store->maintenance()->send((new GetCollectionStatisticsOperation());
```

Statistics are returned in the `CollectionStatistics` object.

```php
// Collection stats results:
class CollectionStatistics
{
  // Total # of documents in all collections
  private ?int $countOfDocuments = null;
  // Total # of conflicts
  private ?int $countOfConflicts = null;
  // Total # of documents per collection
  private array $collections = [];

  // ... getters and setters
}
```

## Get detailed collection statistics

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

```php
// Pass an instance of class `GetDetailedCollectionStatisticsOperation` to the store
/** @var DetailedCollectionStatistics $stats */
$stats = $store->maintenance()->send(new GetDetailedCollectionStatisticsOperation());
```

Statistics are returned in the `DetailedCollectionStatistics` object.

```php
// 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
class CollectionDetails
{
  private ?string $name = null;
  private ?int $countOfDocuments = null;
  private ?Size $size = null;
  private ?Size $documentsSize = null;
  private ?Size $tombstonesSize = null;
  private ?Size $revisionsSize = null;

  // ... getters and setters
}
```

## Get database statistics

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

```php
// Pass an instance of class `GetStatisticsOperation` to the store
/** @var DatabaseStatistics $stats */
$stats = $store->maintenance()->send(new GetStatisticsOperation());
```

Statistics are returned in the `DatabaseStatistics` object.

```php
// Database stats results:
class DatabaseStatistics implements ResultInterface
{
  private ?int $lastDocEtag = null;               // Last document etag in database
  private ?int $lastDatabaseEtag = null;          // Last database etag

  private ?int $countOfIndexes = null;            // Total # of indexes in database
  private ?int $countOfDocuments = null;          // Total # of documents in database
  private ?int $countOfRevisionDocuments = null;  // Total # of revision documents in database
  private ?int $countOfDocumentsConflicts = null; // Total # of documents conflicts in database
  private ?int $countOfTombstones = null;         // Total # of tombstones in database
  private ?int $countOfConflicts = null;          // Total # of conflicts in database
  private ?int $countOfAttachments = null;        // Total # of attachments in database
  private ?int $countOfUniqueAttachments = null;  // Total # of unique attachments in database
  private ?int $countOfCounterEntries = null;     // Total # of counter-group entries in database
  private ?int $countOfTimeSeriesSegments = null; // Total # of time-series segments in database

  // List of stale index names in database
  public function getStaleIndexes(): IndexInformationArray
  {
      return IndexInformationArray::fromArray(
          array_map(
              function (IndexInformation $index) {
                  return $index->isStale();
              },
          $this->indexes->getArrayCopy())
      );
  }

  // Statistics for each index in database
  private ?IndexInformationArray $indexes = null;

  private ?string $databaseChangeVector = null;           // Global change vector of the database
  private ?string $databaseId = null;                     // Database identifier
  private bool $is64Bit = false;                          // Indicates if process is 64-bit
  private ?string $pager = null;                          // Component handling the memory-mapped files
  private ?DateTimeInterface $lastIndexingTime = null;    // Last time of indexing an item
  private ?Size $sizeOnDisk = null;                       // Database size on disk
  private ?Size $tempBuffersSizeOnDisk = null;            // Temp buffers size on disk
  private ?int $numberOfTransactionMergerQueueOperations = null;

  // ... getters and setters
}
```

## Get detailed database statistics

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

```php
// Pass an instance of class `GetDetailedStatisticsOperation` to the store
/** @var DetailedDatabaseStatistics $stats */
$stats = $store->maintenance()->send(new GetDetailedStatisticsOperation());
```

Statistics are returned in the `DetailedDatabaseStatistics` object.

```php
// Detailed database stats results:
class DetailedDatabaseStatistics extends DatabaseStatistics implements ResultInterface
{
  // Total # of identities in database
  private ?int $countOfIdentities = null;
  // Total # of compare-exchange items in database
  private ?int $countOfCompareExchange = null;
  // Total # of cmpXchg tombstones in database
  private ?int $countOfCompareExchangeTombstones = null;
  // Total # of TS deleted ranges values in database
  private ?int $countOfTimeSeriesDeletedRanges = null;

  // ... getters and setters
}
```

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

```php
// Get stats for 'AnotherDatabase':
/** @var DatabaseStatistics $stats */
$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.php.md).

## See also

- [What are Operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.php.md)
- [Switch operation to another database](https://docs.ravendb.net/6.2/client-api/operations/how-to/switch-operations-to-a-different-database.php.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.php.md)
