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.
