---
id: w1/m25/t002
title: "`top-queries` endpoint: `pg_stat_statements`-backed; verify/enable the extension on CNPG cluster spec"
worker: worker1
status: todo
estimate: 1h
depends_on: []
---

## Objective

Expose Render's `GET /postgres/{id}/top-queries` equivalent, backed by `pg_stat_statements`, across REST/GraphQL/MCP.

## Context

- `pg_stat_statements` is not currently guaranteed enabled on tenant CNPG clusters — check the CNPG `Cluster` spec / `postgresql.conf` `shared_preload_libraries` the operator applies.
- CNPG supports enabling extensions via `Cluster.spec.postgresql.shared_preload_libraries` and a `CREATE EXTENSION` bootstrap.

## Steps

1. Confirm whether `pg_stat_statements` is already loaded on managed-Postgres clusters (check the operator's CNPG `Cluster` CR template).
2. If not, add it to `shared_preload_libraries` + a bootstrap `CREATE EXTENSION IF NOT EXISTS pg_stat_statements` for new and existing clusters.
3. Add a `TopQueries` verb querying `pg_stat_statements` ordered by total/mean time, exposed on REST (`GET /v1/postgres/{id}/top-queries`), GraphQL, and MCP.

## Files

- operator CNPG `Cluster` template (likely under `lego/operator/internal/...` postgres reconciler)
- `lego/backend/internal/postgres/` observability verb + REST/GraphQL/MCP adapters

## Acceptance criteria

- [ ] `pg_stat_statements` is enabled on managed-Postgres clusters (new and existing, via migration/rollout).
- [ ] `GET /v1/postgres/{id}/top-queries` returns real query-stat rows from a live CNPG cluster.
- [ ] GraphQL and MCP equivalents match.

## Out of scope

- Query-plan/EXPLAIN introspection — not part of Render's parity surface.
