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
Open a terminal window.
Run the Porter connect command:
porter datastore connect <your-database-name>
Keep this terminal window open to maintain the tunnel connection.
Step 2: Prepare for Restoration
Open a new terminal window.
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
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
Replace
<port>
with the port number provided by Porter.Adjust the file path to match your backup file's location.
Step 4: Enter Password and Wait
When prompted, enter the password provided by Porter.
Wait for the restoration process to complete. This may take some time depending on the size of your backup.
Step 5: Verify Restoration
After the restore completes, you can connect to the database to verify:
Copypsql -h 127.0.0.1 -p <port> -U postgres -d postgres
Run some queries to check if your data has been restored correctly.
Step 6: Close the Connection
Once verified, exit the psql session.
Go back to the first terminal window with the Porter tunnel.
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.