Migrate postgres database between servers
Aug 21, 2025
Prerequisites
Source database server with shell access.
Destination database server with shell access.
Basic knowledge of SSH to the servers.
Knowledge of docker cli commands and,
docker execcommands if you are using docker based postgres database
Prepare destination database
Login to the destination postgres instance.
Create the destination database if it does not exists.
If you need to drop the database first, then use one of the following command.
Create database backup/dump from the source
Login to the shell of the source database instance.
Use the following command to backup the data from source database.
This will create the backup.dump file in the shell path.
Download the backup file and migrate to another database server.
In case of database containers, create a relative docker volume on the container and store the file in the path of the mounted docker volume. For postgres, it is normally
/var/lib/postgresql/data.
Restore the database backup to the destination
Login to the shell of the destination database instance.
Make sure you have the database backup/dump file on the same server accessible to the user.
Then run the following command.
Above command will seed data to your destination database from the backup dump.
Verify the migration
You can verify if the migration is imported using the following command and listing the tables in the database.
