> For the complete documentation index, see [llms.txt](https://docs.datasentinel.io/manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.datasentinel.io/manual/features/key-features/session-history.md). Agents can also search and read this documentation through its [MCP server](https://docs.datasentinel.io/manual/~gitbook/mcp).

# Session History

Datasentinel samples the active sessions of your PostgreSQL instances and keeps their history, so you can see what an instance was doing at any time.

Session History shows the load of an instance over time. It tells you how many sessions were active, what they were doing, and which queries, users or applications they belonged to.

Use it to find the source of a slowdown, to see whether sessions were on CPU, doing I/O or waiting for a lock, and to identify the queries behind a peak.

<figure><picture><source srcset="https://1072624949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlcWi6G1jtNuyGT9C0pkc%2Fuploads%2Fgit-blob-2db4a41975d3fe0e924477a13cdf90b441a13a82%2Fsession-history-dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://1072624949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlcWi6G1jtNuyGT9C0pkc%2Fuploads%2Fgit-blob-5093ba1fc25dadf17d283cbd38cd662e7dcc6bad%2Fsession-history.svg?alt=media" alt="Animated illustration of the Session History dashboard. The active sessions of a PostgreSQL instance are charted over the selected time range, stacked by wait event type, with annotations on blocked sessions. The chart dimension is switched to the user name and the chart is redrawn by user. The workload is then grouped by database, filtered on one database, and the queries responsible for that workload are listed with their pg_stat_statements metrics."></picture><figcaption><p>Session History: active sessions over time, by any dimension</p></figcaption></figure>

## How it works

The agent samples the active sessions in `pg_stat_activity`. A session is active when it is running a query or waiting for a resource.

The samples are aggregated into a session load, stored every 10 seconds. The load is expressed in **average active sessions**: a value of 4 means that, on average, 4 sessions were active at the same time.

{% hint style="info" %}
The session load is stored every 10 seconds. The sampling frequency itself is set by the `collection-rate` parameter of the agent. See the [Agent CLI](https://docs.datasentinel.io/manual/implementation/agent-usage/cli.md).
{% endhint %}

## Dimensions

Each sample carries tags taken from `pg_stat_activity`. You can group and filter the load by any of them.

| Tag                                                                                                        | Meaning                                                                                                              |
| ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [wait\_event\_type](https://docs.datasentinel.io/manual/features/tips-and-hints/wait-event-description.md) | Category of the wait: CPU, IO, Lock, and so on                                                                       |
| [wait\_event](https://docs.datasentinel.io/manual/features/tips-and-hints/wait-event-description.md)       | Precise event the session waits on                                                                                   |
| application\_name                                                                                          | Application that opened the session                                                                                  |
| client\_host\_name                                                                                         | Host the session connects from                                                                                       |
| command\_type                                                                                              | Type of statement, such as SELECT or UPDATE                                                                          |
| query\_md5\_id                                                                                             | [Identifier](https://docs.datasentinel.io/manual/features/tips-and-hints/query-identifier.md) of the query being run |
| user\_name                                                                                                 | PostgreSQL user of the session                                                                                       |

{% hint style="info" %}
Your own [tags](https://docs.datasentinel.io/manual/features/tips-and-hints/tags.md), such as application, environment or datacenter, apply here too. They let you look at one instance or at a whole group of instances.
{% endhint %}

## Read the dashboard

* **The main chart** shows the session load over time. Group it by wait event type or by wait event to see where the time goes.
* **The three small charts** show cluster or system metrics of your choice, on the same time axis. See [Metric Correlation](https://docs.datasentinel.io/manual/features/tips-and-hints/metric-correlation.md).
* **The lower part** ranks the load by the dimension you choose, such as wait event, query or user.

Select a time window, then zoom on a peak. Every part of the dashboard follows the new window and the filters in effect.

{% hint style="info" %}
Hover over the question mark next to a wait event to read its description. See [Wait Event Description](https://docs.datasentinel.io/manual/features/tips-and-hints/wait-event-description.md).
{% endhint %}

## Typical questions

| Question                                      | How to answer it                                                                                                                             |
| --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| Why was the application slow at 10:40?        | Zoom on that time and read the dominant wait event type.                                                                                     |
| Is the instance short of CPU or of I/O?       | Group by wait event type and compare CPU and IO.                                                                                             |
| Which query caused the peak?                  | Group the load by query, then open the query.                                                                                                |
| Which application or user loads the instance? | Group the load by application or by user.                                                                                                    |
| Were sessions blocked?                        | Look at the Lock wait event type, then open the [Lock Explorer](https://docs.datasentinel.io/manual/features/key-features/lock-explorer.md). |

## Go further

* From a query, open its details: statistics, history and execution plans. See [Top Queries](https://docs.datasentinel.io/manual/features/key-features/top-queries.md).
* Alerts and blocking scenarios appear as [annotations](https://docs.datasentinel.io/manual/features/tips-and-hints/graphical-annotations.md) on the chart.
* The **Session history** [report](https://docs.datasentinel.io/manual/features/key-features/reporting.md) puts this dashboard in a PDF.

{% content-ref url="/pages/dbLGoTRlMNoFwgFYcbNF" %}
[Metric Correlation](https://docs.datasentinel.io/manual/features/tips-and-hints/metric-correlation.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.datasentinel.io/manual/features/key-features/session-history.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
