dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Home/Error Library/postgresql-could-not-resize-shared-memory
PostgreSQL
PG 14 - 17Memory & Docker
6 min read
ERROR: could not resize shared memory segment: No space left on device

PostgreSQL "could not resize shared memory segment": Where Does Memory Run Out?

The Docker /dev/shm 64MB default limit, parallel query shared memory exhaustion, proper work_mem calculation, and ordered remediation.

Reviewed by:Senior Database Architect & SRE (dataiotech Labs)
Tested Versions: PostgreSQL 14.10, 15.6, 16.4, 17.0 (Ubuntu 24.04 LTS / Docker 26.1)

Operational Verification & Reliability Metadata

Last Technical Review: 27 Ekim 2026
Tested VersionsPostgreSQL 14.10, 15.6, 16.4, 17.0 (Ubuntu 24.04 LTS, Docker 26.1, Kernel 6.8)
Required PrivilegesSUPERUSER or pg_read_all_stats / pg_signal_backend
Risk Assessment
MediumTerminating active sessions forces application-layer transaction rollbacks
Expected OutputTotal connections drop safely below max_connections threshold in pg_stat_activity
Rollback Procedure:Reset temporary session timeouts, reload PgBouncer or revert pool sizing
PostgreSQL Docs: Connections
First 60 Seconds Emergency Protocol:

The error string is a symptom, not the root cause. Do not restart the server blindly. Run the diagnostic queries below to pinpoint the actual failure mode.

▸Symptoms

plaintext
ERROR: could not resize shared memory segment: No space left on device ERROR: out of memory

The issue is almost universally Docker's default 64MB mount for /dev/shm.

▸Ordered Fix

  1. 1Adjust Docker `--shm-size`: Set --shm-size=1g or in docker-compose.yml:
yaml
services: postgres: shm_size: 1gb
  1. 1Emergency Query Throttle: Disable parallel gathering temporarily:
sql
SET max_parallel_workers_per_gather = 0;
  1. 1Audit `work_mem` Formula:
plaintext
work_mem ≈ (RAM - shared_buffers) / (max_connections * 3)

Other Database Error Triage Playbooks

Other battle-tested diagnostic guides for high-severity database errors.

All Errors (20)