Skip to main content

PostgreSQL (postgresql)

Relational database of the platform services with the pgvector extension for embeddings. Single server, or high availability with Patroni: streaming replication, automatic failover and leader election in etcd. A PostgreSQL cluster of the bank can be connected instead.

Generated from catalog/services/postgresql.yaml: do not edit by hand.

Summary​

Version16.15
Useinstall and configure
Layerfunctional (AI catalog)
CategoryData platforms
Installation methodspodman, package, python
External connectionpostgresql
Sandbox onlyno

Licence​

SPDX identifierPostgreSQL
Licence policylicence exception
Licence exceptionLEX-001 (pending, awaiting the client)
Platform componentpostgresql

Packages and artifacts​

A package the project of the service publishes (its image, its binary archive, its Python or OS package) carries the licence of the service; a third-party package carries the licence written on its row, read from the official upstream metadata.

KindPackageVersionLicenceDetails
container imagedocker.io/pgvector/pgvector0.8.7-pg16-bookwormPostgreSQLimage key postgres, used by postgres, digest sha256:0dd3149a06e4579a0d70d8fef9945636cd514005e7237deb27f9b67886f8dc4f
Python packagepixeltable-pgserver0.7.1PostgreSQLinterpreters, in order of preference python3.11, python3.12, python3.10
Python packagepatroni[etcd3]4.1.5PostgreSQLinterpreters, in order of preference python3.11, python3.12, python3.10
Python packagepsycopg[binary]3.3.2PostgreSQLinterpreters, in order of preference python3.11, python3.12, python3.10
OS packagepostgresql16-serverversion of the configured repositoryPostgreSQLRHEL family (dnf)
OS packagepostgresql16version of the configured repositoryPostgreSQLRHEL family (dnf)
OS packagepostgresql16-contribversion of the configured repositoryPostgreSQLRHEL family (dnf)
OS packagepgvector_16version of the configured repositoryPostgreSQLRHEL family (dnf)
OS packagepatroniversion of the configured repositoryPostgreSQLRHEL family (dnf)
OS packagepatroni-etcdversion of the configured repositoryPostgreSQLRHEL family (dnf)
OS packagepostgresql-16version of the configured repositoryPostgreSQLDebian family (apt)
OS packagepostgresql-client-16version of the configured repositoryPostgreSQLDebian family (apt)
OS packagepostgresql-16-pgvectorversion of the configured repositoryPostgreSQLDebian family (apt)
OS packagepatroniversion of the configured repositoryPostgreSQLDebian family (apt)
OS packagepython3-etcdversion of the configured repositoryPostgreSQLDebian family (apt)

Images are pinned by tag in the descriptor, and by digest when the descriptor declares one (the offline bundle then refuses a pulled image that does not carry it); the digest is recorded in the mirror of the Manager when the offline bundle is imported, and every pull or load is checked against it.

Supported systems and architectures​

MethodOperating systemsArchitectures
podmanRHEL family (dnf), Debian family (apt), Arch Linux (pacman)x86_64, aarch64 (not restricted by the descriptor)
packageRHEL family (dnf), Debian family (apt)x86_64, aarch64 (not restricted by the descriptor)
pythonRHEL family (dnf), Debian family (apt), Arch Linux (pacman)x86_64, aarch64 (not restricted by the descriptor)

Certified host systems: RHEL 8/9/10, Rocky Linux 8/9/10, AlmaLinux 8/9/10, Oracle Linux 8/9, CentOS Stream 9/10, Ubuntu 22.04/24.04, Debian 12, Arch Linux (rolling). The host preflight accepts these systems (other releases of a known family give a warning, end of life releases are refused) and the x86_64 and aarch64 architectures.

Prerequisites​

Host​

  • at least 1024 MB of memory (blocking, memory).
  • at least 5120 MB free for /var/lib/navin (warning, disk).
  • a synchronized clock (warning, time_sync).

Network and ports​

ComponentPort namePortOpened in the host firewall
postgressql5432/tcpyes
postgresrestapi8008/tcp (mode ha)yes

Services and connections needed​

Details and resolution: see Dependencies.

Installation methods and modes​

MethodDefaultWhat the method uses
podmanyesthe container images of the descriptor, run by Podman under systemd
package-the OS packages of the descriptor, installed by the package manager of the host
python-a Python virtual environment holding the Python packages of the descriptor

Components​

ComponentKindInstallation methodsPorts
PostgreSQL server (postgres)masterpodman, package, python5432/tcp, 8008/tcp (mode ha)

Single server (standalone) (default)​

One PostgreSQL server, without replica.

What the mode deploys:

ComponentPlacement
postgresmin 1, max 1

High availability (Patroni) (ha)​

2 to 7 members (3 recommended) managed by Patroni: one leader, the other members are streaming replicas, automatic failover through etcd. Methods package and python.

What the mode deploys:

ComponentPlacement
postgresmin 2, max 7, recommended 3

Install this service​

The install wizard of the Navin Manager plans, validates and runs the installation; you need the services:install permission on the cluster.

  1. Open the wizard. In Clusters, choose the row action Install services of the target cluster. The wizard opens on its first step, Service.

  2. Choose the service. On the Service step, select PostgreSQL. The card shows the licence PostgreSQL and the dependencies the installation needs. Pick the Method among podman, package, python (default podman). To register an existing postgresql service of your organisation instead, turn on Use an existing external service.

  3. Choose the hosts and the mode. On the Hosts step, tick the hosts, then choose the Mode: standalone (default), ha. Each mode deploys the components listed in Installation methods and modes.

  4. Bind the dependencies. On the Bindings step, choose for each dependency (dcs) Install with the platform or Use an existing connection; an optional dependency can stay on No binding.

  5. Configure. On the Configure step, review the parameters (see Configuration parameters). Passwords left empty with a generated default are generated and sealed by the Manager.

  6. Review and install. On the Install step the Manager validates the plan and shows the installation order; when it says "The plan is valid. Ready to install.", choose Install. A highly available mode is installed only when its HA checks pass.

  7. Verify. The operation ends when the health checks of every instance pass (see Health checks); the service then shows as running in Services. Open the service and choose Run the smoke test in the Checks card: Creates a temporary table on the leader, writes then reads a row; with pgvector, a vector(3) column and a nearest neighbour query.

High availability​

Clusterreplicas (replication)
High availabilitynative (native)
Failoverorchestrated (orchestrated)
Replicationnative (native)
QuorumRaft (raft)
Discoveryregistry (registry)
Entry pointclient discovery (client-discovery)
Official documentationhttps://patroni.readthedocs.io/en/latest/ha_loop.html
Referenceshttps://www.postgresql.org/docs/16/warm-standby.html, https://patroni.readthedocs.io/en/latest/yaml_configuration.html, https://patroni.readthedocs.io/en/latest/rest_api.html, https://www.postgresql.org/docs/16/libpq-connect.html, https://github.com/pgvector/pgvector
Peer TLS parametertls_enabled
Peer authenticationReplication with the replicator role and pg_rewind with the postgres role (scram-sha-256), allowed only from the member hosts; with TLS, hostssl only, the replicas verify the certificate of the leader (verify-full) and Patroni presents its certificate to etcd and to the REST API of the other members.
Cluster status commandcluster_status

Prerequisites​

PrerequisiteMust be highly availableModesDescription
dcsyeshaetcd in mode cluster (3 or 5 members, Raft quorum): Patroni demotes the leader when etcd is unreachable, so a single etcd member would make it the single point of failure.

Topology per mode​

ModesHighest catalog levelDistributionQuorum componentFault domainsDescription
standalonestandalone (standalone)single (single)-1One PostgreSQL server, restored from its backups after a loss.
haha (ha)active-passive (active-passive)-3One read-write leader and 1 to 6 streaming replicas; Patroni promotes the most advanced healthy replica when the leader key expires in etcd, the old leader rejoins as a replica (pg_rewind).

Notes​

  • Mode ha: the consumers reach the leader through the libpq list of every member with target_session_attrs=read-write (PostgreSQL 14 or later clients). For clients that only take one address, put HAProxy in front of the members with an HTTP check GET /primary on the Patroni REST API port: only the leader answers 200.
  • Asynchronous replication by default: a failover may lose the last transactions not yet received by the promoted replica, bounded by maximum_lag_on_failover; synchronous_mode removes this loss.
  • The mode ha runs with the methods package and python; Patroni without a watchdog device relies on the leader key TTL in etcd.
  • The bootstrap settings (max_connections, WAL, ttl, loop_wait, retry_timeout, synchronous_mode) are written in etcd at the first start; a later change is applied with the command push_settings.
  • A PostgreSQL cluster of the bank that meets its high availability requirements can be connected instead (connection type postgresql).

