What Database Types Does Logto Support?
Logto exclusively supports PostgreSQL (versions 14.0 and higher), using the Slonik driver for connection pooling across all core services including the OIDC provider and management API.
The logto-io/logto repository is architected as a PostgreSQL-native application. Every database interaction—from CLI tooling to the core OIDC adapter—depends on PostgreSQL-specific features and error handling, with no abstraction layer supporting alternative databases like MySQL or SQLite.
Logto's PostgreSQL-Only Architecture
Logto hardcodes PostgreSQL as its sole datastore throughout the codebase. The project uses Slonik (a PostgreSQL client with strict typing) for all connection pooling, and every database-related module references PostgreSQL-specific implementations.
According to the source code in packages/cli/src/database.ts, the CLI creates a PostgreSQL pool using createPool from Slonik, with no configurable adapter pattern for other database engines. Similarly, packages/core/src/oidc/adapter.ts implements a PostgreSQL-specific OIDC adapter that stores tokens, codes, and sessions directly in PostgreSQL tables.
Required PostgreSQL Version
The contribution guidelines explicitly mandate PostgreSQL ^14.0 for development environments.
As documented in /.github/CONTRIBUTING.md, contributors must have PostgreSQL version 14 or higher installed locally. The docker-compose.yml file at the repository root further enforces this by spinning up a postgres:17-alpine container (or similar recent version) as the default datastore for local development and CI pipelines.
How Logto Connects to PostgreSQL
Logto establishes database connections through the DB_URL environment variable, which must contain a valid PostgreSQL DSN. The core server initializes a connection pool on startup using Slonik, and the CLI commands perform database creation and migration using the same PostgreSQL client.
Key connection characteristics include:
- Connection pooling via Slonik's
createPoolmethod - PostgreSQL error code mapping in
packages/core/src/middleware/koa-slonik-error-handler.ts - No fallback drivers—the application fails to start if
DB_URLis not a PostgreSQL connection string
Key Implementation Files
The following source files demonstrate Logto's PostgreSQL dependency:
docker-compose.yml—Defines thepostgresservice and setsDB_URLto a PostgreSQL DSNpackages/cli/src/database.ts—Handles PostgreSQL pool creation and maintenance database connectionspackages/core/src/oidc/adapter.ts—PostgreSQL-specific OIDC adapter implementation for tokens and sessionspackages/core/src/middleware/koa-slonik-error-handler.ts—Maps PostgreSQL error codes (e.g.,23505for unique violations) to HTTP responses
No alternative database drivers are present in the source tree. All query building and schema migrations target PostgreSQL-specific syntax and features.
Configuration Examples
Connecting via the Logto CLI
The CLI utilities establish PostgreSQL connections using Slonik. From packages/cli/src/database.ts:
import { createPool } from 'slonik';
const dsn = {
host: 'localhost',
port: 5432,
database: 'logto',
username: 'postgres',
password: 'p0stgr3s',
};
const pool = await createPool(
`postgres://${dsn.username}:${dsn.password}@${dsn.host}:${dsn.port}/${dsn.database}`
);
Environment Variable Configuration
Set the DB_URL environment variable to point to your PostgreSQL instance:
export DB_URL="postgres://postgres:p0stgr3s@localhost:5432/logto"
pnpm start:dev
The core server reads this variable during initialization to configure its global connection pool.
Docker Compose Setup
For local development, Logto provides a docker-compose.yml that provisions PostgreSQL:
services:
postgres:
image: postgres:17-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: p0stgr3s
POSTGRES_DB: logto
ports:
- "5432:5432"
This configuration matches the default development settings expected by the Logto core and CLI tools.
Summary
- Logto supports only PostgreSQL—no MySQL, SQLite, or other databases are implemented
- Minimum version requirement is PostgreSQL 14.0 or higher
- Connection management uses Slonik with
createPoolfor robust connection pooling - Critical files include
packages/cli/src/database.tsfor CLI connections andpackages/core/src/oidc/adapter.tsfor session storage - Configuration requires the
DB_URLenvironment variable pointing to a PostgreSQL DSN
Frequently Asked Questions
Does Logto support MySQL or MariaDB?
No. Logto does not include drivers or adapters for MySQL, MariaDB, or any database other than PostgreSQL. The source code in packages/core/src/oidc/adapter.ts and related files uses PostgreSQL-specific queries and Slonik's PostgreSQL client exclusively.
What happens if I try to use a SQLite database with Logto?
The application will fail to start. Logto's database initialization in packages/cli/src/database.ts expects a PostgreSQL DSN in the DB_URL environment variable and attempts to create a Slonik pool using PostgreSQL-specific connection parameters. There is no SQLite driver fallback.
Which PostgreSQL version should I use for Logto production deployments?
Use PostgreSQL version 14.0 or higher. The /.github/CONTRIBUTING.md file specifies PostgreSQL ^14.0 as the minimum supported version, and the Docker Compose configurations typically use PostgreSQL 17 Alpine for development and testing environments.
Can I run Logto without Docker?
Yes, but you still need PostgreSQL. You can install PostgreSQL 14+ directly on your host machine or use a managed PostgreSQL service (like AWS RDS, Google Cloud SQL, or Azure Database). Set the DB_URL environment variable to your PostgreSQL connection string and run pnpm start without Docker.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →