Skip to content

feat: scale Postgres memory settings with instance RAM#100

Draft
tonychang04 wants to merge 1 commit into
mainfrom
feat/scale-pg-memory-settings
Draft

feat: scale Postgres memory settings with instance RAM#100
tonychang04 wants to merge 1 commit into
mainfrom
feat/scale-pg-memory-settings

Conversation

@tonychang04

@tonychang04 tonychang04 commented Jul 15, 2026

Copy link
Copy Markdown
Member

Problem

docker-init/db/postgresql.conf ships nano-safe memory values (shared_buffers=32MB, work_mem=2MB, maintenance_work_mem=16MB, effective_cache_size=128MB) and every instance tier runs them#98 made max_connections/pool scale with RAM, but the memory settings stayed fixed, so a large (8G) or xl (16G) instance runs nano-tuned Postgres and leaves most of its RAM unused by the planner and buffer cache.

Change

Same mechanism as #98:

  • auto-scale-memory.sh picks per-tier values (nano tier = current conf values, unchanged) and writes PG_SHARED_BUFFERS / PG_EFFECTIVE_CACHE_SIZE / PG_WORK_MEM / PG_MAINTENANCE_WORK_MEM to .env
  • compose passes them as -c flags (command line wins over config_file); the -c defaults equal the conf values, so hosts without the env vars behave exactly as before
Tier shared_buffers effective_cache_size work_mem maintenance_work_mem
nano (~0.5G) 32MB 128MB 2MB 16MB
micro (~1G) 64MB 256MB 4MB 32MB
small (~2G) 128MB 512MB 4MB 64MB
medium (~4G) 256MB 1GB 8MB 128MB
large (~8G) 512MB 2GB 8MB 256MB
xl (~16G) 1GB 4GB 16MB 512MB
2xl (~32G) 2GB 8GB 16MB 1GB

shared_buffers stays ~15–25% of the postgres container limit (not host RAM) since the host is shared with the API; work_mem is bounded per tier against worst-case work_mem × max_connections.

Verification

  • bash -n + real run of auto-scale-memory.sh (24G host → xl tier written to .env correctly)
  • docker compose config renders the -c flags for both the scaled case and the no-env default case (defaults = conf values, no behavior change)
  • Nano values are the exact config just validated under load (see docs: load-test evidence for the nano Postgres memory settings #99): survives 90-conn storm fail-fast, 0 OOM

Notes

🤖 Generated with Claude Code

https://claude.ai/code/session_01J9NtiFkU34HQQgRSffNb4k


Summary by cubic

Scale Postgres memory settings with instance RAM so larger tiers don’t run nano defaults and can better use available memory. docker-compose.yml now passes these settings via -c flags with safe defaults, so behavior is unchanged until auto-scale runs.

  • New Features

    • auto-scale-memory.sh writes PG_SHARED_BUFFERS, PG_EFFECTIVE_CACHE_SIZE, PG_WORK_MEM, PG_MAINTENANCE_WORK_MEM to .env based on RAM tiers.
    • docker-compose.yml applies them with -c flags; defaults equal current postgresql.conf values.
    • Tiers mirror connection scaling; shared_buffers ~15–25% of the Postgres container limit; work_mem bounded per tier.
  • Migration

    • No action needed. Changes apply on next provision/resize or after running auto-scale-memory.sh and docker compose up. Existing instances keep current behavior until then.

Written for commit 419f78b. Summary will update on new commits.

Review in cubic

postgresql.conf ships nano-safe values (shared_buffers=32MB, work_mem=2MB,
maintenance_work_mem=16MB, effective_cache_size=128MB) and every tier ran
them — a large (8G) instance got nano-tuned Postgres. Follow the #98
pattern: auto-scale-memory.sh picks per-tier values and writes them to
.env; the compose command passes them as -c flags (command line overrides
config_file). Without the env vars the -c defaults equal the conf values,
so behavior on existing hosts is unchanged until auto-scale re-runs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J9NtiFkU34HQQgRSffNb4k
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a83a801e-3c27-4587-9b0c-340cc32e2cff

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/scale-pg-memory-settings

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant