This page looks best with JavaScript enabled

Dump and Restore PostgreSQL Database

 ·  ☕ 1 min read

Do you want to move your database to other environment? This is how

Overview

This will be simple and short process, please read it well… 😎

Requisite

  • Terminal knowledge
  • PostgreSQL installed

How To

Dump Your PostgreSQL Database

To dump your current database just run this simple command from your terminal, here
pg_dump database_name > database_file_name.sql

Move/Copy Your SQL File

You can use scp or copy it manual if you have phisicaly access the environment.
Here I will show you how to copy using scp from other host to localhost:
scp login@host:path_to_dir_with/database_file_name.sql path_to_lcalhost_dir/database_file_name.sql

Restore Your PostgreSQL Database

Now, to restore the database to localhost we can use this command:
psql database_name < database_file_name.sql



Yes… that’s all! With these simple command you can dump and restore your postgreSQL database over terminal command.
At least with those 3 command line and you are ready to go… 😊
Aaand…. see you next post 👋

Share on

AlextraPixel
WRITTEN BY
AlextraPixel
DIY Anywhere - Share any knowledge & Experience for everyone