# Migrating Psql / Files ## Dump DB ```bash # Eliminate compression and use all cores (8 in this example) pg_dump -h 127.0.0.1 -U postgres -Z0 -j 8 -Fd amlegal -f dumpdir # Compress directory in parallel using pigz tar -cf - dumpdir | pigz > dumpdir.tar.gz ``` ## Restore DB ```bash pigz -dc dumpdir.tar.gz | tar -C dumpdir --strip-components 1 -xf - pg_restore -h 127.0.0.1 -U postgres -j 8 -Fd -O -d amlegal dumpdir ``` ## To kill all open psql connections ```postgresql SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = 'amlegal'; ``` ## Rsync Files ```bash sudo rsync -azOP --delete -e "ssh -i prod_amlegal.pem" alpadmin@192.168.40.115:~/media . ```