---
title: "Find statements with filters | Speedscale Docs"
description: "Narrow your services' recorded PostgreSQL, MySQL and SQL Server calls in the Speedscale dashboard to the ones that matter: by user, session, transaction, table, statement, error code, deadlock or timeout, row count, route or trace id."
canonical: "https://docs.speedscale.com/guides/databases/find-statements/"
---

[Documentation index](https://docs.speedscale.com/guides/llms.txt) | [Markdown](https://docs.speedscale.com/guides/databases/find-statements/index.md) | [Canonical page](https://docs.speedscale.com/guides/databases/find-statements/)

# Find statements with filters

A busy service runs millions of database calls a day. The **Database** filters on the **Traffic** page narrow them to the ones you care about in one step: the statements that failed with a given error, the calls that deadlocked, everything one service account ran, every statement that touched a table, or the queries that returned too many rows. Because the filters compare the facts Speedscale recorded for each call, they need no access to the database.

When a filter targets database traffic, the grid switches to the [Database columns](https://docs.speedscale.com/guides/databases/#watch-database-traffic), so the matches read like a database profiler trace.

<a id="the-database-filters"></a>

## The Database filters

Open **Filters**, add a filter and pick a field from the **Database** group at the end of the list:

| Filter | What it matches | Example |
| --- | --- | --- |
| Application | The client's application name | Every call from one service's connection pool |
| DB user | The database user that logged in | Everything a service account or a person ran |
| Database | The database it connected to | One schema in a shared server |
| Session | The server's id for the connection: the Postgres backend pid, the MySQL connection id or the SQL Server session id (SPID) | Everything one connection did |
| Transaction | `idle`, `active` or `failed` when the statement started | Statements that ran inside a transaction that had already failed |
| Event | `login`, `logout` or `statement` | Every login, to see who connects and how often |
| SQL operation | The leading command, such as `SELECT` or `DELETE` | Every `DELETE` |
| Table | A table the statement names | Every call that touches `orders` |
| Statement shape | The statement with its values masked | Every execution of one query |
| Error | The SQLSTATE for Postgres, or the error number for MySQL and SQL Server | Every `23505` unique violation or `40P01` deadlock, or SQL Server's `2627` and `1205` |
| Attention | `cancelled`, `timeout`, `deadlock`, `lock_timeout`, `terminated`, `cancel_request` or `aborted` | Every call that timed out |
| Rows | Rows returned or changed, compared with is, greater than or less than | Queries that returned more than 1,000 rows |
| Route | The route the app wrote into the statement's SQL comment | Every statement `orders#show` ran |

Text fields compare with **is**, **contains** or **regex**, and each can be negated. The value pickers offer the values in the traffic you are looking at, and errors show with their names, such as `23505 · unique_violation`.

![The filter type list in the Filters dialog, ending with Trace ID, UUID and the Database group: Application, DB user, Database, Session, Transaction, Event, SQL operation, Table, Statement shape, Error, Attention, Rows and Route](https://docs.speedscale.com/assets/images/database-filters-30dc3ec996828dbbc377e1c5b6bfc5ce.png)

<a id="filter-by-trace-id"></a>

## Filter by trace id

The **Trace ID** filter matches one request's trace across protocols: HTTP and gRPC calls by their `traceparent` or B3 headers, and database calls by the trace id the app wrote into their SQL comment. A filter on a header would drop the database calls, so use **Trace ID** to see a request together with the queries it ran. You can paste a whole `traceparent`; the filter keeps only the trace id. See [Link queries to the request that ran them](https://docs.speedscale.com/guides/databases/link-queries-to-requests/).

<a id="filter-from-a-call"></a>

## Filter from a call

In the request drawer, every database fact of a call carries a filter and an exclude button. Open a failed call, select the filter next to its error code, and the grid shows every call that failed the same way; select the one next to its session to follow that connection. See [Inspect a statement](https://docs.speedscale.com/guides/databases/inspect-a-statement/).

<a id="recipes"></a>

## Recipes

| To find | Filter on |
| --- | --- |
| Deadlocks and lock timeouts | Attention is `deadlock`, or Attention is `lock_timeout` |
| Duplicate-key failures | Error is `23505` (Postgres), `1062` (MySQL), or `2627` or `2601` (SQL Server) |
| Slow writes | SQL operation is `UPDATE` and Duration greater than 100 ms |
| Unbounded queries | Rows greater than 1000 |
| Work done inside failed transactions | Transaction is `failed` |
| One connection's story | Session is the session id, then open any call's Connection tab |
| Who touches a sensitive table | Table is the table, then read the User and Application columns |

<a id="limits"></a>

## Limits

*   The connection facts (user, database, application, session) need a capture from Speedscale 2.5.1103 or later, and the route and trace id need 2.5.1153 or later. Traffic indexed before an upgrade keeps the facts it was indexed with, so filter on a recent time range.
*   Database filters match PostgreSQL, MySQL and SQL Server calls. Other databases are found with the usual filters, such as Host or L7 Protocol.
*   On a SQL Server connection recorded without TLS interception whose driver encrypted the login packet, DB user and Application are empty, so filter those calls by Database or Session instead. See [Record SQL Server](https://docs.speedscale.com/proxymock/databases/record/sqlserver/#encryption).

<a id="related"></a>

## Related

*   [Inspect a statement](https://docs.speedscale.com/guides/databases/inspect-a-statement/)
*   [Database traffic](https://docs.speedscale.com/concepts/database-traffic/)
*   [Filters and Subsets](https://docs.speedscale.com/concepts/filter/)
