使用dump+restore离线迁移的方法shi最快的,过程中使用压缩+并行导出导入。示例如下:
source_db_user=
source_db_ip=
source_db_port=
source_db_name=
source_db_password=
target_db_user=
target_db_ip=
target_db_port=
target_db_name=
target_db_password=
echo "begin dumping"
date
export PGPASSWORD=$source_db_password
pg_dump -U $source_db_user -h $source_db_ip -p $source_db_port $source_db_name -Fd -j 5 -f dumpdir
echo "done dumping"
date
echo "begin restoring"
date
export PGPASSWORD=$target_db_password
pg_restore -U $target_db_user -h $target_db_ip -p $target_db_port -d $target_db_name -j 5 dumpdir
echo "end restoring"
date