以下Windows批处理脚本在进行数据库还原时失败:

@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

错误是:

最佳答案

-f输出文件名,而不是输入文件。

输入文件没有任何参数开关。

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

因此,您需要使用:
pg_restore.exe -h localhost -U postgres -d Mydata "Mydata.backup"

手册中的更多详细信息:http://www.postgresql.org/docs/current/static/app-pgrestore.html

关于postgresql - 为什么pg_restore返回 “options -d/--dbname and -f/--file cannot be used together”?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27882070/

10-15 23:15