Files
langflow/docs/docs/Configuration/configuration-custom-database.md
Mendon Kissling d790761ff0 docs: fix onBrokenAnchor behavior and links (#5520)
* fix: component url errors

* remove-unnecessary-nav-controls

* fix: update link-ids so onBrokenAnchors doesnt throw warnings

* delete unused category files

* delete unused sidebar_position

* space

* docs: format URLs in documentation for consistency

* fix: urls returning 404s

* backtick
2025-01-03 16:30:59 +00:00

2.6 KiB

title, slug
title slug
Configure an external PostgreSQL database /configuration-custom-database

Langflow's default database is SQLite, but you can configure Langflow to use PostgreSQL instead.

This guide will walk you through the process of setting up an external database for Langflow by replacing the default SQLite connection string sqlite:///./langflow.db with PostgreSQL.

Prerequisite

Connect Langflow to PostgreSQL

To connect Langflow to PostgreSQL, follow these steps.

  1. Find your PostgreSQL database's connection string. It looks like postgresql://user:password@host:port/dbname. For example, if you started PostgreSQL with this Docker command:
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres

Your connection string would be postgresql://some-postgres:mysecretpassword@localhost:5432/postgres.

  1. Create a .env file for configuring Langflow.
touch .env
  1. To set the database URL environment variable, add it to your .env file:
LANGFLOW_DATABASE_URL="postgresql://user:password@localhost:5432/dbname"

:::tip The Langflow project includes a .env.example file to help you get started. You can copy the contents of this file into your own .env file and replace the example values with your own preferred settings. Replace the value for LANGFLOW_DATABASE_URL with your PostgreSQL connection string. :::

  1. Run Langflow with the .env file:
langflow run --env-file .env
  1. In Langflow, create traffic by running a flow.
  2. Inspect your PostgreSQL deployment's tables and activity. You will see new tables and traffic created.

Example Langflow and PostgreSQL docker-compose.yml

The Langflow project includes a docker-compose.yml file for quick deployment with PostgreSQL.

This configuration launches Langflow and PostgreSQL containers, with Langflow pre-configured to use the PostgreSQL database. Customize the database credentials as needed.

To start the services, navigate to the /docker_example directory, and then run docker-compose up.

services:
  langflow:
    image: langflow-ai/langflow:latest
    environment:
      - LANGFLOW_DATABASE_URL=postgresql://user:password@postgres:5432/langflow
    depends_on:
      - postgres

  postgres:
    image: postgres:15
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=langflow