# Copy the database

> Move your library's posts, tags and share links to another PostgreSQL such as Neon, check the copy, switch over, and later delete the old data.

Source: https://crawl-docs.pdhq.win/guide/database-copy/
Last updated: 2026-12-02

Your posts, tags, notes, share links and settings are kept in a PostgreSQL database. Your saved **files** (pictures, videos) are not in it: they stay on the disk, in R2 or on WebDAV, and moving the database does not touch them.

By default the database is the `db` service of your stack. If you would rather use a hosted one, such as [Neon](https://neon.com), Social Crawl can copy everything over from **Settings → Database**. There are two cards for two separate steps. In both, the **old database** is the one you are leaving and the **new database** is the one you are moving to.

> [!WARNING]
> Do not save posts while the copy runs: a post saved during the copy is not included. Switch right after it finishes.

## Step 1: Copy to a new database

Card: **Copy to a new database**.

1. In Dokploy's **Environment**, add `MIGRATE_TO_DATABASE_URL` with the address of the new database, and restart the server:

```text
MIGRATE_TO_DATABASE_URL=postgres://user:password@host/database?sslmode=require
```

   Use the **direct** address (for Neon: the one without `-pooler` in it) and keep `?sslmode=require`, so the data is encrypted on its way.

2. Open **Settings → Database** and press **Check**. It only looks at both databases and changes nothing. If something is marked with a red cross, fix it and press **Check** again. The new database must be **empty** and have the `uuid-ossp` add-on.
3. Press **Copy now**. The page shows the progress, the speed (MB/s) and the time left. **Cancel** stops it.
4. When it says **Done**: in Dokploy set `DATABASE_URL` to the new address, remove `MIGRATE_TO_DATABASE_URL`, and redeploy. The card says "What to do next" and shows these two steps. The app now uses the new database.

Until you set `DATABASE_URL`, the app uses the `db` service of this stack.

**Safety:** the copy only reads the old database, so nothing in it is changed. If anything goes wrong, or you press **Cancel**, the new database is left empty. The copy is kept only if every table in the new database matches the original. Nothing in the new database is overwritten.

### After the switch

Once `DATABASE_URL` is set you can remove `POSTGRES_PASSWORD`, `POSTGRES_USER` and `POSTGRES_DB`. The stack still starts its own `db` service with your old data in it (the volume `pgdata`), so the old database stays available as a backup, and Step 2 can reach it.

> [!IMPORTANT]
> A brand-new install that has never run this stack's own database needs `POSTGRES_PASSWORD` (any value) even with `DATABASE_URL` set, because that database has to be created once. If neither `DATABASE_URL` nor `POSTGRES_PASSWORD` is set, the deploy goes through but the API does not start. Its log says: `DATABASE_URL: points to the database in this stack (sc-db) but has no password: set POSTGRES_PASSWORD ... or set DATABASE_URL to another database`.

## Step 2: Delete the old database's data

Card: **Delete the old database**. Do this **later**, only when the app already runs on the new database and everything works.

1. In Dokploy's **Environment**, add `OLD_DATABASE_URL` with the address of the old database, and restart the server.
2. Open **Settings → Database** and press **Compare old and new**. It reads both databases, row by row, and changes nothing.
3. If they match, **Delete old data…** is switched on. If they do not match, it stays off and the page shows what is different, table by table: rows only in the old database (what deleting would lose), rows only in the new database, and rows that changed (it names the columns, never the values). Some difference is normal if you have used the new database since you switched. If you accept it, tick **Delete anyway. I have looked at what is different.**
4. Press **Delete old data…** and enter your password. It always asks again.

**Safety:** it never deletes the database the app is using, also when the old address is only another way to reach it. It removes only this app's own tables, all together or not at all, and leaves everything else in that database. The empty database and its user stay.

Afterwards remove `OLD_DATABASE_URL`. If the old database was this stack's own `db` service, its container keeps running and its disk stays in use. To stop it for good, remove the `db` service from `docker-compose.yml` (the file lives in the repository, not in Dokploy), and delete the `pgdata` volume in Dokploy to free the disk.

## Tables are made by the server

The tables are created by TypeORM `synchronize` (`DB_SYNCHRONIZE`, on in the compose file). There are no migrations yet. See [Data model](https://crawl-docs.pdhq.win/advanced/data-model.md) for what that means for you.
