Skip to content

Storage

The tables behind each Redis data type and how keys, expiry and streams are stored.

All durable Redis state lives in ordinary WAL-logged PostgreSQL tables inside schema redis. The Go gateway holds no persistent data of its own.

Keyspace and binary identity

Every Redis key has one row in redis._keyspace:

CREATE TABLE redis._keyspace (
    id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    db integer NOT NULL CHECK (db BETWEEN 0 AND 15),
    digest bytea NOT NULL CHECK (octet_length(digest) = 32),
    key bytea NOT NULL,
    kind "char" NOT NULL DEFAULT 's',
    value bytea,
    expires bigint
) WITH (fillfactor = 85, autovacuum_vacuum_scale_factor = 0.02);

CREATE INDEX ON redis._keyspace (db, digest);
CREATE INDEX ON redis._keyspace (expires) WHERE expires IS NOT NULL;
  • Digest-indexed lookup: Unbounded binary keys (bytea, up to 512 MiB) never enter a PostgreSQL B-tree index directly. Instead, pg_redis indexes (db, digest) using a 32-byte SHA-256 digest, locks the digest bucket, and compares the full key bytes to resolve hash collisions safely.
  • Collection child rows: Hash fields (redis._hash), Set members (redis._set), ZSet members (redis._zset), Stream groups (redis._stream_group) and Stream consumers (redis._stream_consumer) use the same 32-byte digest + full bytea comparison rule, referencing redis._keyspace(id) with ON DELETE CASCADE.
  • Sorted sets: redis._zset stores score double precision (rejecting NaN) and breaks ties by comparing full member bytes.
  • Lists and length cache: redis._list orders elements by (kid, pos, id) without putting element value bytes in a B-tree. Schema 0.54 adds redis._list_length(kid, length), maintained by statement-level transition-table triggers on redis._list so LLEN, LPUSH and RPUSH read one row instead of counting every element.

Table inventory (schema 0.54)

CategoryTablesPurpose
Keyspace and Stringsredis._keyspaceLogical DB (0–15), 32-byte digest, binary key, type tag (s, h, l, S, z, x), inline payload (value for Strings, Bitmaps, HLL) and millisecond deadline (expires)
Hashesredis._hash(kid, digest, field, value) rows per hash field
Listsredis._list, redis._list_length(kid, pos, value) element rows and statement-trigger-maintained per-list length cache
Setsredis._set(kid, digest, member) rows per set member
Sorted sets ( and Geo)redis._zset(kid, digest, member, score) rows; Geo keys store 52-bit geohash integers as ZSet scores
Streamsredis._stream, redis._stream_entry, redis._stream_node, redis._stream_radix, redis._stream_group, redis._stream_consumer, redis._stream_pel, redis._stream_configStream metadata (last_id, max_deleted_id, entries_added), live entries, listpack nodes, radix tree prefixes, consumer groups, consumers and Pending Entries List (PEL)
Object metadataredis._object_encoding, redis._object_heat, redis._object_shared_heat, redis._object_reference, redis._object_configEncoding state, optional listpack/quicklist layout (pg_redis.list_layout_tracking), optional LRU/LFU heat (pg_redis.object_heat_tracking) and shared-integer tracking
Transactionsredis._transaction_session, redis._watch, redis._exec_context, redis._mutation_statsWATCH key versions, EXEC context and per-key mutation counters
Blocking commandsredis._blocked, redis._block_keys, redis._readyBlocked waiter registrations, watched keys per waiter and committed handoff replies
Pub/Subredis._pubsub_session, redis._pubsub_subscription, redis._pubsub_message, redis._notify_configSubscriber sessions, channel/pattern/shard bindings, message ring pages and keyspace-event configuration
Client trackingredis._tracking_client, redis._tracking_key, redis._tracking_prefix, redis._tracking_pending, redis._tracking_configClient-side caching sessions, tracked key digests, BCAST prefixes and queued invalidations
Auth and Redis ACLredis._acl_user, redis._acl_session, redis._acl_log, redis._acl_config, redis._acl_service, redis._auth_ticket, redis._auth_key_ticketRedis ACL users, rules, security log and session tickets
Diagnostics and controlredis._monitor_client, redis._client_pause_control, redis._debug_control, redis._output_config, redis._slowlog_config, redis._encoding_config, redis._hll_config, redis._runtime_identityMONITOR observers, CLIENT PAUSE deadlines, DEBUG PAUSE-CRON / SET-ACTIVE-EXPIRE state, output buffer limits, SLOWLOG settings and installation identity

Encoding history and Streams

redis._object_encoding stores per-key encoding metadata (int, embstr, raw, listpack, hashtable, intset, skiplist, stream), and COPY copies this representation state alongside the key. Deleting a key cascades to its child rows and encoding metadata; transaction and savepoint rollback restore both business values and encoding state.

Streams persist both live entries (redis._stream_entry) and physical listpack/radix structures (redis._stream_node, redis._stream_radix) so XTRIM approximate trimming and XINFO STREAM FULL reflect the recorded structure.

Runtime statistics versus durable rows

Keyspace modifications and dirty counters participate in PostgreSQL WAL transactions. Runtime command call counters (INFO commandstats, INFO stats) live in bounded shared memory partitioned by database OID and extension installation identity:

  • Rolling back a SQL transaction undoes all table writes and queued notifications, while the in-memory call counter records that the command handler ran.
  • Blocking command completion counters update only after the transaction that fixes the blocking result commits; repeated blocking_poll calls do not increment completion counts again.
Scan to open this page
https://mimus.pgsty.com/docs/redis/architecture/storage/