简体   繁体   中英

How to import SQL dump into Postgres DB running on Vagrant instance of Ubuntu

I am using Postgres via a vagrant instance running ubuntu-xenial-16.04-cloudimg box and I have an sql dump from another developer.

By the way, I tried using PGAdmin IV from my Win 10 host machine after I had connected to the Postgres server on the virtualbox (ubuntu) but it takes forever and not running.

How can I import this to the Postgres running on virtualbox instance?

So given an sql dump file as dump.sql .

  1. Run vagrant ssh on an ssh client like git bash(for windows)
  2. Put the dump file in the directory containing the vagrantfile on the host machine. As it syncs by default with the guest machine or run vagrant rsync , just to make sure.
  3. Navigate to the vagrant directory on the host machine (eg cd ../../ for an ubuntu guest on a window host)
  4. Run psql -h hostname -U test -d databasename -f dump.sql .

Depending on the format of the dump (normal or custom), you can use psql or pg_restore . Check the --format option in the documentation for pg_dump

Following the simple steps below solves my problem:

  1. After vagrant up , vagrant ssh to log into the os
  2. Type psql command
  3. Then create database your_db_name to create the empty db
  4. Make sure the dump sql file is in the folder containing the vagrantfile ( cd vagrant) or a sub folder within
  5. Write this command to import the dump file into the newly create db
    your_db_name -f /path/to/the/dump.sql

I hope the steps will help you too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM