Get a PostgreSQL instance's metrics

Get each node's transactions, writes, connections, cache hit ratio, disk use and replication lag over time. Defaults to the last day. A range can be at most 366 days.

GET https://{availability_zone}.betterstackcloud.com/v1/postgres/{id}/metrics
id string required

The ID of the PostgreSQL instance.

from datetime

The start of the range. Defaults to one day before to. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

to datetime

The end of the range. Defaults to now. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

Authorization string required

Bearer $TOKEN

200

Returns each node's metrics over time.

200 OK
{
  "postgres_id": "123456789",
  "postgres_name": "Example",
  "from": "2026-07-01T12:00:00.000Z",
  "to": "2026-07-01T12:00:00.000Z",
  "resolution": "raw",
  "members": [
    {
      "member_id": "123456789",
      "role": "primary",
      "data": [
        {
          "dt": "2026-07-01T12:00:00.000Z",
          "transactions_per_second": 1.5,
          "writes_per_second": 1.5,
          "connections": {
            "direct": 1.5,
            "direct_max": 1,
            "pooled": 1.5,
            "pooled_max": 1,
            "max_connections": 1,
            "max_pooled_connections": 1
          },
          "cache_hit_ratio": 1.5,
          "disk": {
            "used_bytes": 1,
            "used_bytes_max": 1,
            "usable_bytes": 1
          },
          "replication_lag_seconds": 1.5
        }
      ]
    }
  ]
}
400

The body isn't valid JSON.

400 Bad Request
{
  "error": {
    "message": "Malformed JSON body.",
    "code": "bad_request"
  }
}
401

The API token is missing or invalid.

401 Unauthorized
{
  "error": {
    "message": "Missing or invalid token.",
    "code": "unauthorized"
  }
}
402

The organization hasn't made its first payment yet, and the request creates a resource we charge for. The code is payment_required. A request that creates a server, load balancer, object cache, database, reserved IP or volume can also return first_purchase. The url in first_purchase opens a page where you make the payment. The resource is created after the payment. The page works until expires_at, 24 hours after the response.

402 Payment Required
{
  "error": {
    "message": "We require at least one successful credit card transaction before allowing billable actions via the API. This significantly helps us to prevent fraud. Once your first transaction is processed, you will be able to use the API unrestricted. Please add credit to your account at https://betterstack.com/settings/billing/card/new?credits=10&activate_api=true. Need help? We're here for you at hello@betterstack.com.",
    "code": "payment_required"
  }
}
403

A rule of the resource forbids the request.

404

We couldn't find a resource with this ID in this zone.

404 Not Found
{
  "error": {
    "message": "Resource not found.",
    "code": "not_found"
  }
}
409

The resource's current status doesn't allow the request.

422

A value isn't valid, with the code validation_failed. The error's details list the messages for each field.

423

We've locked the resource, with the code locked. Every change to a locked resource is refused, and so is a change that involves one.

429

Too many requests, with the code rate_limited. We limit requests per client IP and per organization, and some costly endpoints have a stricter limit. Wait as long as the Retry-After header says.

500

An unexpected, temporary error on our side, with the code internal_error. Try again.

500 Internal Server Error
{
  "error": {
    "message": "The request could not be completed right now. Please try again in a few moments.",
    "code": "internal_error"
  }
}
503

We couldn't set up or change the resource, with the code orchestration_failed. Or the organization is creating too many resources at the same time, with the code concurrent_create_limit. Try again after a short wait.

postgres_id string

The instance's ID.

postgres_name string

The instance's name.

from datetime

The start of the range returned. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

to datetime

The end of the range returned. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

resolution string

How far apart the points are.
Valid values:
raw: One point per minute, for a range of up to one day.
hourly: One point per hour, for a longer range.

members array of objects

Each node's metrics over time. Every point has the transaction and write rates, the connections straight to PostgreSQL and through PgBouncer, the cache hit ratio, the disk use and the replication lag.

members[].member_id string

The member id.

members[].role string

Whether the node is the primary or a replica.
Valid values:
primary: The node that accepts writes.
replica: A read-only copy of the primary.

members[].data array of objects

The data.

members[].data[].dt datetime

In ISO 8601 format, such as 2026-07-01T12:00:00Z.

members[].data[].transactions_per_second number

The transactions per second.

members[].data[].writes_per_second number

The writes per second.

members[].data[].connections object

The connections.

members[].data[].connections.direct number

The direct.

members[].data[].connections.direct_max integer

The direct max.

members[].data[].connections.pooled number

The pooled.

members[].data[].connections.pooled_max integer

The pooled max.

members[].data[].connections.max_connections integer

The max connections.

members[].data[].connections.max_pooled_connections integer

The max pooled connections.

members[].data[].cache_hit_ratio number

The cache hit ratio.

members[].data[].disk object

The disk.

members[].data[].disk.used_bytes integer

The used bytes.

members[].data[].disk.used_bytes_max integer

The used bytes max.

members[].data[].disk.usable_bytes integer

The usable bytes.

members[].data[].replication_lag_seconds number

The replication lag seconds.