Requirements
What a deployment needs from PostgreSQL, its hosts, memory, clocks, network and process supervisor.
A deployment is only as safe as what it runs on. This page lists what the server relies on and what happens when it is missing.
PostgreSQL
Every byte a deployment keeps is in PostgreSQL, so PostgreSQL is where its durability comes from.
- Version 16 or later, with no extension: a managed PostgreSQL serves as well as one you run yourself. A process refuses to start on an older one (exit code 5).
- A database and a role that owns it, or may create a schema in it. The
role needs no superuser. At every start the process applies its schema
(
mimic) and checks the store's settings. - Settings that keep acknowledged writes. A process refuses to start
(exit code 5) when
fsyncis off,full_page_writesis off, orsynchronous_commitis off or anything buton,remote_apply,localandremote_write(localandremote_writeare refused too whensynchronous_standby_namesnames a standby). It warns while data checksums are off: turn them on. - A standby for failover, and point-in-time recovery. Both are PostgreSQL's (your provider's, or pgBackRest, WAL-G, …). With a synchronous standby no acknowledged write is lost when the primary fails; promoting an asynchronous one can lose what it had not received. See PostgreSQL stores.
- One role for every process. A process taking a partition over may
have to end a session that another process left holding it. PostgreSQL
allows that only to the session's own role, or to a role holding
pg_signal_backendandpg_read_all_stats. Otherwise the takeover waits for the session to end by itself, and the process logs the alertmimic_lease_takeover_blocked. - Session settings. Each transaction sets its own TCP keepalives (and,
on Linux,
tcp_user_timeout) and an idle-in-transaction timeout. A store that refuses any of these settings fails at start.
Connections
A serving process holds at most postgres.pool-size + 1 connections to each
store it is given: its pool (64 by default) and one connection of its own
that asks each second whether the store answers. mimicd serve --init-only
opens at most 4. An operator command opens a few to each store, and
mimicd archive export its --parallel and 2 more (up to 66).
Give PostgreSQL's max_connections, or the role's CONNECTION LIMIT, room
for every process's total, the operator commands you run beside them and
PostgreSQL's own reserve. Or put PgBouncer in transaction mode in front of
the store, which the server is designed for but which has not been tested
or measured yet (see PostgreSQL stores).
A small pool costs concurrency, never correctness: requests and background
work queue for its connections. 4 is the least a process takes.
Disk
The disk is PostgreSQL's. Size each store from the retained bytes of
the databases on it, not from document sizes: each document's current
checkpoint and the events after it, the outcomes of about 30 days of
transactions (about one per transaction), and history held back for
backups (while a backup destination is out of reach, up to 7 days or twice
backup_full_interval, whichever is longer), triggers
and sessions catching up. Add PostgreSQL's own overhead (indexes, row
headers, rows vacuum has not reclaimed yet) and its WAL.
The usage history samples each database's retained bytes every minute. A store that cannot write refuses the transactions that would: nothing is acknowledged that was not committed.
Memory and CPU
A process's memory is bounded by the Go runtime. Set GOMEMLIMIT a little
below the container's memory limit, and GOMAXPROCS to its CPU limit where
the runtime would see more CPUs than the container may use.
resident-memory bounds what resident documents and their buffers hold in
all: half of GOMEMLIMIT by default, or half of the host's memory without
one. Past four fifths of it, quiet documents leave memory first. The other
half is for everything else: sessions, connections, and the garbage
collector's headroom. CPU goes mostly to the document core's evaluation,
TLS and password hashing; add processes to add CPU. See
Maintenance.
Synchronized clocks
Safety never depends on clocks: who may write to a partition is decided by the store, not by time. Capability lifetimes, transaction ids' times, backups' cut times and ACME do use clocks. Run NTP on every host and every PostgreSQL server.
Network
- Clients reach the public listener (port
7700, or443when the process orders its own certificate), directly over TLS or through a proxy or load balancer that terminates it. - The operations listener (port
7702) serves health checks, status and metrics, unauthenticated. Keep it private. - When several processes serve a deployment, they forward requests to each other on the internal listener, mutual TLS only. Keep it on a private network.
- Every process reaches every store. Reach a store on another host over TLS
(
sslmode=verify-full).
See Network and TLS.
A supervisor that restarts processes
Run every process under a supervisor (Docker's restart policy, Kubernetes,
systemd) that restarts it after a failure (exit code 1), but not after exit
codes 2 and 5: those say the configuration is invalid or the store is
incompatible, which a restart does not change. Give a stopping process more
time than drain-timeout (20 seconds by default) before it is killed, so it
hands its partitions over: 30 seconds or more. See
Maintenance.
Migration sandboxes on Linux
Schema migrations run in sandbox processes under a system-call filter
(seccomp). A container's security profile must allow seccomp; where it
does not, migrations answer unavailable, unless the process runs with
--migrations.allow-unfiltered-sandbox, which is fit only where every
database's administrators are trusted with the whole deployment. See
Security.