<@U04UQ68083H> does kratos support postgres?
# ory-copilot
r
@chilly-king-10285 does kratos support postgres?
c
A message from kapa.ai
Yes, Ory Kratos supports PostgreSQL as a database backend. In fact, PostgreSQL is recommended as the default database for production deployments of Ory Kratos. You can configure Kratos to use PostgreSQL by setting the DSN (Data Source Name) with the postgres:// prefix in your configuration. Example:
Copy code
dsn: <postgres://kratos:your-password@127.0.0.1:5432/kratos?sslmode=disable>
This is documented in the official deployment and production guides, which provide step-by-step instructions for setting up Kratos with PostgreSQL, including database creation and configuration details [Deploy to production](https://www.ory.sh/docs/kratos/guides/deploy-kratos-example#install-ory-kratos), [Self-hosted deployment](https://www.ory.sh/docs/self-hosted/deployment).
r
@chilly-king-10285 could you explain what kratos-sqlite volume does here? Do I need the value if I use postgres?
Copy code
version: '3.7'
services:
  kratos-migrate:
    image: oryd/kratos:v1.3.1
    environment:
      - DSN=sqlite:///var/lib/sqlite/db.sqlite?_fk=true&mode=rwc
    volumes:
      - type: volume
        source: kratos-sqlite
        target: /var/lib/sqlite
        read_only: false
      - type: bind
        source: ./contrib/quickstart/kratos/email-password
        target: /etc/config/kratos
    command: -c /etc/config/kratos/kratos.yml migrate sql -e --yes
    restart: on-failure
    networks:
      - intranet
  kratos-selfservice-ui-node:
    image: oryd/kratos-selfservice-ui-node:v1.3.1
    environment:
      - KRATOS_PUBLIC_URL=<http://kratos:4433/>
      - KRATOS_BROWSER_URL=<http://127.0.0.1:4433/>
      - COOKIE_SECRET=changeme
      - CSRF_COOKIE_NAME=ory_csrf_ui
      - CSRF_COOKIE_SECRET=changeme
    networks:
      - intranet
    restart: on-failure
  kratos:
    depends_on:
      - kratos-migrate
    image: oryd/kratos:v1.3.1
    ports:
      - '4433:4433' # public
      - '4434:4434' # admin
    restart: unless-stopped
    environment:
      - DSN=sqlite:///var/lib/sqlite/db.sqlite?_fk=true
      - LOG_LEVEL=trace
    command: serve -c /etc/config/kratos/kratos.yml --dev --watch-courier
    volumes:
      - type: volume
        source: kratos-sqlite
        target: /var/lib/sqlite
        read_only: false
      - type: bind
        source: ./contrib/quickstart/kratos/email-password
        target: /etc/config/kratos
    networks:
      - intranet
  mailslurper:
    image: oryd/mailslurper:latest-smtps
    ports:
      - '4436:4436'
      - '4437:4437'
    networks:
      - intranet
networks:
  intranet:
volumes:
  kratos-sqlite:
c
A message from kapa.ai
The
kratos-sqlite
volume in your Docker Compose file is used to persist the SQLite database file (
db.sqlite
) on disk, so that data is not lost when the container restarts. This is necessary when using SQLite, as the database file needs to be stored outside the container's ephemeral filesystem. If you switch to using PostgreSQL (or another supported production-grade database), you do not need the
kratos-sqlite
volume. Instead, you would configure the
DSN
environment variable to point to your PostgreSQL instance, and you can remove the
kratos-sqlite
volume from both the
volumes
section and the service definitions. The database persistence will then be managed by your PostgreSQL server, not by a local file in the container. This is consistent with Ory's documentation, which recommends using PostgreSQL for production and only using SQLite (and thus the volume) for development or quickstart scenarios [Ory Kratos Identity Server Quickstart](https://www.ory.sh/docs/kratos/quickstart#clone-ory-kratos-and-run-it-in-docker), [Self-hosted deployment](https://www.ory.sh/docs/self-hosted/deployment#sqlite).