Skip to content

Integrate with PostgreSQL ​

Use Olares PostgreSQL middleware by declaring it in OlaresManifest.yaml, then mapping the injected values to your container environment variables.

PosgreSQL installed

PostgreSQL service has been installed by default.

Configure OlaresManifest.yaml ​

In OlaresManifest.yaml, add the required middleware configuration.

  • Use the scripts field to specify scripts that should be executed after the database is created.
  • Use the extensions field to add the corresponding extension in the database.

Variable injection in scripts

The OS provides two variables, $databasename and $dbusername, which will be replaced by Olares Application Runtime when the command is executed.

Example

yaml
middleware:
  postgres:
    username: immich
    databases:
    - name: immich
      extensions:
      - vectors
      - earthdistance
      scripts:
      - BEGIN;                                           
      - ALTER DATABASE $databasename SET search_path TO "$user", public, vectors;
      - ALTER SCHEMA vectors OWNER TO $dbusername;
      - COMMIT;

Map to environment variables ​

In your deployment YAML, map the injected .Values.postgres.* fields to the container environment variables your app requires.

Example

yaml
containers:
  - name: my-app
    env:
      # The database name configured in OlaresManifest, specified in middleware.postgres.databases[i].name
      # NOTE: Replace <dbname> with the actual name defined in the Manifest (e.g., immich)
      - name: DB_POSTGRESDB_DATABASE
        value: {{ .Values.postgres.databases.<dbname> }}
      
      # Host
      - name: DB_POSTGRESDB_HOST
        value: {{ .Values.postgres.host }}
      
      # Port
      - name: DB_POSTGRESDB_PORT
        value: "{{ .Values.postgres.port }}"
      
      # Username
      - name: DB_POSTGRESDB_USER
        value: {{ .Values.postgres.username }}
      
      # Password
      - name: DB_POSTGRESDB_PASSWORD
        value: {{ .Values.postgres.password }}

PostgreSQL values reference ​

PostgreSQL values are predefined runtime values injected into values.yaml during deployment. They are system-managed and not user-editable.

ValueTypeDescription
.Values.postgres.hostStringPostgreSQL host.
.Values.postgres.portNumberPostgreSQL port.
.Values.postgres.usernameStringPostgreSQL username.
.Values.postgres.passwordStringPostgreSQL password.
.Values.postgres.databasesMap<String,String>Requested databases, keyed by database name. For example, a request for app_db is available at .Values.postgres.databases.app_db.