跳转到主要内容
FIM One supports two database backends: SQLite (default, zero-config) and PostgreSQL (recommended for production). The backend is determined by the DATABASE_URL environment variable.
start.sh and the Docker entrypoint run the Alembic migrations on every start, so tables are created automatically — no manual migration step is required.

SQLite vs PostgreSQL

本地开发: SQLite 开箱即用 — 无需数据库服务器、无需 Redis、无需配置任何内容。直接开始编码。生产环境: 使用 Docker Compose 部署,PostgreSQL + Redis 会自动配置。无需手动设置数据库。

Known Limitation: SQLite Concurrent Streaming

SQLite can become a bottleneck under concurrent load.FIM One uses Server-Sent Events (SSE) for streaming AI responses. During streaming, each active SSE connection holds a database connection from the pool for the duration of the stream. SQLite enforces a global write lock, meaning only one write operation can proceed at a time — all other writes queue behind it.Even though the connection pool supports up to 15 simultaneous connections (pool_size=10 + max_overflow=5), the bottleneck is the lock itself, not the pool. When multiple users are chatting simultaneously, their write operations (saving messages, updating token counts) serialize against each other.Symptoms you may observe:
  • Conversation list loads slowly while another user is streaming
  • Settings pages feel sluggish during active chat sessions
  • API responses are delayed when multiple streams are active
Recommendation: If you have more than 2-3 concurrent users, switch to PostgreSQL. PostgreSQL uses MVCC (Multi-Version Concurrency Control) with row-level locking, so concurrent reads and writes proceed independently without blocking each other.

Connection Pool Configuration

FIM One configures SQLAlchemy connection pool settings internally for each backend. These are tuned defaults that do not require environment variables (the SQLite pool can be resized with SQLITE_POOL_SIZE / SQLITE_MAX_OVERFLOW) — they are applied automatically based on the DATABASE_URL scheme. Understanding them helps explain runtime behavior.

SQLite Pool Settings

WAL mode and the 30-second busy timeout are set via SQLite PRAGMAs on every new connection. This combination ensures that short-lived reads (loading a conversation list, fetching settings) are not blocked by long-running write transactions, and that concurrent writes queue gracefully instead of failing.

PostgreSQL 连接池设置

PostgreSQL 通过 MVCC 原生处理并发,因此连接池设置主要控制资源使用而非竞争。30 分钟的回收间隔可以避免防火墙、负载均衡器或托管数据库服务无声地丢弃空闲 TCP 连接的问题。

切换到 PostgreSQL

第 1 步:启动 PostgreSQL 实例

最快的方式是使用 Docker:

第 2 步:设置 DATABASE_URL

在你的 .env 文件中添加或更新以下行:

第 3 步:重启 FIM One

表会在首次启动时自动创建。无需手动进行架构迁移。
现有 SQLite 数据不会自动迁移。 将 DATABASE_URL 从 SQLite 切换到 PostgreSQL 会使用全新数据库启动。如果您在 SQLite 中有需要保留的现有对话、智能体或连接器,请参阅下面的数据迁移部分。
If you deploy with Docker Compose, PostgreSQL and Redis are already included and auto-configured — there is nothing extra to set up. The docker-compose.yml sets DATABASE_URL internally — your .env value is overridden:
No additional database setup is needed when using Docker Compose.

数据迁移

SQLite 到 PostgreSQL 没有内置的迁移工具。对于大多数部署,推荐的方法取决于您的情况: 全新部署(无现有数据): 只需将 DATABASE_URL 设置为您的 PostgreSQL 连接字符串并启动 FIM One。所有表都会自动创建。 必须保留现有数据: 需要手动导出/导入。一般方法:
  1. 使用 sqlite3 CLI 或 Python 脚本等工具从 SQLite 导出数据
  2. 根据需要转换数据(SQLite 和 PostgreSQL 有细微的类型差异)
  3. 使用 psql、pg_restore 或应用级别的插入脚本导入到 PostgreSQL
对于大多数从开发设置升级到生产环境的用户,使用 PostgreSQL 重新开始会更简单,并通过 UI 重新创建您的智能体和连接器。对话历史通常不重要到足以保证手动迁移的必要性。