spat

spat

spat : Redis-like In-Memory DB Embedded in Postgres

Overview

ID Extension Package Version Category License Language
9400
spat
spat
0.1.0a4
SIM
AGPL-3.0
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
redis_fdw
redis
pgmemcache
mongo_fdw
kafka_fdw
documentdb
documentdb_core
documentdb_distributed

Alpha Stage!

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
0.1.0a4
18
17
16
15
14
spat -
RPM
PGDG
0.1.0a4
18
17
16
15
14
spat_$v -
DEB
PIGSTY
0.1.0a4
18
17
16
15
14
postgresql-$v-spat -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
MISS
PIGSTY 0.1.0
MISS
MISS
MISS
el8.aarch64
MISS
PIGSTY 0.1.0
MISS
MISS
MISS
el9.x86_64
MISS
PIGSTY 0.1.0
MISS
MISS
MISS
el9.aarch64
MISS
PIGSTY 0.1.0
MISS
MISS
MISS
el10.x86_64
MISS
MISS
MISS
MISS
MISS
el10.aarch64
MISS
MISS
MISS
MISS
MISS
d12.x86_64
MISS
PIGSTY 0.1.0
MISS
MISS
MISS
d12.aarch64
MISS
PIGSTY 0.1.0
MISS
MISS
MISS
d13.x86_64
MISS
MISS
MISS
MISS
MISS
d13.aarch64
MISS
MISS
MISS
MISS
MISS
u22.x86_64
MISS
PIGSTY 0.1.0
MISS
MISS
MISS
u22.aarch64
MISS
PIGSTY 0.1.0
MISS
MISS
MISS
u24.x86_64
MISS
PIGSTY 0.1.0
MISS
MISS
MISS
u24.aarch64
MISS
PIGSTY 0.1.0
MISS
MISS
MISS
Package Version OS ORG SIZE File URL
spat_17 0.1.0 el8.x86_64 pigsty 36.4 KiB spat_17-0.1.0a4-1PIGSTY.el8.x86_64.rpm
spat_17 0.1.0 el8.aarch64 pigsty 35.8 KiB spat_17-0.1.0a4-1PIGSTY.el8.aarch64.rpm
spat_17 0.1.0 el9.x86_64 pigsty 36.3 KiB spat_17-0.1.0a4-1PIGSTY.el9.x86_64.rpm
spat_17 0.1.0 el9.aarch64 pigsty 35.5 KiB spat_17-0.1.0a4-1PIGSTY.el9.aarch64.rpm
postgresql-17-spat 0.1.0 d12.x86_64 pigsty 46.3 KiB postgresql-17-spat_0.1.0a4-1PIGSTY~bookworm_amd64.deb
postgresql-17-spat 0.1.0 d12.aarch64 pigsty 45.6 KiB postgresql-17-spat_0.1.0a4-1PIGSTY~bookworm_arm64.deb
postgresql-17-spat 0.1.0 u22.x86_64 pigsty 51.3 KiB postgresql-17-spat_0.1.0a4-1PIGSTY~jammy_amd64.deb
postgresql-17-spat 0.1.0 u22.aarch64 pigsty 50.8 KiB postgresql-17-spat_0.1.0a4-1PIGSTY~jammy_arm64.deb
postgresql-17-spat 0.1.0 u24.x86_64 pigsty 47.7 KiB postgresql-17-spat_0.1.0a4-1PIGSTY~noble_amd64.deb
postgresql-17-spat 0.1.0 u24.aarch64 pigsty 47.2 KiB postgresql-17-spat_0.1.0a4-1PIGSTY~noble_arm64.deb

Source

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

pig install spat -v 17;   # install for PG 17

Create this extension with:

CREATE EXTENSION spat;

Usage

spat: Redis-like In-Memory DB Embedded in Postgres

An in-memory key-value data structure server embedded in PostgreSQL shared memory. Keys are strings; values can be strings, lists, sets, or hashes.

Enabling

CREATE EXTENSION spat;

Strings

SELECT SPSET('key', 'value');
SELECT SPGET('key');              -- 'value'

-- With TTL
SELECT SPSET('temp', 'data', ttl => interval '5 minutes');

-- Store any type as text
SELECT SPSET('config', '{"a": 1}'::jsonb);
SELECT SPGET('config')::text::jsonb;

Sets

SELECT SADD('myset', 'elem1');
SELECT SADD('myset', 'elem2');
SELECT SISMEMBER('myset', 'elem1');  -- true
SELECT SCARD('myset');               -- 2
SELECT SREM('myset', 'elem1');       -- 1

Lists

SELECT LPUSH('mylist', 'a');
SELECT LPUSH('mylist', 'b');
SELECT LPOP('mylist');     -- 'b' (LIFO)
SELECT LLEN('mylist');     -- 1

Hashes

SELECT HSET('myhash', 'field1', 'Hello');
SELECT HGET('myhash', 'field1');  -- 'Hello'

Generic Operations

SELECT SPTYPE('key');           -- 'string', 'list', 'set', or 'hash'
SELECT DEL('key');              -- true if removed
SELECT TTL('key');              -- returns TTL interval
SELECT GETEXPIREAT('key');      -- returns expiration timestamp
SELECT SP_DB_NITEMS();          -- number of entries
SELECT SP_DB_SIZE();            -- human-friendly size

Multiple Databases

SET spat.db = 'db1';             -- switch to database 'db1'
SET spat.db = 'spat-default';   -- switch back to default

Important Notes

  • Data is stored in PostgreSQL shared memory and is not durable – lost on restart
  • Operations are not transactional – ROLLBACK does not undo spat changes
  • Changes are immediately visible across all sessions (no MVCC isolation)
  • Per-key locks ensure concurrent write safety
Last updated on