Configuration parameters​

Network​

ParameterTypeDefaultAllowed valuesRequiredSecretRestartDescription
Port (port)port5432-nononoTCP port of the SQL server.
Patroni REST API port (restapi_port)port8008-nononoPort of the Patroni REST API of each member (health checks /liveness, /primary, /replica, cluster state, switchover). (ha)
Listen address (listen_address)string*-nononoAddresses the server and the Patroni REST API listen on. (advanced)

Tuning​

ParameterTypeDefaultAllowed valuesRequiredSecretRestartDescription
Maximum connections (max_connections)int200min 20, max 5000nonoyesMaximum number of client connections.
Shared buffers (shared_buffers_mb)int512min 64, MBnonoyesMemory of the shared buffer cache, about 25 percent of the host memory. (recommended clamp(round(host.memory_mb * 0.25), 128, 16384))
WAL kept for replicas (wal_keep_size_mb)int1024min 0, max 1048576, MBnononoWAL kept in pg_wal for the replicas and the backups (wal_keep_size).

Security​

ParameterTypeDefaultAllowed valuesRequiredSecretRestartDescription
Superuser password (superuser_password)passwordgenerated-noyesnoPassword of the postgres role, used by the provisioning commands, the backups and pg_rewind.
Replication password (replication_password)passwordgenerated-noyesnoPassword of the replicator role the replicas stream the WAL with. (ha)
REST API password (restapi_password)passwordgenerated-noyesnoBasic authentication password (user navin) of the unsafe endpoints of the Patroni REST API (switchover, restart, reinitialize). (ha)
TLS (tls_enabled)boolfalse-nononoServe SQL, replication and the Patroni REST API over TLS with the certificate of the manager CA and reject every connection without TLS (hostnossl reject). Methods podman and package only: the PostgreSQL of the python method is built without OpenSSL. Required in the mode ha when etcd uses TLS (client certificate).
Allowed network (allowed_cidr)string0.0.0.0/0-nononoCIDR allowed to connect with a password (scram-sha-256).

Extensions​

ParameterTypeDefaultAllowed valuesRequiredSecretRestartDescription
pgvector (pgvector)booltrue-nononoCreate the vector extension in template1 and in each consumer database at provisioning (vector type, HNSW and IVFFlat indexes).

High availability​

ParameterTypeDefaultAllowed valuesRequiredSecretRestartDescription
WAL limit of a slot (max_slot_wal_keep_size_mb)int10240min 1024, max 1048576, MBnononoMaximum WAL a replication slot of a stopped member retains (max_slot_wal_keep_size), so a lost replica never fills the disk of the leader; past it the member is reinitialized. (ha)
Synchronous replication (synchronous_mode)boolfalse-nononoPatroni synchronous_mode: a commit waits for one synchronous replica and only that replica may be promoted (no committed transaction lost on failover, higher commit latency). (ha)
Leader key TTL (ttl)int30min 10, max 300, snononoTime to live of the leader key in etcd: a leader that cannot renew it for this long is demoted and a replica is promoted. (advanced; ha)
Loop wait (loop_wait)int10min 1, max 60, snononoSeconds between two runs of the Patroni high availability loop. (advanced; ha)
Retry timeout (retry_timeout)int10min 1, max 120, snononoTimeout of the etcd and PostgreSQL operations retried by Patroni before a demotion. (advanced; ha)
Maximum lag on failover (maximum_lag_on_failover_mb)int1min 0, max 102400, MBnononoA replica further behind the leader than this is never promoted (maximum_lag_on_failover). (advanced; ha)

Dependencies​

For each active dependency the Manager takes the first of: the binding chosen in the wizard; a service of the same installation that provides it; a service already installed in the cluster; the only connection of the expected type. Otherwise an optional dependency stays unbound, and a required one is added to the installation in its default mode (the column below names the catalog service added).

