Postgres DB dump and restore

Export a database

pg_dump -U username dbname > dbexport.pgsql

pg_dump -U db_user -W -F t db_name > /path/to/your/file/dump_name.tar
    -F is used to specify the format of the output file, which can be one of the following:
    p – plain-text SQL script
    c – custom-format archive
    d – directory-format archive
    t – tar-format archive

Restore database

Restore with psql

psql -U username dbname < dbexport.pgsql

Restore with pg_restore

pg_restore -d db_name /path/to/your/file/dump_name.tar -c -U db_user

-c to drop database objects before recreating them,
-C to create a database before restoring into it,
-e exit if an error has encountered,
-F format to specify the format of the archive.