Once you have your DB download, you need to restore it in order to use it and access any information contained within. This article will show you how to restore it via CLI.
- Open a new terminal/cmd window and use the
createdbcommand to create a new database. (Read more about the createdb command).
user$ createdb -hlocalhost -p 5432 -U postgress testdb
createdbis the name of the command you are executing.
-hspecifies the host, which should be the localhost for default installs.
-pspecifies the port to connect through, which should be 5432 for default installs.
-Uspecifies the username you are connecting as, which should be postgres.
testdbis the name chosen for the new database. You may want to replace it with a different name.
user$ createdb -h localhost -p 5432 -U postgress testdb
pg_restorecommand to restore the dump file to the newly created database. (Read more about the pg_restore command).
user$ pg_restore -v -h localhost -p 5432 -U postgres -b testdb ~/Desktop/Database/Downloads/dumptest.dmp
pg_restoreis the name of the command you are executing.
-voption indicates verbose mode. This means the program will print information about what it is doing as it is running. This is optional but can be helpful if you want to troubleshoot issues.
-hoption is the host, as in
-poption is the port, as in
-Uoption is the user, as in
-doption is the database to restore to, which should be the name of the database you created in step 1 with the
~/Desktop/Database\ Downloads/dumptest.dmpis the path to the dump file.
Note: If you wish to restore the backup of a single table from the database backup, you can add the
-t <tablename>option to the
pg_restore -v -h localhost -U postgres -d testdb -t <Table_Name> ~/Desktop/Database/Downloads/dumptest.dmp
user$ pg_restore -h localhost -p 5432 -U postgres -d testdb ~/Desktop/Database\ Downloads/dumptest.dmpIf you did include the verbose option, then you will see extra messaging preceded by
pg_restore:, while the command is running. You will know that it is done when a new terminal line is presented.
The database has been restored and it is ready to be used.