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.
On this page
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 (opens in a new tab), 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.
Step 1: Copy to a new database#
Card: Copy to a new database.
- In Dokploy's Environment, add
MIGRATE_TO_DATABASE_URLwith the address of the new database, and restart the server:
MIGRATE_TO_DATABASE_URL=postgres://user:password@host/database?sslmode=requireUse the direct address (for Neon: the one without -pooler in it) and keep ?sslmode=require, so the data is encrypted on its way.
- 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-osspadd-on. - Press Copy now. The page shows the progress, the speed (MB/s) and the time left. Cancel stops it.
- When it says Done: in Dokploy set
DATABASE_URLto the new address, removeMIGRATE_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.
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.
- In Dokploy's Environment, add
OLD_DATABASE_URLwith the address of the old database, and restart the server. - Open Settings → Database and press Compare old and new. It reads both databases, row by row, and changes nothing.
- 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.
- 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 for what that means for you.