关于postgresql:如何pg_restore

How to pg_restore

我通过命令行将我的数据库'mydatabase'转储到文本文件'mydatabase.sql'中。

1
"C:/Program Files (x86)/PostgreSQL/9.1/bin/pg_dump.exe" --host localhost --port 5432 --username"postgres" --no-password --verbose --file"C:\Users\User 1\Desktop\mydatabase.sql""mydatabase"

Thas'好转。
但经过多次尝试后,我无法用数据将pg_restore文件重新发送回数据库。
但是,如果我删除此数据库中的所有表,我可以使用:

1
psql -f"C:\Users\User 1\Desktop\mydatabase.sql""mydatabase""postgres"

这可以恢复所有数据。
问题是我无法通过VBNET / shell运行pgsl所以我宁愿需要pg_restore.exe
这是我的尝试:

1
"C:/Program Files (x86)/PostgreSQL/9.1/bin/pg_restore.exe" -i -h localhost -p 5432 -U postgres -d"mydatabase" -v"C:\Users\User 1\Desktop\mydatabase.sql"

...我收到消息的地方:

C:\Users\User 1>"C:/Program Files (x86)/PostgreSQL/9.1/bin/pg_restore.exe" -i -h
localhost -p 5432 -U postgres -d"mydatabase" -v"C:\Users\User 1\Desktop\mydatabase.sql"
invalid binary"C:/Program Files (x86)/PostgreSQL/9.1/bin/pg_restore.exe"
pg_restore.exe : [archiver] input file does not appear to be a valid archive

在尝试恢复之前,我在服务器上有空数据库'mydatabase'(没有表)。
请帮助pg_restore使用'mydatabase.sql',它与pg_dump一起转储,显然包含正确的数据,所以我可以通过纯命令行或VBNET / shell使用它。


在pg_dump中,指定-F t标志。 这告诉pg_dump以tar格式创建备份,这适合通过pg_restore进行恢复。

1
"C:/Program Files (x86)/PostgreSQL/9.1/bin/pg_dump.exe" --host localhost --port 5432 --username"postgres" --no-password --verbose -F t --file"C:\Users\User 1\Desktop\mydatabase.sql""mydatabase"