Search code examples
sqlwindowspostgresqlubuntuvagrant

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?


Solution

  • 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.