---
title: "Return the latest per-database metric values for a Postgres or MariaDB service."
method: GET
path: "/external-services/{id}/metrics/by-database"
tags: ["Metrics"]
---

# Return the latest per-database metric values for a Postgres or MariaDB service.

`GET /external-services/{id}/metrics/by-database`

## Request

- Base URL: `/api` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/external-services/{id}/metrics/by-database`
- Auth: HTTP bearer

Postgres: groups `pg_stat_database` and size metrics by `datname` (size,
cache-hit ratio, commits, tuple activity). MariaDB: groups storage metrics
by schema (data, index and free-space size, table count, estimated rows).
The UI shows this as a breakdown table instead of collapsing every database
into one value. Engines without per-database series get an empty list
while the metrics store is available; without it the endpoint returns 503.

## Path parameters

- `id` integer, required

## Response `200`

Per-database metric breakdown; empty for engines without per-database series

- DatabaseMetricsResponse: Response for the per-database metrics breakdown.
  - `databases` DatabaseMetricsRow[], required: One entry per database, largest first by the engine's `*.database_size_bytes` metric (ties broken by name) so the biggest database leads the table. Empty when the service's engine has no per-database series (for example Redis or S3) or nothing has been scraped yet. The MariaDB collector labels at most the 100 largest schemas per scrape; the response covers the latest lookback window, so during schema churn it can briefly include schemas from an earlier scrape as well.
    - `database` string, required: Database name: the `datname` of a Postgres database, or the schema name of a MariaDB database.
    - `metrics` object, required: Latest value of each of the engine's per-database metrics for this database, keyed by metric name (e.g. `{"pg.database_size_bytes": 7943871, "pg.cache_hit_ratio": 0.99}` for Postgres, or `{"mariadb.database_size_bytes": 1589248, "mariadb.tables": 3}` for MariaDB). A metric that has not been reported is absent.

## Other responses

- `401`: Unauthorized
- `404`: External service not found
- `500`: Internal server error
- `503`: Metrics not available

## Changes

- **2026-10-27** `16d4df6e7b6a`: 1 info
  - added the non-success response with the status `404`
- **2026-06-05** `61b7612b2d33`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/external-services/:id/metrics/by-database/get.md)

---

[API](https://skmtc.dev/gotempsh/apis/temps.md) - [All operations](https://skmtc.dev/gotempsh/apis/temps/llms.txt) - [OpenAPI document](https://skmtc.dev/gotempsh/apis/temps/revisions/3b040526eb43?raw)
