Skip to content

pg_local_cache

Transaction-aware shared-memory cache serving PostgreSQL primary-key rows over RESP2 MGET

pg_local_cache · Transaction-aware shared-memory cache serving PostgreSQL primary-key rows over RESP2 MGET

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
2890pg_local_cachepg_local_cache3.1.0FEATMITC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--NoYesYesYesnono
Relationships
Schemaslocal_cache
Preload.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY3.1.019 18 17 16 15pg_local_cache-
RPMPIGSTY3.1.019 18 17 16 15pg_local_cache_$vopenssl-libs
DEBPIGSTY3.1.019 18 17 16 15postgresql-$v-pg-local-cache`libssl3
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
el8.aarch64N/APIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
el9.x86_64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
el9.aarch64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
el10.x86_64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
el10.aarch64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
d12.x86_64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
d12.aarch64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
d13.x86_64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
d13.aarch64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
u22.x86_64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
u22.aarch64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
u24.x86_64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
u24.aarch64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
u26.x86_64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
u26.aarch64PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0PIGSTY 3.1.0
PackageVersionOSORGSIZEFile URL
pg_local_cache_193.1.0el9.x86_64pigsty257.8 KiBpg_local_cache_19-3.1.0-1PGSTY.el9.x86_64.rpm
pg_local_cache_193.1.0el9.aarch64pigsty255.1 KiBpg_local_cache_19-3.1.0-1PGSTY.el9.aarch64.rpm
pg_local_cache_193.1.0el10.x86_64pigsty260.5 KiBpg_local_cache_19-3.1.0-1PGSTY.el10.x86_64.rpm
pg_local_cache_193.1.0el10.aarch64pigsty257.5 KiBpg_local_cache_19-3.1.0-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-local-cache3.1.0d12.x86_64pigsty242.4 KiBpostgresql-19-pg-local-cache_3.1.0-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-local-cache3.1.0d12.aarch64pigsty236.9 KiBpostgresql-19-pg-local-cache_3.1.0-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-local-cache3.1.0d13.x86_64pigsty242.4 KiBpostgresql-19-pg-local-cache_3.1.0-1PGSTY~trixie_amd64.deb
postgresql-19-pg-local-cache3.1.0d13.aarch64pigsty237.0 KiBpostgresql-19-pg-local-cache_3.1.0-1PGSTY~trixie_arm64.deb
postgresql-19-pg-local-cache3.1.0u22.x86_64pigsty264.4 KiBpostgresql-19-pg-local-cache_3.1.0-1PGSTY~jammy_amd64.deb
postgresql-19-pg-local-cache3.1.0u22.aarch64pigsty262.1 KiBpostgresql-19-pg-local-cache_3.1.0-1PGSTY~jammy_arm64.deb
postgresql-19-pg-local-cache3.1.0u24.x86_64pigsty250.6 KiBpostgresql-19-pg-local-cache_3.1.0-1PGSTY~noble_amd64.deb
postgresql-19-pg-local-cache3.1.0u24.aarch64pigsty249.3 KiBpostgresql-19-pg-local-cache_3.1.0-1PGSTY~noble_arm64.deb
postgresql-19-pg-local-cache3.1.0u26.x86_64pigsty247.2 KiBpostgresql-19-pg-local-cache_3.1.0-1PGSTY~resolute_amd64.deb
postgresql-19-pg-local-cache3.1.0u26.aarch64pigsty245.3 KiBpostgresql-19-pg-local-cache_3.1.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_local_cache_183.1.0el8.x86_64pigsty255.8 KiBpg_local_cache_18-3.1.0-1PGSTY.el8.x86_64.rpm
pg_local_cache_183.1.0el8.aarch64pigsty249.0 KiBpg_local_cache_18-3.1.0-1PGSTY.el8.aarch64.rpm
pg_local_cache_183.1.0el9.x86_64pigsty257.8 KiBpg_local_cache_18-3.1.0-1PGSTY.el9.x86_64.rpm
pg_local_cache_183.1.0el9.aarch64pigsty255.1 KiBpg_local_cache_18-3.1.0-1PGSTY.el9.aarch64.rpm
pg_local_cache_183.1.0el10.x86_64pigsty260.6 KiBpg_local_cache_18-3.1.0-1PGSTY.el10.x86_64.rpm
pg_local_cache_183.1.0el10.aarch64pigsty257.5 KiBpg_local_cache_18-3.1.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-local-cache3.1.0d12.x86_64pigsty242.4 KiBpostgresql-18-pg-local-cache_3.1.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-local-cache3.1.0d12.aarch64pigsty236.9 KiBpostgresql-18-pg-local-cache_3.1.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-local-cache3.1.0d13.x86_64pigsty242.5 KiBpostgresql-18-pg-local-cache_3.1.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-local-cache3.1.0d13.aarch64pigsty236.9 KiBpostgresql-18-pg-local-cache_3.1.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-local-cache3.1.0u22.x86_64pigsty264.5 KiBpostgresql-18-pg-local-cache_3.1.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-local-cache3.1.0u22.aarch64pigsty262.1 KiBpostgresql-18-pg-local-cache_3.1.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-local-cache3.1.0u24.x86_64pigsty250.6 KiBpostgresql-18-pg-local-cache_3.1.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-local-cache3.1.0u24.aarch64pigsty249.4 KiBpostgresql-18-pg-local-cache_3.1.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-local-cache3.1.0u26.x86_64pigsty247.2 KiBpostgresql-18-pg-local-cache_3.1.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-local-cache3.1.0u26.aarch64pigsty245.3 KiBpostgresql-18-pg-local-cache_3.1.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_local_cache_173.1.0el8.x86_64pigsty255.7 KiBpg_local_cache_17-3.1.0-1PGSTY.el8.x86_64.rpm
pg_local_cache_173.1.0el8.aarch64pigsty248.8 KiBpg_local_cache_17-3.1.0-1PGSTY.el8.aarch64.rpm
pg_local_cache_173.1.0el9.x86_64pigsty257.0 KiBpg_local_cache_17-3.1.0-1PGSTY.el9.x86_64.rpm
pg_local_cache_173.1.0el9.aarch64pigsty255.0 KiBpg_local_cache_17-3.1.0-1PGSTY.el9.aarch64.rpm
pg_local_cache_173.1.0el10.x86_64pigsty260.2 KiBpg_local_cache_17-3.1.0-1PGSTY.el10.x86_64.rpm
pg_local_cache_173.1.0el10.aarch64pigsty257.3 KiBpg_local_cache_17-3.1.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-local-cache3.1.0d12.x86_64pigsty242.2 KiBpostgresql-17-pg-local-cache_3.1.0-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-local-cache3.1.0d12.aarch64pigsty236.7 KiBpostgresql-17-pg-local-cache_3.1.0-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-local-cache3.1.0d13.x86_64pigsty242.4 KiBpostgresql-17-pg-local-cache_3.1.0-1PGSTY~trixie_amd64.deb
postgresql-17-pg-local-cache3.1.0d13.aarch64pigsty236.6 KiBpostgresql-17-pg-local-cache_3.1.0-1PGSTY~trixie_arm64.deb
postgresql-17-pg-local-cache3.1.0u22.x86_64pigsty284.0 KiBpostgresql-17-pg-local-cache_3.1.0-1PGSTY~jammy_amd64.deb
postgresql-17-pg-local-cache3.1.0u22.aarch64pigsty281.4 KiBpostgresql-17-pg-local-cache_3.1.0-1PGSTY~jammy_arm64.deb
postgresql-17-pg-local-cache3.1.0u24.x86_64pigsty250.4 KiBpostgresql-17-pg-local-cache_3.1.0-1PGSTY~noble_amd64.deb
postgresql-17-pg-local-cache3.1.0u24.aarch64pigsty249.2 KiBpostgresql-17-pg-local-cache_3.1.0-1PGSTY~noble_arm64.deb
postgresql-17-pg-local-cache3.1.0u26.x86_64pigsty247.1 KiBpostgresql-17-pg-local-cache_3.1.0-1PGSTY~resolute_amd64.deb
postgresql-17-pg-local-cache3.1.0u26.aarch64pigsty245.1 KiBpostgresql-17-pg-local-cache_3.1.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_local_cache_163.1.0el8.x86_64pigsty255.8 KiBpg_local_cache_16-3.1.0-1PGSTY.el8.x86_64.rpm
pg_local_cache_163.1.0el8.aarch64pigsty248.8 KiBpg_local_cache_16-3.1.0-1PGSTY.el8.aarch64.rpm
pg_local_cache_163.1.0el9.x86_64pigsty257.3 KiBpg_local_cache_16-3.1.0-1PGSTY.el9.x86_64.rpm
pg_local_cache_163.1.0el9.aarch64pigsty255.0 KiBpg_local_cache_16-3.1.0-1PGSTY.el9.aarch64.rpm
pg_local_cache_163.1.0el10.x86_64pigsty260.2 KiBpg_local_cache_16-3.1.0-1PGSTY.el10.x86_64.rpm
pg_local_cache_163.1.0el10.aarch64pigsty257.2 KiBpg_local_cache_16-3.1.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-local-cache3.1.0d12.x86_64pigsty242.3 KiBpostgresql-16-pg-local-cache_3.1.0-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-local-cache3.1.0d12.aarch64pigsty236.6 KiBpostgresql-16-pg-local-cache_3.1.0-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-local-cache3.1.0d13.x86_64pigsty242.4 KiBpostgresql-16-pg-local-cache_3.1.0-1PGSTY~trixie_amd64.deb
postgresql-16-pg-local-cache3.1.0d13.aarch64pigsty236.6 KiBpostgresql-16-pg-local-cache_3.1.0-1PGSTY~trixie_arm64.deb
postgresql-16-pg-local-cache3.1.0u22.x86_64pigsty282.5 KiBpostgresql-16-pg-local-cache_3.1.0-1PGSTY~jammy_amd64.deb
postgresql-16-pg-local-cache3.1.0u22.aarch64pigsty280.3 KiBpostgresql-16-pg-local-cache_3.1.0-1PGSTY~jammy_arm64.deb
postgresql-16-pg-local-cache3.1.0u24.x86_64pigsty250.5 KiBpostgresql-16-pg-local-cache_3.1.0-1PGSTY~noble_amd64.deb
postgresql-16-pg-local-cache3.1.0u24.aarch64pigsty249.2 KiBpostgresql-16-pg-local-cache_3.1.0-1PGSTY~noble_arm64.deb
postgresql-16-pg-local-cache3.1.0u26.x86_64pigsty247.1 KiBpostgresql-16-pg-local-cache_3.1.0-1PGSTY~resolute_amd64.deb
postgresql-16-pg-local-cache3.1.0u26.aarch64pigsty245.1 KiBpostgresql-16-pg-local-cache_3.1.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_local_cache_153.1.0el8.x86_64pigsty257.1 KiBpg_local_cache_15-3.1.0-1PGSTY.el8.x86_64.rpm
pg_local_cache_153.1.0el8.aarch64pigsty250.0 KiBpg_local_cache_15-3.1.0-1PGSTY.el8.aarch64.rpm
pg_local_cache_153.1.0el9.x86_64pigsty259.5 KiBpg_local_cache_15-3.1.0-1PGSTY.el9.x86_64.rpm
pg_local_cache_153.1.0el9.aarch64pigsty256.7 KiBpg_local_cache_15-3.1.0-1PGSTY.el9.aarch64.rpm
pg_local_cache_153.1.0el10.x86_64pigsty262.2 KiBpg_local_cache_15-3.1.0-1PGSTY.el10.x86_64.rpm
pg_local_cache_153.1.0el10.aarch64pigsty258.7 KiBpg_local_cache_15-3.1.0-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-local-cache3.1.0d12.x86_64pigsty243.8 KiBpostgresql-15-pg-local-cache_3.1.0-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-local-cache3.1.0d12.aarch64pigsty238.2 KiBpostgresql-15-pg-local-cache_3.1.0-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-local-cache3.1.0d13.x86_64pigsty244.4 KiBpostgresql-15-pg-local-cache_3.1.0-1PGSTY~trixie_amd64.deb
postgresql-15-pg-local-cache3.1.0d13.aarch64pigsty238.0 KiBpostgresql-15-pg-local-cache_3.1.0-1PGSTY~trixie_arm64.deb
postgresql-15-pg-local-cache3.1.0u22.x86_64pigsty285.1 KiBpostgresql-15-pg-local-cache_3.1.0-1PGSTY~jammy_amd64.deb
postgresql-15-pg-local-cache3.1.0u22.aarch64pigsty282.8 KiBpostgresql-15-pg-local-cache_3.1.0-1PGSTY~jammy_arm64.deb
postgresql-15-pg-local-cache3.1.0u24.x86_64pigsty252.5 KiBpostgresql-15-pg-local-cache_3.1.0-1PGSTY~noble_amd64.deb
postgresql-15-pg-local-cache3.1.0u24.aarch64pigsty251.2 KiBpostgresql-15-pg-local-cache_3.1.0-1PGSTY~noble_arm64.deb
postgresql-15-pg-local-cache3.1.0u26.x86_64pigsty249.6 KiBpostgresql-15-pg-local-cache_3.1.0-1PGSTY~resolute_amd64.deb
postgresql-15-pg-local-cache3.1.0u26.aarch64pigsty247.5 KiBpostgresql-15-pg-local-cache_3.1.0-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_local_cache;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_local_cache;		# install by package name

pig install pg_local_cache -v 19;   # install for PG 19
pig install pg_local_cache -v 18;   # install for PG 18
pig install pg_local_cache -v 17;   # install for PG 17
pig install pg_local_cache -v 16;   # install for PG 16
pig install pg_local_cache -v 15;   # install for PG 15

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_local_cache';

Create this extension with:

CREATE EXTENSION pg_local_cache;

Usage

Sources:

pg_local_cache 3.1.0 caches whole rows by their complete primary key in bounded shared memory. Cached reads now use authenticated RESP MGET; SQL local_cache.mget is removed and ordinary SELECT queries are not rewritten. PostgreSQL remains the durable source of truth.

Core Workflow

shared_preload_libraries = 'pg_local_cache'
pg_local_cache.database = 'app'
pg_local_cache.role = 'local_cache_worker'
pg_local_cache.bind_address = '127.0.0.1'
pg_local_cache.port = 6380
pg_local_cache.auth_token_file = '/secure/path/token'
CREATE EXTENSION pg_local_cache;
CREATE TABLE public.items (id bigint PRIMARY KEY, value text);
INSERT INTO public.items VALUES (42, 'example');
SELECT local_cache.attach_table('public.items'::regclass);
SELECT local_cache.health();

After authenticating the RESP connection:

MGET CRUD:app.public.items:{"id":42} CRUD:app.public.items:{"id":7}

Operational Boundaries

Append the library to existing preload entries, provision a dedicated worker role and its documented metadata/table grants, secure the token file, and restart. A superuser creates the extension in fixed schema local_cache. Attach only supported permanent primary-key tables. RESP MGET preserves order and duplicate keys and returns null for missing rows. Workers use the configured database role, not the client’s SQL privileges, transaction or snapshot. Keep joins, projections, row locks and session-sensitive reads in ordinary SQL.

local_cache.attach_table installs invalidation triggers; local_cache.detach_table removes a mapping; local_cache.reconcile_table revalidates it after DDL or privilege changes. local_cache.health, local_cache.stats and local_cache.metrics report readiness and resource use. Normal PostgreSQL writes invalidate affected cache entries. RLS, partitioned and inherited tables are outside the documented workload. There is no TTL or distributed cache coordination.

Supports PostgreSQL 14–18 on one writable primary. Non-loopback listeners require pg_local_cache.tls or explicit pg_local_cache.allow_plaintext_network opt-in. TLS uses separate certificate/key settings; a CA setting enables mutual TLS. The reloadable pg_local_cache.enabled switch disables caching.

Before upgrading from 2.x, move SQL MGET callers to the RESP authorization model. Install matching 3.1.0 files, configure listener security, restart, confirm the library version and listener readiness, then run ALTER EXTENSION pg_local_cache UPDATE in each affected database. Dependencies on removed functions or the replaced metrics return type can block migration; the script deliberately avoids CASCADE. No downgrade script is supplied.

Upgrade from 3.0.0 to 3.1.0

Version 3.1.0 changes the shared-memory layout and fixes stale-read races and worker memory leaks. Restart PostgreSQL after installing the matching library, then update the extension in each database; the SQL migration itself changes no objects or attached-table mappings. Verify pg_local_cache.binary_version and local_cache.health() afterward.

pg_local_cache.cache_entries now counts descriptors, while byte capacity comes from slab storage. Review pg_local_cache.lock_partitions, dirty-marker limits, the new pg_local_cache.max_deferred_misses, client slots and the process file-descriptor limit before restarting. MGET deduplicates misses, but single-flight waiters can use later transactions; a complete response is not guaranteed to share one snapshot.

Table reader