You can get a backup of the database with the pg_dump program. The actual command you’ll run will depend on what name you used for your database; I run
pg_dump mastodon_production > /home/mastodon/backup.psqld
Then you can FTP the backup and your .env_production file to a different server, clear the disk, create the new database, and then restore with psql:
psql mastodon_production < backup.psqld
(This doesn’t create the database on its own; you’ll have to create it yourself first before running the psql import.)
Possibly this isn’t quite what you’re asking, but I figured it might be useful.