Files
Olares/docs/developer/develop/mw-integrate-with-pg.md
Meow33 776848d2e2 docs: add application environment variables (#2577)
* docs: updated installation env vars and runtime values references

* docs: fix content

* docs: update content

* Update table of contents, and refactored docs.

* Fixed capitalization.

* batch update to fix readability

* refactored declarative env var

* Updated translation.

* Updated based on suggestions.

* Updated based on suggestions.

---------

Co-authored-by: yajing wang <413741312@qq.com>
2026-03-05 17:52:22 +08:00

2.8 KiB

outline, description
outline description
2
3
Learn how to integrate your app with the built-in PostgreSQL service in Olares.

Integrate with PostgreSQL

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

:::info 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.

:::info 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

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

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.

Value Type Description
.Values.postgres.host String PostgreSQL host.
.Values.postgres.port Number PostgreSQL port.
.Values.postgres.username String PostgreSQL username.
.Values.postgres.password String PostgreSQL password.
.Values.postgres.databases Map<String,String> Requested databases, keyed by database name. For example, a request for app_db is available at .Values.postgres.databases.app_db.