This is the multi-page printable view of this section.
Operations
A pgredis deployment runs as two components alongside PostgreSQL 18: the pg_redis C extension inside the database server and the stateless pgredis Go gateway on the Redis wire port. Because all persistent state lives in PostgreSQL tables and write-ahead logs, day-two operations use standard PostgreSQL tooling for roles, upgrades, backups, and crash recovery.
Guides
Install
Installpgredisandpg_redisfrom a Linux development archive, enable the extension, and verify the deployment.Build from source
Required compilers, headers, Makefile targets, and test suites for buildingpgredisandpg_redisfrom source.Authentication and permissions
Configure native PostgreSQL role authentication, Redis ACL mode, SQL capability grants, and TLS listeners.Upgrade and recovery
RunALTER EXTENSION pg_redis UPDATE, configure the background maintenance worker, and back up or restore data.
1 - Install
pgredis is currently at release candidate v0.1.0-rc1 (product version 0.1.0, extension schema 0.54, ABI 3, commit 11411411d72ab45456904cc602cefbb13b68ff25, 2026-11-08). No public download URL or apt/rpm repository is published yet. Install either from a local Linux development archive built for PostgreSQL 18.6 or by building from source.
Candidate packages
The v0.1.0-rc1 development archives target Debian 13 (trixie) and PostgreSQL 18.6 from PGDG:
| Archive | Platform | Size (bytes) | SHA-256 |
|---|---|---|---|
pgredis-0.1.0-pg18.6-debian13-amd64.tar.gz | Linux x86_64, glibc 2.41 | 9,321,730 | d72fdcb4f40d429e5b650d0671105c923db7ceb4425b50f68d45eea0d61e2ba8 |
pgredis-0.1.0-pg18.6-debian13-arm64.tar.gz | Linux aarch64, glibc 2.41 | 8,574,419 | 4dcc546ef4c0562eb0b69500c0bbb43f664c3b955259ccde92900ef52e269cd7 |
Each archive contains these members at its top level:
bin/pgredis— the Redis wire gateway executablelib/pg_redis.so— the PostgreSQL 18 C extension library (ABI3)share/extension/pg_redis.controlandshare/extension/pg_redis--*.sql— the base script (0.1) and upgrade scripts through0.54licenses/— project, Redis and dependency licence filesinstall.pyandmanifest.json— the installer and the file list with SHA-256, size and mode of every member
Install files
Verify the archive checksum
Check the archive hash before unpacking:
Run the installer
install.pychecks that the host is Debian 13 onx86_64oraarch64, thatpg_config --versionreports PostgreSQL 18.6, and that every member matchesmanifest.json. Then it installs the binary and extension files:The installer copies
pgredisinto/usr/local/bin/pgredis,pg_redis.sointopg_config --pkglibdir, and the control and SQL files intopg_config --sharedir/extension.Create the extension in PostgreSQL
Connect to the target PostgreSQL 18 database as a superuser and create the extension:
Confirm that
extversionreturns0.54andredis._abi_version()returns3.
Start and verify
Start the gateway against the target database. Mimus assigns port 6379 to Redis (pgredis defaults to -listen 127.0.0.1:56379 and -pg postgres://127.0.0.1:55432/pgredis when flags are omitted):
Run a post-installation check across both the Redis port and SQL:
redis-cli returns ready and psql returns the RESP2 bulk string $5\r\nready\r\n. To configure least-privilege database roles or Redis ACL rules before exposing the listener to applications, see Authentication and permissions.
2 - Build from source
Building pgredis from source compiles both the pg_redis PostgreSQL C extension and the pgredis Go gateway executable.
Toolchain
PostgreSQL 18Server binaries (initdb,pg_ctl,postgres,psql),pg_config, and server development headers (postgresql-server-dev-18on Debian/Ubuntu).Go 1.27.4Required to build the gateway and test harnesses.CGO_ENABLED=1is mandatory because the gateway uses libc host resolution forMIGRATE.C11 compilerclangorgcccompatible with the PostgreSQL PGXS build flags reported bypg_config.Python 3Used byscripts/prepare_pgx.py(which applies the local read-budget patch to the vendoredpgxcache) and by the reference/application test runners.
The gateway and both Go test modules require Go 1.27.4. Current source uses pgx v5.12.0 with the project’s read-budget and password-preparation patch; the v0.1.0-rc1 packages use v5.11.0. The Go client tests use go-redis v9.23.0.
Build the gateway and extension
Run the gateway build from the repository root, then compile and install the C extension with PGXS:
What each step produces:
make buildrunspython3 scripts/prepare_pgx.py, verifiesCGO_ENABLED=1, executesgo generate ./internal/gateway(which generates the command dispatch table fromspec/commands.json), and writes the gateway binary tobuild/pgredis.make -C extensioncompilesextension/pg_redis.cintoextension/pg_redis.soagainst the target PostgreSQL 18 headers.make -C extension installcopiespg_redis.so,pg_redis.control, andpg_redis--*.sql(0.1through0.54) into the PostgreSQL installation directories reported byPG_CONFIG.
Test targets
| Target | Command | Scope |
|---|---|---|
make test | go test ./cmd/... ./internal/... ./tests/integration/... ./tests/load/... ./tests/probes/... | Fast Go unit tests (RESP parser/writer, command table generation, SQL error probes) without a running PostgreSQL cluster. |
make test-integration | PGREDIS_INTEGRATION=1 go test -count=1 -v ... | Initializes a temporary PostgreSQL 18 cluster, installs pg_redis, and runs end-to-end gateway, SQL rollback, Pub/Sub, Streams, Blocking, and Tracking tests. |
make test-reference | python3 tests/reference/prepare.py && python3 tests/reference/run.py --mode external --variant prd | Builds the pinned Redis 7.2.4 reference binary (5221b82623c) and runs the upstream Tcl test harness against pgredis (requires tclsh). |
Repository layout
- pgredis/
- cmd/pgredis/Gateway CLI entry point and flags
- internal/
- gateway/Session router, tx/watch state, blocking, Pub/Sub, MIGRATE
- resp/Binary-safe RESP2 and RESP3 parser and serializer
- extension/
- pg_redis.cC dispatcher, SPI plans, shared ring, background worker
- pg_redis.controlExtension metadata (default_version = '0.54')
- pg_redis--*.sqlBase schema (0.1) and upgrade scripts through 0.54
- patches/Local pgx v5.12.0 read-budget patch and earlier versions
- spec/commands.jsonRedis 7.2.4 command specification (392 commands)
- examples/outbox.sqlTransactional outbox SQL example
- tests/Integration, reference, client, application, and load suites
3 - Authentication and permissions
pgredis enforces permissions inside the pg_redis C dispatcher on every command. Even if a client bypasses the Go gateway and calls redis.command(...) directly over SQL, the C extension verifies the active PostgreSQL role capabilities or Redis ACL session before touching redis._keyspace or any typed value table.
Authentication modes
The gateway -auth-mode flag selects how Redis clients authenticate:
| Mode | Flag | Client AUTH syntax | Identity enforced by pg_redis |
|---|---|---|---|
| PostgreSQL role mode | -auth-mode native (default) | AUTH <pg_role> <password> or AUTH <password> (uses -default-user) | PostgreSQL login role and SQL EXECUTE grants on capability functions |
| Redis ACL mode | -auth-mode redis-acl | AUTH <acl_user> <password> or AUTH <password> (for default) | Redis ACL user row in redis._acl_user accessed via a bound PostgreSQL service role |
Before authentication succeeds on a connection that requires AUTH, the gateway restricts incoming command headers to at most 10 arguments and 16,384 bytes per bulk argument so unauthenticated callers cannot allocate large buffers.
PostgreSQL role permissions
In native mode, CREATE EXTENSION pg_redis revokes public access from all internal redis._* tables and functions. Database administrators grant access by granting USAGE ON SCHEMA redis, EXECUTE on entry functions, and EXECUTE on three empty capability marker functions checked by the C dispatcher:
redis._read()— required for read-only commands (GET,HGETALL,LRANGE,XRANGE,SUBSCRIBE,WAIT)redis._write()— required for data-modifying commands (SET,DEL,LPUSH,XADD,PUBLISH,EXECwith writes)redis._admin()— required for administrative commands (FLUSHDB,FLUSHALL,CONFIG,SLOWLOG,ACL,DEBUG,MONITOR,MIGRATE)
For a read-only role, omit redis._write() from the GRANT EXECUTE list. For an operational administrator role, add redis._admin().
Redis ACL mode
When -auth-mode redis-acl is enabled, the gateway connects to PostgreSQL using a single dedicated service role, and client sessions authenticate against rules stored in redis._acl_user.
Create and bind the PostgreSQL service role
Create a login role with read, write, and admin dispatch grants, then bind its
regroleidentity inredis._acl_serviceas an extension administrator:Once bound in
redis._acl_service,redis_servicecannot execute commands without an activeredis._acl_sessiontoken.Configure ACL users and passwords
Manage users over SQL or from an admin Redis connection:
Supported
ACLsubcommands includeSETUSER,DELUSER,GETUSER,LIST,USERS,WHOAMI,CAT,GENPASS,DRYRUN,LOG,LOAD, andSAVE(LOADandSAVEreport that no externalaclfileis configured because ACLs persist in PostgreSQL WAL).Start the gateway in
redis-aclmodeDo not place credentials in
-pg; pass-acl-service-userand-acl-service-password-file(orPGREDIS_ACL_SERVICE_PASSWORD):
CONFIG SET requirepass updates the password of the default ACL user in redis._acl_config (never a PostgreSQL LOGIN role). CONFIG SET acl-pubsub-default controls the default Pub/Sub channel policy (resetchannels by default, or allchannels) for newly created ACL users and RESET. redis._acl_user, redis._acl_config, and redis._acl_service are registered with pg_extension_config_dump, so pg_dump and pg_restore preserve ACL users and service role bindings across clusters.
Transport and tenant isolation
- Remote TLS enforcement: Listening on any non-loopback address (
0.0.0.0,::, or a LAN IP) requires-tls-certand-tls-key(minimum TLS 1.2). Starting without TLS on a non-loopback address fails immediately. - Database link security: Never embed a password in the
-pgendpoint URL. When PostgreSQL runs on a separate host, configuresslmode=verify-fullin the-pgconnection string. - Tenant isolation: All 16 logical Redis databases (
SELECT 0throughSELECT 15) share the sameredis._keyspacetable, Pub/Sub event queue, andMONITORring within one PostgreSQL database. Isolate untrusted tenants in separate PostgreSQL databases with separatepgredisgateway instances.
4 - Upgrade and recovery
pgredis stores its catalog schema and durable data inside PostgreSQL 18. Extension upgrades use ALTER EXTENSION, background cleanup runs inside a PostgreSQL background worker, and backup and recovery use standard PostgreSQL physical or logical tools.
Extension upgrades
The extension ships sequential SQL migration scripts from 0.1 through 0.54 (extension/pg_redis--*.sql). To upgrade an existing database to the current 0.54 schema (ABI 3):
Install the updated binary and extension files
Install the matching
pgredisgateway binary,pg_redis.solibrary,pg_redis.control, andpg_redis--*.sqlfiles on the PostgreSQL host. Stop the PostgreSQL instance before replacing a loadedpg_redis.sofile, then start PostgreSQL and the new gateway.Run the catalog update in PostgreSQL
Connect to each database where
pg_redisis installed and update the extension as its administrator:Verify that
extversionis0.54andredis._abi_version()returns3.Reconcile prerequisite checks if upgrading from older schemas
Two migration steps refuse to overwrite ambiguous state automatically:
0.49 → 0.50(redis._acl_service): If a bound ACL service role was dropped or renamed inpg_rolesso its legacyrole_oidandrole_namedisagree, the migration raises SQLSTATE55000(ACL service bindings require explicit reconciliation before update to 0.50). Reconcile or unbind the stale entry before retrying.0.50 → 0.51(stream_group_readytrigger): The migration verifies the SHA-256 hash ofredis._stream_group_ready()before adding aWHEN (OLD.kind='x')filter, raising55000if the trigger or function was manually customized.
Background maintenance worker
While read paths filter out expired keys immediately (expires_at <= clock_timestamp()), background reclamation of expired keys and stale session leases runs in the pg_redis background worker. Enable it in postgresql.conf:
Restart PostgreSQL after changing shared_preload_libraries. The worker periodically deletes expired rows from redis._keyspace, reclaims expired leases in _pubsub_session, _blocked, _transaction_session, and _acl_session, and compacts tracking and mutation-counter tables. DEBUG SET-ACTIVE-EXPIRE 0 and DEBUG PAUSE-CRON 1 pause periodic maintenance in the current database for deterministic testing; a new postmaster epoch resets both controls automatically.
Backup and recovery
- Physical backup and PITR:
pg_basebackup, WAL archiving, and point-in-time recovery preserve all keyspace tables, typed value tables, Streams metadata, and extension configuration tables together with ordinary SQL tables. - Logical backup (
pg_dump/pg_restore): Use custom format (pg_dump -Fc) or plain SQL dumps. Keep PostgreSQL role DDL quiescent during dump and restore when migratingredis._acl_servicebindings across clusters.
What a logical dump includes and excludes:
| Category | Tables | Logical dump behavior |
|---|---|---|
| Keyspace and values | _keyspace, _string, _hash, _list, _set, _zset, _stream_*, _hll, _bitmap | Restored in full; expires_at retains its absolute timestamptz deadline. |
| Extension configuration | _acl_user, _acl_config, _acl_service, _slowlog_config, _tracking_config, _output_config | Registered via pg_extension_config_dump and restored across clusters. |
| Derived caches | _list_length | Excluded from dumps; statement triggers on redis._list rebuild it automatically as rows are copied back during pg_restore. |
| Transient session state | _pubsub_session, _pubsub_event, _blocked, _transaction_session, _watch, _acl_session, _tracking_*, _monitor_client | Excluded from dumps; reconnecting clients establish fresh sessions. |
Failure handling and timeouts
- Command and statement timeouts: Set
-command-timeouton the gateway andstatement_timeout/lock_timeouton the PostgreSQL role to bound worst-case query duration. - Inspecting active backends: Query
pg_stat_activityfor queries executingredis._dispatchorredis.commandwhen diagnosing lock waits or slow commands. - Handling
UNKNOWNwrite outcomes: If a network drop or gateway timeout interrupts a write after the SQL statement was sent to PostgreSQL, the transaction may have either committed or rolled back. Non-idempotent callers should inspect the target key or application outbox table before retrying.