Restore dump on the remote machine

前端 未结 5 836
醉话见心
醉话见心 2020-12-15 06:50

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

相关标签:
5条回答
  • 2020-12-15 07:02

    Alternatively, you can use psql:

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

    0 讨论(0)
  • 2020-12-15 07:08

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

    0 讨论(0)
  • 2020-12-15 07:22

    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:

    • pg_restore documentation
    0 讨论(0)
  • 2020-12-15 07:22

    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)
    
    0 讨论(0)
  • 2020-12-15 07:28

    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.

    0 讨论(0)
提交回复
热议问题