25

I've got my own machine with postgres dmp file, which I want to restore on the remote virtual machine (e.g. ip is 192.168.0.190 and postgres port is 5432) in my network. Is it possible to restore this dump using pg_restore without copying dump to remote machine? Because the size of dump about 12GB and the disk space on the virtual machine is 20GB. Thanks

Danila Zharenkov
  • 1,720
  • 1
  • 15
  • 27

5 Answers5

46

You can run a restore over the network without copying the dump to the remote host.

Just invoke pg_restore with -h <hostname> and -p <port> (and probably -U <username> to authenticate as different user) on the host you got the dump file, for example:

pg_restore -h 192.168.0.190 -p 5432 -d databasename -U myuser mydump.dump

References:

nif
  • 3,342
  • 20
  • 18
  • Yeah, you are right. I'm trying like this pg_restore -i -h 192.168.1.190 -p 5432 -U postgres -d MFC_sara -v /home/develop/BD_Dumps/Saratov.dmp ; But after this command it's needed to input some password for destination database. And I don't know it, on virtual machine I just create db like createdb -T template0 MFC_sara – Danila Zharenkov Oct 15 '14 at 08:55
  • 1
    If you want to access from a remote machine you will need password authentication (or any other non-local authentication). Create a user and assign privileges for the database. Or if this is no production environment, create a superuser with password: `createuser -P -s someusername` – nif Oct 15 '14 at 09:46
18

Alternatively, you can use psql:

psql -h 192.168.0.190 -p 5432 -d <dbname> -U <username> -W -f mydump.dump

plomovtsev
  • 512
  • 4
  • 11
9

An example for a remote RDS instance on AWS

psql -h  mydb.dsdreetr34.eu-west-1.rds.amazonaws.com -p 5432 -d mydbname -U mydbuser -W -f  mydatabase-dump.sql

  -f, --file=FILENAME      execute commands from file, then exit
  -W, --password           force password prompt (should happen automatically)
Dr Manhattan
  • 13,537
  • 6
  • 45
  • 41
1

You can pass the password parameter in your script before "pg_restore" using PGPASSWORD="your_database_password"

Van
  • 11
  • 1
1

I run this and works to me:

    scp backup.dump user@remotemachine:~

    ssh user@remotemachine "pg_restore -h localhost -p 5432 -U databaseuser -W -F c -d databasename -v backup.dump"

You can write a script to automate this.

doganak
  • 798
  • 14
  • 31
Franco S
  • 11
  • 3