Skip to content

Feature Request: PostgreSQL backend support #29

@rivetphilbot

Description

@rivetphilbot

Summary

It would be great to have PostgreSQL as an alternative backend to SQLite for LCM storage. This unlocks several capabilities that are difficult or impossible with SQLite:

Motivation

  • Multi-agent shared memory — Multiple OpenClaw instances (e.g., separate agents on different containers) can read/write the same conversation store concurrently without SQLite file locking issues
  • Native full-text search — PostgreSQL's tsvector/tsquery with GIN indexes provides robust FTS without needing FTS5 (which isn't always available)
  • Trigram similarity searchpg_trgm extension enables fuzzy/approximate text matching
  • pgvector support — Future path for semantic search via embeddings stored alongside conversation data
  • Centralized backups — One database to back up rather than per-agent SQLite files scattered across containers
  • Connection pooling — Proper concurrent access for multi-tenant setups

Proposed Architecture

A DbClient interface abstraction that both SQLite and PostgreSQL implement, keeping the store layer backend-agnostic:

  • SQLite remains the default (backwards compatible)
  • When connectionString is set in LCM config, use PostgreSQL instead
  • Stores use the DbClient interface instead of DatabaseSync directly
  • FTS5 queries map to tsvector/tsquery equivalents
  • Recursive CTEs port cleanly (both engines support them)

Working Fork

I've started implementing this as a fork with dual SQLite/PostgreSQL backend support:

https://github.com/rivetphilbot/lossless-claw-pg

Key changes:

  • src/db/db-interface.ts — Backend-agnostic database client interface
  • src/db/postgres-client.ts — PostgreSQL implementation using pg Pool
  • src/db/sqlite-client.ts — SQLite wrapper implementing the same interface
  • src/store/tsquery-sanitize.ts — PostgreSQL FTS query sanitizer
  • Modified stores to use DbClient instead of DatabaseSync

The fork tracks upstream releases and maintains backwards compatibility with the SQLite backend.

Use Case

Running a homelab with multiple OpenClaw agents (different models on separate LXC containers) that need to share conversation memory through a centralized PostgreSQL instance. Each agent gets its own database with tenant isolation, but the same schema and tooling.

Happy to contribute this upstream if there's interest. The dual-backend approach means it's additive — no breaking changes to existing SQLite users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions