Skip to content

pg_kv

Shared-memory key/value cache, token-bucket rate limits and sorted sets.

pg_kv : Shared-memory key/value cache, token-bucket rate limits and sorted sets.

Overview

ID Extension Package Version Category License Language
2895 pg_kv pg_kv 0.1.0 FEAT PostgreSQL Rust
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sLd-- No Yes Yes Yes no no
Relationships
Schemas kv
Early release, not production ready. Preload/restart and superuser installation required. Cluster-wide keyspace: nontransactional, not durable or replicated. Grant kv schema usage deliberately; prefixing keys is not tenant access control. Capacity eviction can reset rate-limit allowance.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 0.1.0 18 17 16 15 14 pg_kv -
RPM PIGSTY 0.1.0 18 17 16 15 14 pg_kv_$v -
DEB PIGSTY 0.1.0 18 17 16 15 14 postgresql-$v-pg-kv -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
el8.aarch64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
el9.x86_64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
el9.aarch64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
el10.x86_64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
el10.aarch64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
d12.x86_64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
d12.aarch64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
d13.x86_64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
d13.aarch64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u22.x86_64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u22.aarch64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u24.x86_64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u24.aarch64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u26.x86_64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
u26.aarch64 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 PIGSTY 0.1.0 N/A
Package Version OS ORG SIZE File URL
pg_kv_18 0.1.0 el8.x86_64 pigsty 242.2 KiB pg_kv_18-0.1.0-1PGSTY.el8.x86_64.rpm
pg_kv_18 0.1.0 el8.aarch64 pigsty 213.2 KiB pg_kv_18-0.1.0-1PGSTY.el8.aarch64.rpm
pg_kv_18 0.1.0 el9.x86_64 pigsty 246.2 KiB pg_kv_18-0.1.0-1PGSTY.el9.x86_64.rpm
pg_kv_18 0.1.0 el9.aarch64 pigsty 229.6 KiB pg_kv_18-0.1.0-1PGSTY.el9.aarch64.rpm
pg_kv_18 0.1.0 el10.x86_64 pigsty 246.2 KiB pg_kv_18-0.1.0-1PGSTY.el10.x86_64.rpm
pg_kv_18 0.1.0 el10.aarch64 pigsty 229.9 KiB pg_kv_18-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-kv 0.1.0 d12.x86_64 pigsty 209.5 KiB postgresql-18-pg-kv_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-kv 0.1.0 d12.aarch64 pigsty 181.5 KiB postgresql-18-pg-kv_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-kv 0.1.0 d13.x86_64 pigsty 209.5 KiB postgresql-18-pg-kv_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-kv 0.1.0 d13.aarch64 pigsty 181.5 KiB postgresql-18-pg-kv_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-kv 0.1.0 u22.x86_64 pigsty 224.8 KiB postgresql-18-pg-kv_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-kv 0.1.0 u22.aarch64 pigsty 208.4 KiB postgresql-18-pg-kv_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-kv 0.1.0 u24.x86_64 pigsty 223.5 KiB postgresql-18-pg-kv_0.1.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-kv 0.1.0 u24.aarch64 pigsty 206.6 KiB postgresql-18-pg-kv_0.1.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-kv 0.1.0 u26.x86_64 pigsty 223.0 KiB postgresql-18-pg-kv_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-kv 0.1.0 u26.aarch64 pigsty 206.1 KiB postgresql-18-pg-kv_0.1.0-1PGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_kv_17 0.1.0 el8.x86_64 pigsty 242.1 KiB pg_kv_17-0.1.0-1PGSTY.el8.x86_64.rpm
pg_kv_17 0.1.0 el8.aarch64 pigsty 213.3 KiB pg_kv_17-0.1.0-1PGSTY.el8.aarch64.rpm
pg_kv_17 0.1.0 el9.x86_64 pigsty 246.1 KiB pg_kv_17-0.1.0-1PGSTY.el9.x86_64.rpm
pg_kv_17 0.1.0 el9.aarch64 pigsty 229.4 KiB pg_kv_17-0.1.0-1PGSTY.el9.aarch64.rpm
pg_kv_17 0.1.0 el10.x86_64 pigsty 246.2 KiB pg_kv_17-0.1.0-1PGSTY.el10.x86_64.rpm
pg_kv_17 0.1.0 el10.aarch64 pigsty 229.8 KiB pg_kv_17-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-kv 0.1.0 d12.x86_64 pigsty 209.5 KiB postgresql-17-pg-kv_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-kv 0.1.0 d12.aarch64 pigsty 181.7 KiB postgresql-17-pg-kv_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-kv 0.1.0 d13.x86_64 pigsty 209.6 KiB postgresql-17-pg-kv_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-17-pg-kv 0.1.0 d13.aarch64 pigsty 181.4 KiB postgresql-17-pg-kv_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-17-pg-kv 0.1.0 u22.x86_64 pigsty 224.7 KiB postgresql-17-pg-kv_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-17-pg-kv 0.1.0 u22.aarch64 pigsty 208.2 KiB postgresql-17-pg-kv_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-17-pg-kv 0.1.0 u24.x86_64 pigsty 223.4 KiB postgresql-17-pg-kv_0.1.0-1PGSTY~noble_amd64.deb
postgresql-17-pg-kv 0.1.0 u24.aarch64 pigsty 206.2 KiB postgresql-17-pg-kv_0.1.0-1PGSTY~noble_arm64.deb
postgresql-17-pg-kv 0.1.0 u26.x86_64 pigsty 223.0 KiB postgresql-17-pg-kv_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-17-pg-kv 0.1.0 u26.aarch64 pigsty 206.1 KiB postgresql-17-pg-kv_0.1.0-1PGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_kv_16 0.1.0 el8.x86_64 pigsty 242.2 KiB pg_kv_16-0.1.0-1PGSTY.el8.x86_64.rpm
pg_kv_16 0.1.0 el8.aarch64 pigsty 213.3 KiB pg_kv_16-0.1.0-1PGSTY.el8.aarch64.rpm
pg_kv_16 0.1.0 el9.x86_64 pigsty 246.3 KiB pg_kv_16-0.1.0-1PGSTY.el9.x86_64.rpm
pg_kv_16 0.1.0 el9.aarch64 pigsty 229.5 KiB pg_kv_16-0.1.0-1PGSTY.el9.aarch64.rpm
pg_kv_16 0.1.0 el10.x86_64 pigsty 246.2 KiB pg_kv_16-0.1.0-1PGSTY.el10.x86_64.rpm
pg_kv_16 0.1.0 el10.aarch64 pigsty 229.8 KiB pg_kv_16-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-kv 0.1.0 d12.x86_64 pigsty 209.7 KiB postgresql-16-pg-kv_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-kv 0.1.0 d12.aarch64 pigsty 181.3 KiB postgresql-16-pg-kv_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-kv 0.1.0 d13.x86_64 pigsty 209.7 KiB postgresql-16-pg-kv_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-16-pg-kv 0.1.0 d13.aarch64 pigsty 181.3 KiB postgresql-16-pg-kv_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-16-pg-kv 0.1.0 u22.x86_64 pigsty 224.9 KiB postgresql-16-pg-kv_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-16-pg-kv 0.1.0 u22.aarch64 pigsty 208.2 KiB postgresql-16-pg-kv_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-16-pg-kv 0.1.0 u24.x86_64 pigsty 223.5 KiB postgresql-16-pg-kv_0.1.0-1PGSTY~noble_amd64.deb
postgresql-16-pg-kv 0.1.0 u24.aarch64 pigsty 206.6 KiB postgresql-16-pg-kv_0.1.0-1PGSTY~noble_arm64.deb
postgresql-16-pg-kv 0.1.0 u26.x86_64 pigsty 223.1 KiB postgresql-16-pg-kv_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-16-pg-kv 0.1.0 u26.aarch64 pigsty 205.7 KiB postgresql-16-pg-kv_0.1.0-1PGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_kv_15 0.1.0 el8.x86_64 pigsty 242.1 KiB pg_kv_15-0.1.0-1PGSTY.el8.x86_64.rpm
pg_kv_15 0.1.0 el8.aarch64 pigsty 213.3 KiB pg_kv_15-0.1.0-1PGSTY.el8.aarch64.rpm
pg_kv_15 0.1.0 el9.x86_64 pigsty 246.2 KiB pg_kv_15-0.1.0-1PGSTY.el9.x86_64.rpm
pg_kv_15 0.1.0 el9.aarch64 pigsty 229.4 KiB pg_kv_15-0.1.0-1PGSTY.el9.aarch64.rpm
pg_kv_15 0.1.0 el10.x86_64 pigsty 246.1 KiB pg_kv_15-0.1.0-1PGSTY.el10.x86_64.rpm
pg_kv_15 0.1.0 el10.aarch64 pigsty 229.8 KiB pg_kv_15-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-kv 0.1.0 d12.x86_64 pigsty 209.3 KiB postgresql-15-pg-kv_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-kv 0.1.0 d12.aarch64 pigsty 181.3 KiB postgresql-15-pg-kv_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-kv 0.1.0 d13.x86_64 pigsty 209.4 KiB postgresql-15-pg-kv_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-15-pg-kv 0.1.0 d13.aarch64 pigsty 181.3 KiB postgresql-15-pg-kv_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-15-pg-kv 0.1.0 u22.x86_64 pigsty 224.7 KiB postgresql-15-pg-kv_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-15-pg-kv 0.1.0 u22.aarch64 pigsty 208.1 KiB postgresql-15-pg-kv_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-15-pg-kv 0.1.0 u24.x86_64 pigsty 223.3 KiB postgresql-15-pg-kv_0.1.0-1PGSTY~noble_amd64.deb
postgresql-15-pg-kv 0.1.0 u24.aarch64 pigsty 206.4 KiB postgresql-15-pg-kv_0.1.0-1PGSTY~noble_arm64.deb
postgresql-15-pg-kv 0.1.0 u26.x86_64 pigsty 223.0 KiB postgresql-15-pg-kv_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-15-pg-kv 0.1.0 u26.aarch64 pigsty 205.7 KiB postgresql-15-pg-kv_0.1.0-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_kv;		# 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_kv;		# install via package name, for the active PG version

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

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_kv';

Create this extension with:

CREATE EXTENSION pg_kv;

Usage

Sources:

pg_kv 0.1.0 provides a shared-memory cache, counters, token-bucket rate limiting and sorted sets. This early release targets PostgreSQL 15–18 and is not production ready.

Core Workflow

Add the library to the existing preload list and restart PostgreSQL before installing the extension as a superuser:

shared_preload_libraries = 'pg_kv'
CREATE EXTENSION pg_kv;
SELECT kv.set('app:session:42', '{"user":1}', interval '30 minutes');
SELECT kv.get('app:session:42');
SELECT kv.ttl('app:session:42');
SELECT kv.incr('app:views:7');
SELECT kv.rate_limit('app:api:42', 100, interval '1 minute');
SELECT kv.zadd('app:leaderboard', 'player:9', 1520);
SELECT * FROM kv.zrange('app:leaderboard', 0, 9, reverse => true);
SELECT * FROM kv.stats();

Installation fails if the library was not preloaded. Grant schema kv usage only to intended callers. The keyspace is shared across every database in the cluster; prefixes organize keys but do not enforce tenant isolation.

Operations and Capacity

kv.ttl returns milliseconds, -1 for a permanent key and -2 for a missing key. kv.expire changes expiry, kv.del removes a key, and kv.rate_limit_info reports allowance and retry timing. Sorted sets also support kv.zscore, kv.zrank, kv.zrevrank, kv.zincrby, kv.zcard and kv.zrem.

Restart settings include pg_kv.max_entries, pg_kv.max_key_bytes, pg_kv.max_value_bytes, pg_kv.shards, pg_kv.sweep_interval_ms, pg_kv.max_zset_members and pg_kv.max_member_bytes. Storage is bounded; oversize values fail, and pressure can evict cached keys. kv.flush is an administrative operation unavailable to the public role by default.

Durability Boundary

Cache changes survive transaction rollback but disappear on a server restart or crash. They are not WAL logged or replicated; a standby has its own cache. Use this for disposable state, not authoritative records or a globally coordinated limiter across independent servers.