# Configuration

> Tenant configuration, listeners, pools and extension settings.

---

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

---

Start the tenant gateway with `pgetcd --tenant-config FILE` and `PGETCD_DSN`. The gateway reads the JSON file once at startup; restart the process to apply configuration changes.

## Tenant JSON file {#tenant}

The example below configures one tenant. Replace the persistent `cluster_id` and `member_id` placeholders with the decimal values returned by `diag.status` during [database setup](/docs/etcd/quickstart/#database), and set your certificate paths and listener addresses:

```json
{
  "tenant": "demo",
  "listen": "127.0.0.1:2379",
  "diagnostics_listen": "127.0.0.1:2381",
  "database": "pgetcd_demo",
  "role": "pgetcd_demo_gateway",
  "cluster_id": "1",
  "member_id": "1",
  "member_name": "demo-1",
  "public_urls": ["https://127.0.0.1:2379"],
  "tls": {
    "certificate": "/etc/pgetcd/server.crt",
    "private_key": "/etc/pgetcd/server.key",
    "client_ca": "/etc/pgetcd/client-ca.crt",
    "client_uri": "spiffe://pgetcd/tenant/demo",
    "server_name": ""
  },
  "pool_size": 32,
  "max_streams": 32,
  "max_rpc_connections": 64,
  "watch_max_tenant_bytes": 134217728,
  "watch_progress_notify_interval": "10m"
}
```

The tenant file must be a single JSON object of at most `65,536` bytes. Unknown fields, duplicate keys, and trailing JSON values are rejected.

| Field | Rule |
| --- | --- |
| `tenant` | `1`–`63` characters; starts with a lowercase ASCII letter, followed by lowercase letters, digits, or `-` |
| `listen`, `diagnostics_listen` | Two distinct explicit `IP:port` addresses (port `1`–`65535`); both are required with no built-in default |
| `database`, `role`, `member_name` | Required non-empty strings |
| `cluster_id`, `member_id` | Canonical decimal strings for non-zero `uint64` values; checked against `etcd.meta` at startup |
| `public_urls` | `1`–`16` distinct `https://` URLs; no credentials, query string, or fragment; path empty or `/` |
| `tls` | Server certificate, private key, client CA, exact tenant URI SAN, and optional SNI hostname |
{.wide}

Each gateway process binds its listener to the single configured `database` and `role`. Request keys or gRPC metadata cannot select another database. Because `cluster_id` and `member_id` identify persistent database state, never generate new random IDs on gateway restart.

## TLS and database connection {#tls}

- **Client to gateway**: The gateway requires TLS 1.2 or newer and a client certificate signed by `tls.client_ca` carrying the exact URI SAN `spiffe://pgetcd/tenant/<tenant>`. A valid certificate for a different tenant is rejected. Both the gRPC listener (`listen`) and the HTTP/1.1 diagnostics listener (`diagnostics_listen`) enforce the same client certificate check.
- **SNI and endpoint matching**: For a DNS endpoint, set `tls.server_name` to that exact hostname and use it in every entry of `public_urls`; clients must send matching SNI. For an IP endpoint, leave `tls.server_name` empty and use IP URLs in `public_urls`.
- **Gateway to PostgreSQL (`PGETCD_DSN`)**: `PGETCD_DSN` must connect to the exact `database` and `role` named in the tenant JSON. Every host entry in `PGETCD_DSN` must verify the server certificate chain and hostname (for example `sslmode=verify-full sslrootcert=/path/to/ca.crt`). Add `sslcert` and `sslkey` when PostgreSQL requires client certificate authentication. Any plaintext or unverified TLS fallback in `PGETCD_DSN` causes startup to fail closed.

## Capacity and timing {#capacity}

| Field | Default (when omitted or `0`) | Allowed range |
| --- | --- | --- |
| `pool_size` | `32` | `1`–`256` PostgreSQL connections / publication slots |
| `max_streams` | `32` | `1`–`1,024` active Watch streams |
| `max_rpc_connections` | `64` | `1`–`4,096` TCP connections, enforced before the TLS handshake |
| `watch_max_tenant_bytes` | `134,217,728` (128 MiB) | `68,681,728`–`1,073,741,824` bytes (with default stream limits) |
| `watch_progress_notify_interval` | `"10m"` | Duration string of at least `1ms` |
{.wide}

- **Publication slots (`pool_size`)**: Each active request holds one slot until its synchronous `COMMIT` resolves. Since `v0.1.0-rc2`, a request that finds every slot busy waits up to 5 s for one and receives `ResourceExhausted` only if still waiting; the readiness check uses a separate reserved slot. Set `pool_size` for the expected concurrency per gateway. In `v0.1.0-rc1` the readiness check shared these slots and requests were refused at once.
- **Watch byte budget (`watch_max_tenant_bytes`)**: The minimum budget reserves 32 MiB for reading `_tail_v2` batches, 32 MiB for per-stream buffers, and 1.5 MiB for request envelopes. It bounds serialized event data, not total Go process RSS.
- **HTTP/2 keepalive**: Fixed at a 5-second minimum ping interval with pings disallowed when no stream is open.

## PostgreSQL extension settings {#postgresql}

Load `pg_etcd` in `postgresql.conf` and list the tenant databases whose Lease background workers should be supervised:

```ini
shared_preload_libraries = 'pg_etcd'
pg_etcd.databases = 'pgetcd_demo'
synchronous_commit = on
```

| GUC or setting | Rule |
| --- | --- |
| `shared_preload_libraries` | Must include `pg_etcd` so the Lease worker launcher starts with the postmaster |
| `pg_etcd.databases` | Comma-separated list of `1`–`8` distinct database names (each `1`–`63` bytes; quoted GUC syntax preserves case) |
| `pg_etcd.database` | Single-database alias; mutually exclusive with `pg_etcd.databases` |
| `max_worker_processes` | Must leave enough background worker slots for the `pg_etcd` launcher plus 1 Lease worker per configured database |
| `synchronous_commit` | Must be `on` (`fsync = on`, `full_page_writes = on`) |
{.wide}

Changing `shared_preload_libraries`, `pg_etcd.databases`, or `pg_etcd.database` requires a PostgreSQL restart. Before running `CREATE EXTENSION pg_etcd`, create the `pgetcd_owner NOLOGIN NOSUPERUSER` role and grant the gateway login role only `USAGE ON SCHEMA etcd` and `EXECUTE` on the four public ABI functions (see [SQL ABI](/docs/etcd/reference/sql/#boundary)).

## Command-line flags {#entry}

| Flag | Purpose |
| --- | --- |
| `--tenant-config FILE` | Production/MVP mode: start the mTLS tenant gateway from `FILE` (requires `PGETCD_DSN`) |
| `--version` | Print the gateway version (`0.1.0`) and exit |
| `--p0-fixture` | Internal test mode: run the historical plaintext P0 loopback fixture (requires `PGETCD_DSN`) |
| `--listen ADDRESS` | Internal test flag: set the `--p0-fixture` loopback address (default `127.0.0.1:12379`; ignored in `--tenant-config` mode) |
| `--qualification-config FILE` | Internal test mode: run development Owner/watchdog diagnostics |
{.wide}

Exactly one of `--tenant-config`, `--p0-fixture`, or `--qualification-config` must be supplied when starting the server. Positional arguments are rejected.

---

Backlinks:

- [Compatibility](/docs/etcd/compatibility/)
- [Quick start](/docs/etcd/quickstart/)
- [Reference](/docs/etcd/reference/)
