---
title: "Update a service's resource limits (memory, CPU caps)."
method: PATCH
path: "/external-services/{id}/resources"
tags: ["External Services"]
---

# Update a service's resource limits (memory, CPU caps).

`PATCH /external-services/{id}/resources`

## 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}/resources`
- Auth: none declared

Persists the new caps to the encrypted config AND live-applies them
via Docker's update API. Memory and CPU can be hot-changed without a
restart on running containers; stopped containers also accept the
update and pick up the new caps on next start.

Pass `null` (or omit) any field to leave it unlimited. A request where
every field is `null` removes any existing limits.

The response includes a per-container `applied[]` list so the caller
can tell which members got the update and which were skipped (e.g.,
container not yet created, or `docker update` rejected because the
new memory cap is below current usage).

## Path parameters

- `id` integer, required

## Request body

- ServiceResourceLimits: Optional cgroup resource limits applied to a service container. All fields are `Option<i64>`: `None` means "no limit" (the kernel default), matching Docker's behavior when the corresponding `HostConfig` field is left at zero. Operators opt in to limits explicitly through the `PATCH /external-services/{id}/resources` endpoint or by writing the `resources` block into `ServiceConfig::parameters` at create time. These map directly onto bollard fields: - `memory_mb` → `HostConfig.memory` (bytes) - `memory_swap_mb`→ `HostConfig.memory_swap` (bytes; ≥ memory) - `nano_cpus` → `HostConfig.nano_cpus` (1e9 = 1 full CPU) - `cpu_shares` → `HostConfig.cpu_shares` (relative weight, default 1024) - `shm_size_mb` → `HostConfig.shm_size` (bytes; default 64 MiB) IMPORTANT: enabling hard memory limits causes the kernel OOM killer to terminate the container when the working set exceeds the limit. The container will restart (RestartPolicy::ALWAYS) but in-flight queries fail. Surface this clearly in any UI that lets users set limits.
  - `cpu_shares` integer, nullable: Relative CPU weight (default 1024). Only used when `nano_cpus` is None.
  - `memory_mb` integer, nullable: Hard memory limit in MiB. None = unlimited.
  - `memory_swap_mb` integer, nullable: Memory + swap limit in MiB. None = unlimited. MUST be >= memory_mb when both are set; Docker rejects the request otherwise. Set equal to `memory_mb` to disable swap entirely.
  - `nano_cpus` integer, nullable: CPU quota in nano-cpus. 1_000_000_000 = 1 full CPU core. None = unlimited.
  - `shm_size_mb` integer, nullable: Shared memory (/dev/shm) size in MiB. None = Docker default (64 MiB). Maps to HostConfig.shm_size (bytes). PostgreSQL uses /dev/shm for parallel query workers and large work_mem; the 64 MiB default causes "could not resize shared memory segment ... No space left on device" under load. NOTE: shm_size is fixed at container-create time — Docker's live update API cannot change it, so changing this value recreates the container.

## Response `200`

Updated resource limits

- ResourceLimitsUpdateResponse: Response from PATCH /external-services/{id}/resources.
  - `applied` ResourceLimitApplyResult[], required: Per-container result of trying to apply the limits live.
    - `container_name` string, required
    - `error` string, nullable: Populated only when `outcome == "failed"`.
    - `outcome` string, required: One of: - "applied" — Docker accepted the update; caps are live now. - "missing" — container does not exist; caps stored, will apply on next start. - "stopped" — container exists but isn't running; Docker still accepts the update (the new caps apply on next start). - "failed" — `docker update` returned an error (see `error`).
    - `role` string, required: `service_members.role` for cluster members; "standalone" otherwise.
  - `limits` ServiceResourceLimits, required: The limits that were persisted to the encrypted config.
    - `cpu_shares` integer, nullable: Relative CPU weight (default 1024). Only used when `nano_cpus` is None.
    - `memory_mb` integer, nullable: Hard memory limit in MiB. None = unlimited.
    - `memory_swap_mb` integer, nullable: Memory + swap limit in MiB. None = unlimited. MUST be >= memory_mb when both are set; Docker rejects the request otherwise. Set equal to `memory_mb` to disable swap entirely.
    - `nano_cpus` integer, nullable: CPU quota in nano-cpus. 1_000_000_000 = 1 full CPU core. None = unlimited.
    - `shm_size_mb` integer, nullable: Shared memory (/dev/shm) size in MiB. None = Docker default (64 MiB). Maps to HostConfig.shm_size (bytes). PostgreSQL uses /dev/shm for parallel query workers and large work_mem; the 64 MiB default causes "could not resize shared memory segment ... No space left on device" under load. NOTE: shm_size is fixed at container-create time — Docker's live update API cannot change it, so changing this value recreates the container.
  - `shm_not_applied` string, nullable: Set when a new `/dev/shm` size was saved but could not be applied, because that needs a new container and replacing it was refused or failed (the reason says which, and that no data was changed).

## Other responses

- `400`: Invalid resource limits
- `404`: Service not found
- `500`: Internal server error

## Changes

- **2026-10-12** `7cc011be3463`: 1 info
  - added the optional property `shm_not_applied` to the response with the `200` status
- **2026-07-01** `d83dcb738585`: 2 info
  - added the new optional request property `shm_size_mb`
  - added the optional property `limits/shm_size_mb` to the response with the `200` status
- **2026-05-30** `b72341d12f63`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/external-services/:id/resources/patch.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)