BindingProvided byConnection typeEndpointOptionalWhen nothing is boundDescription
dcs (ha)etcd-clientnoetcd is added to the installationetcd cluster where Patroni keeps the leader key, the member list and the dynamic configuration (mode ha).

Endpoints​

EndpointSchemeComponentPortPathTLS parameterBinding parametersBinding secretsProvisioning command
sqlpostgresqlpostgres5432 (port)-tls_enableddatabase, username, sslmodepasswordprovision_consumer

Client configuration files​

Files rendered for the client configuration download:

  • postgresql.env (client.env.j2)

Commands​

CommandComponentTargetDescription
Provision a consumer database (provision_consumer)postgresfirst hostCreates or updates the role and the database of one consumer service on the leader, with the vector extension when pgvector is on (idempotent).
Enable an extension (enable_extension)postgresfirst hostCreates an extension in one database on the leader (idempotent). The python method only bundles vector.
List databases (list_databases)postgresfirst hostLists the databases and their owners.
Show activity (activity)postgresfirst hostShows the sessions of pg_stat_activity of the leader.
Cluster status (cluster_status)postgresfirst hostMode ha: members, role, state, timeline and lag (patronictl list). Single server: role and replication of the server.
Switchover (switchover)postgresfirst hostMode ha: moves the leader role to the member given, which must be a healthy streaming replica (patronictl switchover); the sessions of the old leader are cut. (asks for confirmation)
Reinitialize a member (reinit_member)postgresfirst hostMode ha: deletes the data directory of one replica and clones it again from the leader (patronictl reinit). Never the leader. (asks for confirmation)
Push the settings (push_settings)postgresfirst hostMode ha: writes max_connections, wal_keep_size, the slot WAL limit, synchronous_mode, ttl, loop_wait, retry_timeout and maximum_lag_on_failover into the dynamic configuration in etcd (patronictl edit-config), then restarts the members with a pending restart one by one. (asks for confirmation)

Command parameters​

CommandParameterTypeDefaultRequiredDescription
provision_consumerDatabase (database)string-yesDatabase of the consumer.
provision_consumerRole (username)string-yesLogin role of the consumer.
provision_consumerPassword (password)password-yesPassword of the role (derived per consumer).
enable_extensionDatabase (database)string-yesDatabase where the extension is created.
enable_extensionExtension (extension)enumvectoryesvector (pgvector) or a contrib extension of PostgreSQL 16.
switchoverNew leader (candidate)string-yesMember name of the new leader (host name, see cluster status).
reinit_memberMember (member)string-yesMember name of the replica (host name, see cluster status).

Health checks​

Liveness (per instance)​

ComponentCheckDetails
postgresTCP {{ host.ip or '127.0.0.1' }}:{{ config.port }}90 retries; interval 2 s; timeout 3 s

Readiness (service check)​

CheckDetails
{{ paths.etc }}/check.sh30 retries; interval 4 s; timeout 30 s

Smoke test​

Creates a temporary table on the leader, writes then reads a row; with pgvector, a vector(3) column and a nearest neighbour query. (postgres: write_read, nearest_neighbour)

Preflight checks​

CheckTypeMeaningSeverityComponents
memorymemory_mb {"min": 1024}at least 1024 MB of memoryblockingevery component
diskdisk_free_mb {"path": "/var/lib/navin", "min": 5120}at least 5120 MB free for /var/lib/navinwarningevery component
sql_port_freeport_free {"param": "port"}port 5432 free on the hostblockingevery component
time_synctime_sync {}a synchronized clockwarningevery component

Backup and restore​

Physical backup of the whole server taken on the leader (pg_basebackup, tar format, WAL streamed, SHA256 manifest); the verify step extracts it and runs pg_verifybackup. Restore: the data directory of the member of the backup is replaced; in the mode ha the cluster state in etcd is reset, that member restarts as the leader and every other member is cloned again from it when it starts.

Formatpg-basebackup
Componentpostgres
Files{{ backup.dir }}/base.tar.gz, {{ backup.dir }}/pg_wal.tar.gz, {{ backup.dir }}/backup_manifest
Restore testyes
Instances stopped for the restoreyes

Uninstall​

Paths removed when the data is purged: {{ paths.data }}, {{ paths.log }}.

Upstream documentation​