Overview
Once you have obtained your DB download, you will need to restore it to use it and access any information contained within. You can use either of the following methods interchangeably:
- Via pgAdmin (Postgres)
- Via CLI (Command Line Interface)
NOTE: Just because you use pgAdmin to restore a database, does not mean you cannot use the CLI later to do so.
This article describes the step-by-step process to restore a database download via the CLI.
Environment
- This article covers all versions of Jive Custom.
- The commands in this article were written using PostgreSQL version 9.2.6
- This guide was written for the Mac OSX release of Postgres/pgAdmin; however, the steps should translate to Windows or Linux.
Process
- Open a new terminal (on Mac) /command prompt (on Windows) and use the
createdb
command to create a new database:
test.user$ createdb -h localhost -p 1111 -U postgres testdb
-
createdb
is the name of the command we are executing. - the
-h
option specifies the host, which should belocalhost
for default installs. - the
-p
option specifies the port to connect through, which should be1111
for default installs. - the
-U
option specifies the username you are connecting as, which should be Postgres. -
testdb
is the name chosen for the new database. You should replace this with the name you wish to use.
-
- You will be prompted for a password, which is the password of the Postgres user (not your OS user).
- This should be the password you created when installing Postgres.
- Once you enter this password, the database should be created successfully and you should get a new terminal line with no output, so your terminal window should look like this:
test.user$ createdb -h localhost -p 1111 -U postgres testdb
Password:
test.user$
- Use the
pg_restore
command to restore the dump file to the newly created database:
test.user$ pg_restore -v -h localhost -p 1111 -U postgres -d testdb ~/Desktop/Database\ Downloads/dumptest.dmp
-
pg_restore
is the name of the command we are executing. - the
-v
option 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. - the
-h
option is the host, as increatedb
- the
-p
option is the port, as increatedb
- the
-U
option is the user, as increatedb
- the
-d
option is the database to restore to, which should be the name of the database you created in Step 1 with thecreatedb
command. -
~/Desktop/Database\ Downloads/dumptest.dmp
is the path to the dump file. Since these commands were executed in the home directory, the full path to the file is included.
-
- Again, you will be prompted for the password of the Postgres user:
- Once you enter it, the restore will execute.
- If you did not include the verbose option, when the command finishes, you will get a new terminal line with no output, such as below:
test.user$ pg_restore -h localhost -p 1111 -U postgres -d testdb ~/Desktop/Database\ Downloads/dumptest.dmp
Password:
test.user$
- You can now proceed to query your DB via CLI.
Confirmation
- If you did include the verbose option, then you will see extra messaging preceded by pg_restore: while the command is running. A new terminal line is presented once this is done.
- Your database is now restored and ready to query!
Related Articles
Comments
0 comments
Article is closed for comments.