Database¶
Database security¶
Connections to non loopback hosts must use sslmode=verify-full; the server refuses to
start otherwise. Schema changes run as versioned migrations under an advisory lock.
PostgreSQL for several instances¶
All instances connect to the primary. Requirements of LiMDM:
LISTEN/NOTIFYand session advisory locks: connect directly or through a pooler in session mode. PgBouncer transaction or statement pooling breaks both (the notification listener, leader election of background jobs, session settings of the index build), so it is not supported.- Connections: each instance opens up to
LIMDM_DB_MAX_CONNS(default 32) plus one for notifications and, at a schema change, one for the migration. Keep the sum over all instances belowmax_connections(default 100) minus what backups and monitoring use, for example 3 instances with 24 each for 100. Transactions never wait for a second connection of the same pool, so a small pool slows requests down but cannot lock up. For many instances put PgBouncer in session mode in front and sizedefault_pool_sizelike the sum above. - Writes only: standbys cannot serve LiMDM (no read routing).
- After a failover, connections break: instances reconnect (pool, notification listener), background jobs restart under new locks, running remote shells end.
Options:
| Option | Failover | Notes |
|---|---|---|
| Managed service with HA (Amazon RDS/Aurora Multi AZ, Google Cloud SQL HA, Azure Database for PostgreSQL flexible server with zone redundant HA) | automatic, 30 to 120 s, DNS name stays | simplest; use sslmode=verify-full with the provider's CA |
| Patroni with etcd/Consul, access through a virtual IP (vip-manager, keepalived) or HAProxy on the Patroni REST API | automatic, about 30 s | proven self hosted setup; synchronous mode for zero data loss |
Streaming replication with manual promotion (pg_ctl promote, repmgr) |
manual | small setups; document and practice the switch |
| libpq multi host URL | client side | postgres://limdm@db1,db2/limdm?sslmode=verify-full&target_session_attrs=read-write: instances find the primary themselves |
Use synchronous replication (synchronous_commit = on with synchronous_standby_names)
when the audit log must not lose committed entries on failover (RPO 0); asynchronous
replication can lose the last seconds.