21 Sep 2018

Backup and Restore with PostgreSQL

PostgreSQL is a very powerful SQL database. It provides various fields in storing different data types like date, json, text, arrays, etc. It also contains some backup and restore mechanism which you can use to safeguard your data. In the following section, I will demonstrate how you can backup and restore your PostgreSQL database.

Features

  • Backing up PostgreSQL with pg_dump

    export PGPASSWORD="<password>" | pg_dump -c -h <postgresql-host> -U <user> -d <database-name> | gzip > ~/<path>/<database-name>.sql.gz
    
  • Restoring a PostgreSQL backup

    export PGPASSWORD="<password>" | pg_restore -c -h <postgresql-host> -U <user> -d <database-name> [dumpfile_name].dump
    

Tags: