Skip to main content
Version: 3.0.0-alpha (Diátaxis)

Concepts — PostgreSQL

Architecture

PostgreSQL on Hikube is a managed service based on the CloudNativePG operator. Each instance deployed via the Postgres resource creates a replicated cluster with automatic failover, streaming replication, and built-in backup.


Terminology

TermDescription
PostgresKubernetes resource (apps.cozystack.io/v1alpha1) representing a managed PostgreSQL cluster.
PrimaryMain instance that accepts reads and writes.
ReplicaRead-only instance, synchronized via streaming replication from the primary.
CloudNativePGKubernetes operator that manages the lifecycle of PostgreSQL clusters (deployment, failover, backup).
PITRPoint-In-Time Recovery — restoration to a specific point in time using continuous WAL archiving.
WALWrite-Ahead Log — PostgreSQL transaction log, the foundation of PITR and replication.
QuorumMinimum number of synchronous replicas required before confirming a write.
resourcesPresetPredefined resource profile (nano to 2xlarge) to simplify sizing.

Replication and high availability

CloudNativePG ensures high availability through:

  1. Streaming replication: replicas receive WAL in real time from the primary
  2. Automatic failover: if the primary goes down, a replica is automatically promoted
  3. Synchronous replication (optional): the primary waits for write confirmation from replicas before committing a transaction

The quorum field defines the number of synchronous replicas:

  • quorum: 0 (default) — asynchronous replication, best performance
  • quorum: 1 — at least 1 synchronous replica, protection against data loss
tip

For production, configure replicas: 3 and quorum: 1 for a good balance between performance and durability.


Backup and restore

PostgreSQL on Hikube supports two backup mechanisms:

Continuous backup (WAL archiving)

WAL files are continuously archived to an S3 bucket. This enables PITR (Point-In-Time Recovery) — restoring the database to any point in the past.

Scheduled backup

A cron schedule triggers full backups (base backup) at regular intervals. The retention policy (retentionPolicy) determines the retention duration.

ParameterDescription
backup.scheduleCron schedule (e.g., 0 2 * * *)
backup.retentionPolicyRetention duration (e.g., 30d)
backup.s3*S3 bucket credentials and endpoint

User and database management

Each PostgreSQL cluster allows declaring:

  • Users with password
  • Databases with owner
  • Roles: admin (read/write), readonly (read-only)

Credentials are stored in a Kubernetes Secret named <instance>-credentials.


Resource presets

PresetCPUMemory
nano250m128Mi
micro500m256Mi
small1512Mi
medium11Gi
large22Gi
xlarge44Gi
2xlarge88Gi
warning

If the resources field (explicit CPU/memory) is set, resourcesPreset is ignored. The two approaches are mutually exclusive.


Limits and quotas

ParameterValue
Max replicasDepending on tenant quota
Storage sizeVariable (size in Gi)
Connections per userConfigurable per database

Further reading