Skip to content

Instantly share code, notes, and snippets.

@pierrejoubert73
Last active March 12, 2024 06:06
Show Gist options
  • Save pierrejoubert73/85b3ce8b52e7f6dbce69e2636f68383f to your computer and use it in GitHub Desktop.
Save pierrejoubert73/85b3ce8b52e7f6dbce69e2636f68383f to your computer and use it in GitHub Desktop.
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:

\l

Delete the database:

drop database DB_2;

Re-create it:

create databse DB_2;

Quit PSQL. We are done with it for now:

\q

Import the data to the newly created database:

psql -h 127.0.0.1 -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 digilex.co.za -p 5433 -U postgres -v dev > /Users/MacBook/Desktop/devDump.sql
psql -h 127.0.0.1 -U postgres -p 5433 digilex < /Users/MacBook/Desktop/dump-file-name.dump
@wiesys
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