postgresql 如何 pg_restore
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13704160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pg_restore
提问by Wine Too
I am dumping my database 'mydatabase' into a text file 'mydatabase.sql' through command line.
我正在通过命令行将我的数据库“mydatabase”转储到文本文件“mydatabase.sql”中。
"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' going nice.
But after many tries I can't do a pg_restore those file back to database with data.
But if I delete all tables in this database I can do it with:
这很顺利。但是经过多次尝试后,我无法将这些文件与数据一起 pg_restore 返回到数据库。
但是如果我删除这个数据库中的所有表,我可以这样做:
psql -f "C:\Users\User 1\Desktop\mydatabase.sql" "mydatabase" "postgres"
This recover's all data. Problem is that I can't run pgsl through VBNET/shell so I would rather need pg_restore.exe This is my try:
这将恢复所有数据。问题是我不能通过 VBNET/shell 运行 pgsl 所以我宁愿需要 pg_restore.exe 这是我的尝试:
"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"
...where I get message:
...我收到消息的地方:
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
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" 无效的二进制文件 "C:/Program Files (x86)/PostgreSQL/9.1/bin/pg_restore.exe " pg_restore.exe : [archiver] 输入文件似乎不是有效的存档
Before trying to restore I have empty database 'mydatabase' on server (without tables). Please any help to get pg_restore working with 'mydatabase.sql' which is dumped with pg_dump and which obviously contains a proper data so I can use it through pure command line or VBNET/shell.
在尝试恢复之前,我在服务器上有空数据库“mydatabase”(没有表)。请帮助 pg_restore 与“mydatabase.sql”一起工作,该“mydatabase.sql”与 pg_dump 一起转储,并且显然包含正确的数据,因此我可以通过纯命令行或 VBNET/shell 使用它。
采纳答案by Scott S
In your pg_dump, specify the -F t
flag. This tells pg_dump to create the backup in tar format, which is suitable for restore via pg_restore.
在您的 pg_dump 中,指定-F t
标志。这告诉 pg_dump 以 tar 格式创建备份,这适用于通过 pg_restore 恢复。
"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"