--- layout: default title: "pg_local_cache: PostgreSQL row cache" seo_title: pg_local_cache - Transaction-aware PostgreSQL row cache description: Open-source PostgreSQL extension for bounded shared-memory caching of primary-key rows through SQL mget, with transaction-aware invalidation and RESP2. image: /assets/social-card.png home: true permalink: / ---

Primary-key cache for PostgreSQL.

Bounded shared-memory caching for whole-row SQL mget lookups, with transaction-aware invalidation and PostgreSQL fallbacks.

curl -fsSL https://github.com/profundium/pg_local_cache/releases/latest/download/install-latest.sh | bash -s -- app
psql │ postgres@localhost:5432/app
app=> SELECT local_cache.attach_table(
        'public.items'::regclass
      );

app=> SELECT local_cache.mget(
        'public.items'::regclass,
        ARRAY[42, 7, 42, NULL]::bigint[]
      );

 {"id":42,"value":"cached"}
 {"id":7,"value":"cached"}
 {"id":42,"value":"cached"}
 NULL
Explicit SQL API

Only local_cache.mget reads the cache.

Transaction-aware

Writes fence affected entries before commit.

Bounded memory

Capacity is fixed at PostgreSQL startup.

Safe fallback

Ineligible reads use the source table.

Built for exact row lookups

One narrow cache contract keeps behavior predictable.

Use it for

  • Repeated reads by complete primary key
  • Hot whole rows that fit bounded shared memory
  • One writable PostgreSQL primary
  • Ordered JSON rows or limited RESP2 access

Keep PostgreSQL direct for

  • Joins, ranges, aggregates, and full scans
  • Arbitrary query-result caching
  • RLS, partitioned, or inherited tables
  • TTL, pub/sub, or distributed coordination

Install on PostgreSQL 14-18

Verified Linux amd64 packages support glibc and musl. First activation requires one PostgreSQL restart.

1Resolve release

Pin one immutable version.

2Verify

Check helper and archive SHA-256.

3Install

Stage files and preload settings.

4Check health

Create and verify after restart.

SQL-only installation for database app
curl -fsSL https://github.com/profundium/pg_local_cache/releases/latest/download/install-latest.sh | bash -s -- app

Need systemd, Patroni, Kubernetes, PGXS, RESP, rollback, or manual checksums? Read the installation guide.

Read path

application PostgreSQL shared row cache

Documentation

PostgreSQL caching questions

Does pg_local_cache replace Redis?

No. It is a focused PostgreSQL row cache with SQL mget and a limited RESP2 endpoint, not a general Redis server.

Does it cache ordinary SELECT queries?

No. Only explicit local_cache.mget calls use the cache. Ordinary SQL keeps the normal PostgreSQL execution path.

How does it handle transactions?

Writes fence affected entries before commit. Unsafe reads and read-your-writes fall back to PostgreSQL.

Which PostgreSQL versions are supported?

Published Linux amd64 binaries target PostgreSQL 14-18 with glibc or musl. Other targets can build through PGXS.