# Get database query stats

`GET https://api.instacloud.com/projects/{projectId}/database/query-stats`

**Token scope:** `account` · `org` · `project` — read-only tokens allowed.

Top statements by execution time (pg_stat_statements/provider API). Provider-specific; may wake a suspended database.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `branch` | query | `string` | no | branch name (default branch if omitted) |
| `group` | query | `string` | no | postgres service name (default: the sole postgres service) |
| `limit` | query | `integer` | no | max rows (1–100, default 20) |
| `sort` | query | `"total" \| "mean" \| "calls"` | no | order by (default total) |
| `projectId` | path | `string` | yes |  |

## Response 200

Default Response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `stats` | `object[]` | no |  |
| `stats.queryId` | `string` | no |  |
| `stats.query` | `string` | no |  |
| `stats.calls` | `number` | no |  |
| `stats.meanMs` | `number` | no |  |
| `stats.totalMs` | `number` | no |  |
| `stats.rows` | `number` | no |  |
| `extensionReady` | `boolean` | no |  |

## Response 400

Default Response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | `string` | yes |  |

## Response 403

Default Response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | `string` | yes |  |

## Response 404

Default Response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | `string` | yes |  |

## Response 409

Default Response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | `string` | yes |  |

## Response 502

Default Response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | `string` | yes |  |
