Menu ▾ ▴

#66 PostgresStore: share one memory across processes and machines (1.0, item A)

closed
nobody
None
2026-10-18
2026-10-17
Anonymous
No

Originally created by: Thanatos9404

Why

SQLite is one file on one machine. Production agents run several workers, serverless functions or replicas, and teams already run Postgres (Supabase, Neon, RDS). Without a shared store, llmslim serve can't scale past one box, and a hosted tier can't exist.

What

pip install "llmslim[postgres]" (psycopg 3). Then:

Memory("postgresql://user:pass@host:5432/db")              # or PostgresStore(url, table="my_app_memory")

:::bash
llmslim serve --db postgresql://user:pass@host:5432/db     # same for llmslim mcp
  • Schema: the table (llmslim_memory by default, or table=...) and <table>_meta are created if missing.
  • Creation runs under pg_advisory_xact_lock, so several processes can start at once (tested with 6 at once).
  • A newer schema version is refused rather than misread.
  • Inputs: a URL, for which the store opens and later closes its own pool; your own psycopg_pool.ConnectionPool, which it leaves open; or an autocommit psycopg.Connection. A non-autocommit connection is refused.
  • Times are TIMESTAMPTZ and come back as UTC-aware datetimes even when the session TimeZone is not UTC. Tested with Asia/Kolkata and microseconds kept.
  • Order: seq is an identity column. Eight threads × 25 writes kept all 200 turns with unique, ordered seq, and each writer's turns stayed in the order it added them.
  • Duplicate ids raise ValueError, and the whole batch rolls back.
  • Safety: table names are validated before connecting (no SQL injection through table=), and all SQL is composed with psycopg.sql.Identifier.
  • --db: in serve and mcp it accepts a postgresql:// URL. A shared storage_target() helper keeps SQLite paths working as before.

Tests

  • The whole tests/test_memory.py suite now also runs on Postgres when LLMSLIM_TEST_POSTGRES_URL is set: 16 parametrized tests across the 3 stores.
  • tests/test_memory_postgres.py adds 13 more:
  • URL detection;
  • table-name validation;
  • persistence;
  • duplicates and a newer schema;
  • pool and connection inputs;
  • time zones;
  • concurrent writers;
  • concurrent schema creation;
  • the HTTP server on Postgres.
  • New CI job, "Memory on Postgres": it runs both files against a postgres:17 service.
  • Locally, against PostgreSQL 18:
  • 1,801 passed, 8 skipped;
  • postgres.py coverage 98%;
  • every test table was dropped afterwards.
  • Without a database, the Postgres-only tests skip and the rest run.

Related

Tickets: #22
Tickets: #70

Discussion

  • Anonymous

    Anonymous - 2026-10-17

    Originally posted by: vercel[bot]

    The latest updates on your projects. Learn more about Vercel for GitHub.

    Project Deployment Actions Updated
    llmslim Ready Ready Preview <relative-time datetime="2026-10-17T09:41:29.438Z">Oct 17, 2026 9:41am UTC</relative-time>
     
  • Anonymous

    Anonymous - 2026-10-17

    Ticket changed by: Thanatos9404

    • status: open --> closed
     

Log in to post a comment.