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

邮差的信 提交于 2019-12-07 06:19:43

问题


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 "


回答1:


-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



来源:https://stackoverflow.com/questions/27882070/why-does-pg-restore-return-options-d-dbname-and-f-file-cannot-be-used-tog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!