Skip to content

debugging importing a database dump locally

Carlo Beltrame edited this page Jun 26, 2023 · 8 revisions

Sometimes it is necessary to import a database dump on a local machine, e.g. to debug problems which only happen in production. Here is one way to do that.

/usr/bin/pg_dump --clean --if-exists --file=/path/to/dump.sql --dbname=<insert-db-name-here> --username=<insert-db-user-here> --host=<insert-db-host-here> --port=<insert-db-port-here>

Make sure that the database migration files on your local computer match the migrations in the environment which you got the dump from. Start your local ecamp3 normally.

Then, import the dump using psql. This will clean out your database and completely replace it with the data from the dump:

psql -U ecamp3 --host localhost --port 5432 ecamp3dev < /path/to/dump.sql

As password, enter ecamp3

There might be some errors due to indexes and foreign keys which are already present in your database. You can safely ignore these.

If you need to log in as another user, you can safely reset the password and receive the reset email at http://localhost:3000/mail.

Make sure to delete any production data dumps when you are finished!