Skip to main content
All CollectionsBlog
Restoring a Local PostgreSQL Database Backup to Porter
Restoring a Local PostgreSQL Database Backup to Porter
Updated over 5 months ago

Prerequisites:

  • Porter CLI installed and configured

  • Local database backup file (e.g., db.dump)

  • Access to a Porter project and database

Step 1: Connect to the Porter Database

  1. Open a terminal window.

  2. Run the Porter connect command:

    porter datastore connect <your-database-name>
  3. Keep this terminal window open to maintain the tunnel connection.

Step 2: Prepare for Restoration

  1. Open a new terminal window.

  2. Note the connection details provided by Porter:

    • Host: Usually 127.0.0.1

    • Port: Provided by Porter (e.g., 8122)

    • Database name: Usually postgres

    • Username: Usually postgres

    • Password: Provided by Porter

Step 3: Restore the Database

  1. For a custom format dump file (usually .dump extension): Use the pg_restore command:

    pg_restore -h 127.0.0.1 -p <port> -U postgres -d postgres -v /path/to/your/backup.dump
  2. Replace <port> with the port number provided by Porter.

  3. Adjust the file path to match your backup file's location.

Step 4: Enter Password and Wait

  1. When prompted, enter the password provided by Porter.

  2. Wait for the restoration process to complete. This may take some time depending on the size of your backup.

Step 5: Verify Restoration

  1. After the restore completes, you can connect to the database to verify:

    Copypsql -h 127.0.0.1 -p <port> -U postgres -d postgres
  2. Run some queries to check if your data has been restored correctly.

Step 6: Close the Connection

  1. Once verified, exit the psql session.

  2. Go back to the first terminal window with the Porter tunnel.

  3. Press Ctrl+C to close the tunnel connection.

Troubleshooting:

  • If you encounter permission issues, ensure you have the necessary rights in Porter.

  • For large databases, consider using the --jobs option with pg_restore to speed up the process:

    Copypg_restore -h 127.0.0.1 -p <port> -U postgres -d postgres -v --jobs=4 /path/to/your/backup.dump
  • If the restore fails, check the Porter logs and your local PostgreSQL installation for any error messages.

Remember to always test restores in a non-production environment first before applying to production databases.

Did this answer your question?