# Switching from SQLite to Postgres

> Point DATABASE_URL at Postgres, switch the Prisma provider, push the schema, and move existing data.

URL: https://heyorbit.tech/docs/self-hosting/postgres
Last updated: 2026-11-19

Self-hosting and deployment · [Documentation](https://heyorbit.tech/docs)

SQLite is fine for a single server with a persistent disk. Use Postgres for serverless hosts, several instances, or managed backups.

## 1. Set DATABASE_URL

~~~bash
DATABASE_URL="postgresql://orbit:secret@db.internal:5432/orbit?schema=public&connection_limit=10"
~~~

Managed providers (Neon, Supabase, RDS, Cloud SQL) work; add sslmode=require where needed. With a pooled connection string (for example on Neon), also set DIRECT_DATABASE_URL to the direct, unpooled URL; schema pushes use it.

## 2. Switch the Prisma provider

~~~bash
npm run db:prepare
~~~

This reads DATABASE_URL and sets the provider in prisma/schema.prisma to postgresql (adding the direct URL when DIRECT_DATABASE_URL is set), then regenerates the Prisma client. The schema only uses types that exist in both databases, with JSON stored in text columns, so no model changes are needed.

## 3. Create the schema

~~~bash
npx prisma db push
~~~

On Vercel, npm run vercel-build does steps 2 and 3 for you on every deploy, then seeds the demo workspace once when SEED_DEMO is true and the database is empty.

**Docker:** the Dockerfile and compose file are set up for SQLite. To use Postgres, run npm run db:prepare with your Postgres DATABASE_URL in your checkout before docker build, so the image is built with the Postgres provider, and pass the Postgres DATABASE_URL to the container (remove the SQLite DATABASE_URL line from the compose file). The container runs prisma db push against it on start.

## 4. Move existing data (optional)

For a small SQLite database, the simplest path is a script that reads each table through Prisma on SQLite and writes it to Postgres in dependency order (users, workspaces, members, accounts, posts, targets, media, inbox, reports), keeping the same ids so relations hold. pgloader can also convert the SQLite file directly:

~~~bash
pgloader sqlite:///app/data/heyorbit.db postgresql://orbit:secret@db.internal:5432/orbit
~~~

Check DateTime columns afterwards (SQLite stores them as integers or text) and run prisma db push again to add any missing indexes.

## 5. Verify

Sign in, open a workspace, check the calendar and inbox, and publish a test post. Then retire the SQLite volume.

## Backups

Use your provider's point-in-time recovery or a nightly pg_dump. Stored credentials can only be read with the same APP_SECRET, so keep the secret safe alongside the backups.
