# Configuration

> Gateway flags and pg_redis settings with defaults.

---

LLMS index: [llms.txt](/llms.txt)

---

Configuration is split between command-line flags on the `pgredis` Go gateway executable (`cmd/pgredis/main.go`) and database-level settings managed by PostgreSQL and the `pg_redis` extension (`v0.1.0-rc1`, schema `0.54`, commit `11411411d72ab45456904cc602cefbb13b68ff25`).

## Gateway CLI flags {#flags}

{.wide}
| Flag | Default | Description |
| --- | --- | --- |
| `-listen` | `127.0.0.1:56379` | RESP listener address (Mimus assigns `6379` in standard deployments). |
| `-pg` | `postgres://127.0.0.1:55432/pgredis?sslmode=disable` | PostgreSQL connection URL without credentials. |
| `-auth-mode` | `native` | Authentication mode: `native` (PostgreSQL roles) or `redis-acl` (`redis._acl_user`). |
| `-acl-service-user` | `(empty)` | Bound PostgreSQL `LOGIN` role used when `-auth-mode redis-acl` is active. |
| `-acl-service-password-file` | `(empty)` | File containing the ACL service role password (one trailing newline stripped); falls back to `PGREDIS_ACL_SERVICE_PASSWORD`. |
| `-default-user` | `app` | PostgreSQL `LOGIN` role used for single-argument `AUTH <password>` in `native` mode. |
| `-client-default-resp` | `2` | Initial wire protocol for new connections and `RESET` (`2` or `3`). |
| `-max-clients` | `1024` | Maximum concurrent RESP client connections. |
| `-max-pools` | `8` | Maximum cached PostgreSQL identity connection pools. |
| `-pool-size` | `4` | Maximum PostgreSQL backend connections per identity pool (`1..2147483647`). |
| `-tls-cert` | `(empty)` | Server TLS certificate path (required when `-listen` is non-loopback). |
| `-tls-key` | `(empty)` | Server TLS private key path (required when `-listen` is non-loopback). |
| `-max-bulk-bytes` | `536870912` (`512 MiB`) | Maximum bytes for a single request bulk argument. |
| `-max-frame-bytes` | `1074790400` (`1 GiB + 1 MiB`) | Maximum sum of argument bytes in a single request frame. |
| `-max-reply-bytes` | `1074790400` (`1 GiB + 1 MiB`) | Maximum wire bytes for a complete reply, including `EXEC` child replies. |
| `-max-input-bytes` | `2147483648` (`2 GiB`) | Shared budget across connections for live input payloads and bookkeeping. |
| `-max-output-bytes` | `2147483648` (`2 GiB`) | Shared budget across connections for live replies, workspace, and bookkeeping. |
| `-max-pg-read-bytes` | `2147483648` (`2 GiB`) | Shared budget for PostgreSQL receive buffers and `DataRow` metadata. |
| `-max-pg-message-bytes` | `1073741822` (`1 GiB - 2 B`) | Maximum bytes in a single PostgreSQL wire message body. |
| `-frame-read-timeout` | `30s` | Deadline to finish reading a frame after its first byte arrives. |
| `-command-timeout` | `30s` | Per-command execution timeout against PostgreSQL. |
| `-write-timeout` | `10s` | Deadline for writing a reply frame to the client socket. |
| `-tls-handshake-timeout` | `5s` | Deadline for completing a client TLS handshake. |
| `-version` | `false` | Print `pgredis 0.1.0` and exit. |
{.wide .expand}

The `-pg` URL must never contain a password. In `native` mode, clients supply their PostgreSQL role credentials via `AUTH` or `HELLO ... AUTH`. In `redis-acl` mode, the gateway connects with `-acl-service-user` and verifies per-user hashes inside `redis._acl_user`.

## Connection pools and default protocol {#pools}

- **Identity-isolated pools:** The gateway isolates connection pools by database and authenticated principal (`-max-pools 8`, `-pool-size 4`). Active checkout references prevent pool eviction, and up to 4 additional short-lived connections are permitted for credential verification. Connections return to a pool only after transaction state and session state (`redis._pool_reset()`) are cleanly reset; any uncertain connection is closed immediately.
- **Default RESP version:** `-client-default-resp 3` starts new connections in RESP3 mode instead of RESP2. `HELLO 2` or `HELLO 3` switches the active connection protocol, `AUTH` preserves it, and `RESET` restores the gateway's `-client-default-resp` default.

## PostgreSQL extension GUCs {#extension}

Configure these PostgreSQL GUCs in `postgresql.conf` (or with `ALTER DATABASE ... SET` as a superuser):

{.wide}
| GUC | Default | Context | Description |
| --- | --- | --- | --- |
| `pg_redis.maintenance_database` | `'postgres'` | `postmaster` (`shared_preload_libraries`) | Target database where the background maintenance worker reclaims expired keys and leases. |
| `pg_redis.maintenance_role` | `'postgres'` | `postmaster` (`shared_preload_libraries`) | PostgreSQL role used by the background maintenance worker. |
| `pg_redis.object_heat_tracking` | `off` | `superuser` | When `on`, every key access updates LRU/LFU metadata in `redis._object_heat` so `OBJECT IDLETIME` and `OBJECT FREQ` report live values (causing plain reads to write WAL). |
| `pg_redis.list_layout_tracking` | `off` | `superuser` | When `on`, newly created Lists track exact Redis listpack/quicklist encoding transitions on every write. |
{.wide .expand}

## Redis `CONFIG GET` and `CONFIG SET` {#redis-config}

`pg_redis` persists selected Redis runtime settings inside PostgreSQL tables so they participate in SQL transactions, savepoints, and `pg_dump` backups:

{.wide}
| Parameter | Default | Backing table | Effect |
| --- | --- | --- | --- |
| `notify-keyspace-events` | `""` (disabled) | `redis._config` | Enables keyspace (`K`) and keyevent (`E`) Pub/Sub notifications. |
| `slowlog-log-slower-than` | `10000` (10 ms) | `redis._slowlog_config` | Microsecond threshold for recording entries in `redis._slowlog` (negative disables). |
| `slowlog-max-len` | `128` | `redis._slowlog_config` | Maximum retained slowlog entries. |
| `latency-tracking-info-percentiles` | `"50 99 99.9"` | `redis._slowlog_config` | Space-separated percentile list formatted in `INFO latencystats`. |
| `acllog-max-len` | `128` | `redis._acl_config` | Maximum entries retained in `redis._acl_log` for `ACL LOG`. |
| `requirepass` | `""` | `redis._acl_config` | Password for the Redis `default` ACL user (does not alter PostgreSQL `LOGIN` roles). |
| `acl-pubsub-default` | `"resetchannels"` | `redis._acl_config` | Default Pub/Sub channel policy (`resetchannels` or `allchannels`) for new ACL users and `RESET`. |
| `tracking-table-max-keys` | `1000000` | `redis._tracking_config` | Maximum tracked keys in `redis._tracking_key` before earlier entries are evicted and invalidated. |
| `client-output-buffer-limit` | `"normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"` | `redis._output_config` | Per-class `<hard> <soft> <seconds>` output buffer limits (`replica` is accepted as an alias for `slave`). |
| `hash-max-listpack-entries`, `hash-max-listpack-value`, `list-max-listpack-size`, `list-compress-depth`, `set-max-intset-entries`, `set-max-listpack-entries`, `set-max-listpack-value`, `zset-max-listpack-entries`, `zset-max-listpack-value`, `stream-node-max-bytes`, `stream-node-max-entries` | Redis 7.2.4 defaults | `redis._config` | Thresholds used for `OBJECT ENCODING` reporting and approximate `XTRIM` node boundaries. |
{.wide .expand}

## Client output buffer limits and route logs {#client-output}

- **`client-output-buffer-limit` accounting:** `normal` limits apply to ordinary, `MONITOR`, and tracking-only connections (`0 0 0` disabled by default); `pubsub` limits apply to subscribed connections (`32 MiB` hard, `8 MiB` soft for `60` seconds by default). Accounting sums retained Go reply bytes plus unread rows in `redis._pubsub_event` or the `MONITOR` ring. Exceeding a hard or sustained soft limit closes the connection without sending an extra error frame.
- **Server-side route failure log:** When a Pub/Sub or tracking route fails a capacity, message-count, single-message-size, or identity check, `pg_redis` writes a `pg_redis Pub/Sub route failure decision` message to the PostgreSQL server log containing the failure reason, database OID, XID, and tuple position, while omitting tokens, channel names, and payloads.

---

Backlinks:

- [Reference](/docs/redis/reference/)
- [Pub/Sub and keyspace events](/docs/redis/reference/pubsub/)
