Genrating Postgres dump and saving to another server

Viewed 475

I have a website with Postgres DB. Site was created in 2017, So I am updating it to latest versions of all technologies. I have created another server and plan to move this entire site on new server, but I need to test each component. My site code I can directly upload from my computer to new server.

However is there a way to take dump of Postgres directly to new server? I want to take dump of Postgres directly to new server because current server has only 50 GB space and my DB is of 35GB, so backup will fail due to space constraint.

Will this code work? I do not want to take any risk with live database.

pg_dump -C -h local -U localuser source_database | psql -h remote -U remoteuser target_database

Got this from internet. So my purpose in short is: Take backup of database to restore in another server. But do not save file in old server, transfer to new server. Sorry if I sound idiotic. Have learnt 80% of things from SO.

1 Answers

I played with pg-dump a while ago and been using it for updating my test environment. Take a look at the question I asked.

The command worked just fine for me and did not cause any issues to the production (origin) db.

Here is the command I'm running in the new server.

pg_dump -h remotehost -p 5432 -U remoteuser remotedb | psql -h localhost -p 5432 -U localuser localdb

Note that I did not add the -C here, since I already had the destination db created.

Related