Skip to content

This is the multi-page printable view of this section.

Return to the regular view of this page

Operations

Install, build, secure, upgrade, back up and recover pgredis.

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

    Install pgredis and pg_redis from a Linux development archive, enable the extension, and verify the deployment.
  • Build from source

    Required compilers, headers, Makefile targets, and test suites for building pgredis and pg_redis from source.
  • Authentication and permissions

    Configure native PostgreSQL role authentication, Redis ACL mode, SQL capability grants, and TLS listeners.
  • Upgrade and recovery

    Run ALTER EXTENSION pg_redis UPDATE, configure the background maintenance worker, and back up or restore data.

1 - Install

Install the gateway and extension from a package, and what to check afterwards.

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:

ArchivePlatformSize (bytes)SHA-256
pgredis-0.1.0-pg18.6-debian13-amd64.tar.gzLinux x86_64, glibc 2.419,321,730d72fdcb4f40d429e5b650d0671105c923db7ceb4425b50f68d45eea0d61e2ba8
pgredis-0.1.0-pg18.6-debian13-arm64.tar.gzLinux aarch64, glibc 2.418,574,4194dcc546ef4c0562eb0b69500c0bbb43f664c3b955259ccde92900ef52e269cd7

Each archive contains these members at its top level:

  • bin/pgredis — the Redis wire gateway executable
  • lib/pg_redis.so — the PostgreSQL 18 C extension library (ABI 3)
  • share/extension/pg_redis.control and share/extension/pg_redis--*.sql — the base script (0.1) and upgrade scripts through 0.54
  • licenses/ — project, Redis and dependency licence files
  • install.py and manifest.json — the installer and the file list with SHA-256, size and mode of every member

Install files

  1. Verify the archive checksum

    Check the archive hash before unpacking:

    pgredis_archive=pgredis-0.1.0-pg18.6-debian13-amd64.tar.gz
    sha256sum "$pgredis_archive"
    mkdir pgredis-package
    tar -xzf "$pgredis_archive" -C pgredis-package
  2. Run the installer

    install.py checks that the host is Debian 13 on x86_64 or aarch64, that pg_config --version reports PostgreSQL 18.6, and that every member matches manifest.json. Then it installs the binary and extension files:

    sudo python3 -E pgredis-package/install.py \
      "$PWD/$pgredis_archive" \
      --pg-config /usr/lib/postgresql/18/bin/pg_config \
      --gateway-path /usr/local/bin/pgredis

    The installer copies pgredis into /usr/local/bin/pgredis, pg_redis.so into pg_config --pkglibdir, and the control and SQL files into pg_config --sharedir/extension.

  3. Create the extension in PostgreSQL

    Connect to the target PostgreSQL 18 database as a superuser and create the extension:

    CREATE EXTENSION pg_redis;
    SELECT extversion FROM pg_extension WHERE extname = 'pg_redis';
    SELECT redis._abi_version();

    Confirm that extversion returns 0.54 and redis._abi_version() returns 3.

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):

/usr/local/bin/pgredis \
  -listen 127.0.0.1:6379 \
  -default-user pgredis_app \
  -pg "postgres://127.0.0.1:5432/postgres?sslmode=disable"

Run a post-installation check across both the Redis port and SQL:

redis-cli -h 127.0.0.1 -p 6379 --user pgredis_app --askpass PING
redis-cli -h 127.0.0.1 -p 6379 --user pgredis_app --askpass SET install:check ready
redis-cli -h 127.0.0.1 -p 6379 --user pgredis_app --askpass GET install:check
psql -h 127.0.0.1 -p 5432 -U postgres -d postgres \
  -c "SELECT convert_from(redis.command(ARRAY['GET', 'install:check']), 'UTF8');"

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

Toolchain, build targets and test targets.

Building pgredis from source compiles both the pg_redis PostgreSQL C extension and the pgredis Go gateway executable.

Toolchain

  • PostgreSQL 18 Server binaries (initdb, pg_ctl, postgres, psql), pg_config, and server development headers (postgresql-server-dev-18 on Debian/Ubuntu).
  • Go 1.27.4 Required to build the gateway and test harnesses. CGO_ENABLED=1 is mandatory because the gateway uses libc host resolution for MIGRATE.
  • C11 compiler clang or gcc compatible with the PostgreSQL PGXS build flags reported by pg_config.
  • Python 3 Used by scripts/prepare_pgx.py (which applies the local read-budget patch to the vendored pgx cache) 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:

make build
make -C extension PG_CONFIG=/path/to/pg_config
sudo make -C extension PG_CONFIG=/path/to/pg_config install

What each step produces:

  • make build runs python3 scripts/prepare_pgx.py, verifies CGO_ENABLED=1, executes go generate ./internal/gateway (which generates the command dispatch table from spec/commands.json), and writes the gateway binary to build/pgredis.
  • make -C extension compiles extension/pg_redis.c into extension/pg_redis.so against the target PostgreSQL 18 headers.
  • make -C extension install copies pg_redis.so, pg_redis.control, and pg_redis--*.sql (0.1 through 0.54) into the PostgreSQL installation directories reported by PG_CONFIG.

Test targets

TargetCommandScope
make testgo 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-integrationPGREDIS_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-referencepython3 tests/reference/prepare.py && python3 tests/reference/run.py --mode external --variant prdBuilds 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

PostgreSQL-role authentication, Redis ACL mode, TLS and the grants each role needs.

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:

ModeFlagClient AUTH syntaxIdentity 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-aclAUTH <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, EXEC with writes)
  • redis._admin() — required for administrative commands (FLUSHDB, FLUSHALL, CONFIG, SLOWLOG, ACL, DEBUG, MONITOR, MIGRATE)
-- Read/write application role (no admin commands)
CREATE ROLE app_rw LOGIN PASSWORD 'replace-with-strong-password';
GRANT USAGE ON SCHEMA redis TO app_rw;
GRANT EXECUTE ON FUNCTION
  redis._authorize(), redis._abi_version(), redis._read(), redis._write(),
  redis._dispatch(bytea[], integer),
  redis._dispatch(bytea[], integer, integer),
  redis._dispatch_single(bytea[], integer, integer),
  redis._pool_reset(),
  redis.command(text[], integer),
  redis.command_bin(bytea[], integer),
  redis.blocking_begin(bytea[], bytea, integer),
  redis.blocking_begin(bytea[], bytea, integer, integer),
  redis.blocking_poll(bytea, integer),
  redis.blocking_cancel(bytea, integer),
  redis.pubsub_open(bytea, integer),
  redis.pubsub_change(bytea, bytea[]),
  redis.pubsub_poll(bytea),
  redis.pubsub_cancel(bytea)
TO app_rw;

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.

  1. Create and bind the PostgreSQL service role

    Create a login role with read, write, and admin dispatch grants, then bind its regrole identity in redis._acl_service as an extension administrator:

    CREATE ROLE redis_service LOGIN PASSWORD 'replace-with-service-password';
    GRANT USAGE ON SCHEMA redis TO redis_service;
    GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA redis TO redis_service;
    
    SELECT redis._dispatch(ARRAY['ACLSERVICE', 'redis_service', 'ON']::bytea[], 0, 0);

    Once bound in redis._acl_service, redis_service cannot execute commands without an active redis._acl_session token.

  2. Configure ACL users and passwords

    Manage users over SQL or from an admin Redis connection:

    SELECT redis.command(ARRAY[
      'ACL', 'SETUSER', 'alice',
      'on', '>alice-secret',
      '~app:*', '&events:*',
      '+@read', '+@write', '-@admin'
    ]);

    Supported ACL subcommands include SETUSER, DELUSER, GETUSER, LIST, USERS, WHOAMI, CAT, GENPASS, DRYRUN, LOG, LOAD, and SAVE (LOAD and SAVE report that no external aclfile is configured because ACLs persist in PostgreSQL WAL).

  3. Start the gateway in redis-acl mode

    Do not place credentials in -pg; pass -acl-service-user and -acl-service-password-file (or PGREDIS_ACL_SERVICE_PASSWORD):

    pgredis \
      -listen 127.0.0.1:6379 \
      -auth-mode redis-acl \
      -acl-service-user redis_service \
      -acl-service-password-file /etc/pgredis/service.pass \
      -pg "postgres://127.0.0.1:5432/postgres?sslmode=disable"

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-cert and -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 -pg endpoint URL. When PostgreSQL runs on a separate host, configure sslmode=verify-full in the -pg connection string.
  • Tenant isolation: All 16 logical Redis databases (SELECT 0 through SELECT 15) share the same redis._keyspace table, Pub/Sub event queue, and MONITOR ring within one PostgreSQL database. Isolate untrusted tenants in separate PostgreSQL databases with separate pgredis gateway instances.

4 - Upgrade and recovery

Extension upgrades, backups and recovery with PostgreSQL tools.

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):

  1. Install the updated binary and extension files

    Install the matching pgredis gateway binary, pg_redis.so library, pg_redis.control, and pg_redis--*.sql files on the PostgreSQL host. Stop the PostgreSQL instance before replacing a loaded pg_redis.so file, then start PostgreSQL and the new gateway.

  2. Run the catalog update in PostgreSQL

    Connect to each database where pg_redis is installed and update the extension as its administrator:

    ALTER EXTENSION pg_redis UPDATE TO '0.54';
    SELECT extversion FROM pg_extension WHERE extname = 'pg_redis';
    SELECT redis._abi_version();

    Verify that extversion is 0.54 and redis._abi_version() returns 3.

  3. 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 in pg_roles so its legacy role_oid and role_name disagree, the migration raises SQLSTATE 55000 (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_ready trigger): The migration verifies the SHA-256 hash of redis._stream_group_ready() before adding a WHEN (OLD.kind='x') filter, raising 55000 if 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:

shared_preload_libraries = 'pg_redis'
pg_redis.maintenance_database = 'postgres'
pg_redis.maintenance_role = 'postgres'

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 migrating redis._acl_service bindings across clusters.

What a logical dump includes and excludes:

CategoryTablesLogical dump behavior
Keyspace and values_keyspace, _string, _hash, _list, _set, _zset, _stream_*, _hll, _bitmapRestored in full; expires_at retains its absolute timestamptz deadline.
Extension configuration_acl_user, _acl_config, _acl_service, _slowlog_config, _tracking_config, _output_configRegistered via pg_extension_config_dump and restored across clusters.
Derived caches_list_lengthExcluded 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_clientExcluded from dumps; reconnecting clients establish fresh sessions.

Failure handling and timeouts

  • Command and statement timeouts: Set -command-timeout on the gateway and statement_timeout / lock_timeout on the PostgreSQL role to bound worst-case query duration.
  • Inspecting active backends: Query pg_stat_activity for queries executing redis._dispatch or redis.command when diagnosing lock waits or slow commands.
  • Handling UNKNOWN write 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.