# pg_stat_statements — Postgres extension

> Timing and call counts for every query shape (Insights reads it).

Source: https://scribase.com/extensions/pg_stat_statements

Category: Performance. Version: 1.11. Enabled on every project by the platform.

## About

pg_stat_statements groups queries by shape (constants replaced with placeholders) and keeps calls, total and mean time, rows and buffer use for each. It is the first place to look when the database feels slow: sort by total time to find what costs the most overall.

## Enable it

```sql
create extension if not exists pg_stat_statements with schema extensions;
```

## Example

```sql
select
  calls,
  round(total_exec_time) as total_ms,
  round(mean_exec_time::numeric, 2) as mean_ms,
  left(query, 80) as query
from pg_stat_statements
order by total_exec_time desc
limit 10;
```

Upstream: https://www.postgresql.org/docs/17/pgstatstatements.html