Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does pg_restore return "options -d/--dbname and -f/--file cannot be used together"?

The following Windows batch script fails on the line with database restore:

@Echo off

set Path=C:\Program Files (x86)
set Backup_Path=C:\Program Files (x86) 

c:  
cd \  
cd C:\Program Files (x86)\PostgreSQL\9.1\bin  

@echo "Wait ..."  
setlocal
set PGPASSWORD=1234
psql.exe -U postgres -c "create database Mydata"  
"C:\Program Files (x86)\PostgreSQL\9.1\bin\pg_restore.exe" -h localhost -U postgres -d Mydata -f "Mydata.backup"

pause 
endlocal

The error is:

pg_restore : -d / - dbname and -f / - file can not be used together Try " pg_restore --help "

like image 444
Leogreen Avatar asked Jan 10 '15 23:01

Leogreen


People also ask

What is Pg_restore in Postgres?

pg_restore is a utility for restoring a PostgreSQL database from an archive created by pg_dump in one of the non-plain-text formats. It will issue the commands necessary to reconstruct the database to the state it was in at the time it was saved.

Does Pg_restore overwrite?

If you use the --clean option of pg_restore , the old tables will be dropped before the new ones are created. If you do not use the --clean option, you will get an error message that the table already exists, but pg_restore will continue processing unless you use the --exit-on-error option.

How do I restore a Postgres database from a BAK file?

To restore a PostgreSQL database, you can use the psql or pg_restore utilities. psql is used to restore text files created by pg_dump whereas pg_restore is used to restore a PostgreSQL database from an archive created by pg_dump in one of the non-plain-text formats (custom, tar, or directory).


1 Answers

-f is the output filename, not the input file.

The input file does not have any parameter switch.

c:\>pg_restore --help
pg_restore restores a PostgreSQL database from an archive created by pg_dump.

Usage:
  pg_restore [OPTION]... [FILE]

General options:
  -d, --dbname=NAME        connect to database name
  -f, --file=FILENAME      output file name
  -F, --format=c|d|t       backup file format (should be automatic)
  -l, --list               print summarized TOC of the archive
  -v, --verbose            verbose mode
  -V, --version            output version information, then exit
  -?, --help               show this help, then exit

So you need to use:

pg_restore.exe -h localhost -U postgres -d Mydata "Mydata.backup"

More details in the manual: http://www.postgresql.org/docs/current/static/app-pgrestore.html

like image 104
a_horse_with_no_name Avatar answered Oct 27 '22 00:10

a_horse_with_no_name