Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to import a dump file in PSQL.

Open terminal.

Connect to psql:

psql -p 5433

I find it easier to delete and recreate the DB to which you want to import. So ensure the databse you want to delete is listed:


Delete the database:

drop database DB_2;

Re-create it:

create databse DB_2;

Quit PSQL. We are done with it for now:


Import the data to the newly created database:

psql -h -U postgres -p 5433 DB_2 < /Path/To/file/DB-2-new-dump-file.dump

Optionally, to dump a DB, use these commands:

pg_dump -U postgres -n schema-name -s digilex > path/to/file.sql
pg_dump -U postgres -t table-name digilex > path/to/file.sql
pg_dump -h -p 5433 -U postgres -v dev > /Users/MacBook/Desktop/devDump.sql
psql -h -U postgres -p 5433 digilex < /Users/MacBook/Desktop/dump-file-name.dump
Copy link

wiesys commented Nov 23, 2022

Thank you! 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment