Data & Analytics

Database

CloudNativePG PostgreSQL database.

Component:Database

Examples

01

Example 1

import { Database } from '@r8s/recipes'

export default <Database name="app-db" storage="10Gi" />
02

Example 2

import { Platform, Database, WebService } from '@r8s/recipes'

export default (
  <Platform secrets={{ backend: 'openbao' }}>
    <Database name="app-db" storage="10Gi">
      <WebService name="api" image="myapp/api:v1" />
    </Database>
  </Platform>
)
03

Example 3

import { Platform, Database, WebService } from '@r8s/recipes'

// HA database with continuous S3 backup — the backend provisions the
// backup credentials, pods restart when they rotate.
export default (
  <Platform secrets={{ backend: 'openbao', mount: 'kv', path: 'apps', refreshAfter: '3600s' }}>
    <Database
      name="app-db"
      storage="20Gi"
      instances={2}
      rolloutRestartTargets={[{ name: 'api' }]}
      backup={{
        destinationPath: 's3://backups/app-cnpg',
        endpointURL: 'https://s3.example.com',
      }}
    >
      <WebService name="api" image="myapp/api:v1" />
    </Database>
  </Platform>
)

Props

namestringRequired

Resource name (also the default database name)

namespacestringOptional

Kubernetes namespace (defaults to 'default')

instancesnumberOptional

Number of CNPG instances in the dedicated cluster (defaults to 3)

storagestringOptional

Storage size (e.g., '10Gi') for the dedicated cluster data volume

storageClassstringOptional

Storage class name for the data volume (defaults to cluster default)

parametersRecordOptional

PostgreSQL parameters, e.g. { max_connections: '200' }

backupDatabaseBackupPropsOptional

Continuous barman backup to S3 object storage + ScheduledBackup. Explicit opt-in.

rolloutRestartTargets{ kind?: string, name: string, apiVersion?: string }[]Optional

Workloads that consume the database credentials. Rendered as rolloutRestartTargets on the generated VaultStaticSecret/ OpenBaoStaticSecret so pods restart when credentials rotate.

operatorVersionstringOptional

Operator version override. If not set, reads from OperatorContext or uses default.

postInitSQLstring[]Optional

SQL statements run once after the initial database bootstrap (CNPG bootstrap.initdb.postInitApplicationSQL). Use for schema extensions the application requires on a fresh cluster — e.g. creating roles or extensions. Parameterized by the CNPG operator.

childrenunknownOptional

Child components rendered with this database's connection info in context