I'm new to postgresql, and locally, I use pgadmin3. On the remote server, however, I have no such luxury.
I've already created the backup of the database and copied it over, but, is there a way to restore a backup from the command line? I only see things related to GUI or to pg_dumps, so, if someone can tell me how to go about this, that'd be terrific!
try:
If you want to backup your data or restore data from a backup, you can run the following commands:
1 To create backup of your data, go to your postgres \bin\ directory like
C:\programfiles\postgres\10\bin\
and then type the following command -pg_dump -FC -U ngb -d ngb -p 5432 >C:\BACK_UP\ngb.090718_after_readUpload.backup
2 To restore data from a backup, go to your postgres \bin\ directory like
C:\programfiles\postgres\10\bin\
and then type below command -C:\programFiles\postgres\10\bin> pg_restore -Fc -U ngb -d ngb -p 5432 <C:\ngb.130918.backup
Please make sure that the backup file exists.
create backup
-F c is custom format (compressed, and able to do in parallel with -j N) -b is including blobs, -v is verbose, -f is the backup file name
restore from backup
important to set -h localhost - option
Below is my version of
pg_dump
which I use to restore the database:or use
psql
:where
-h
host,-p
port,-u
login username,-d
name of databaseAs below link said, you can use psql command for restoring the dump file:
https://www.postgresql.org/docs/8.1/static/backup.html#BACKUP-DUMP-RESTORE
if you need to set username just add the username after the command like:
There are two tools to look at, depending on how you created the dump file.
Your first source of reference should be the man page
pg_dump(1)
as that is what creates the dump itself. It says:So depends on the way it was dumped out. You can probably figure it out using the excellent
file(1)
command - if it mentions ASCII text and/or SQL, it should be restored withpsql
otherwise you should probably usepg_restore
Restoring is pretty easy:
or
Check out their respective manpages - there's quite a few options that affect how the restore works. You may have to clean out your "live" databases or recreate them from template0 (as pointed out in a comment) before restoring, depending on how the dumps were generated.