In this tutorial, we show how to backup or dump and how to restore a postgresql database.
For making a backup you can use pg_dump command like below:
pg_dump -Fc -h localhost mydatabase -U myuser -n myschema > test.pgdump
in the above, change hostname (localhost), database name (mydatabase), user (myuser) and schema (myschema) based on yours.
The test.pgdump file is the output backup file.
-F means format and -c is custom-format archive
Also for restoring the database using the backup file we use the pg_restore command like:
pg_restore -U myuser -h localhost -p 5432 -c -d mydatabase test.pgdump
Same as the pg_dump command, please change the hostname, database name and the user according to yours.