Home > database >  How can I restore a postgresql db dump from a local db to a server via psql?
How can I restore a postgresql db dump from a local db to a server via psql?

Time:03-17

I have building and testing a psql database on my local machine, and the time is come to move it to a server. I have my dump file, but I'm not sure how to actually get it on the server to restore it there. Obviously something like the following doesn't work:

psql -U user -d datbase < C:/dbbackups/dbbackup.dump

But what is the proper way to get my dump on the server from my local to properly restore it?

CodePudding user response:

You can use pg_dump.

pg_dump -C -h localhost -U localuser dbname | psql -h remotehost -U remoteuser dbname

If you want to use your dump you could of course also transfer your dump file over to the new server securly using e.g. SFTP and then restore it there as you would on your local machine.

  • Related