postgresql – Howto pg_restore

前端之家收集整理的这篇文章主要介绍了postgresql – Howto pg_restore前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我通过命令行将我的数据库’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’好转.
但经过多次尝试后,我无法将这些文件pg_restore用数据返回数据库.
但是,如果我删除数据库中的所有表,我可以使用:

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

这可以恢复所有数据.
问题是我无法通过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"

…我收到消息的地方:

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进行恢复.
"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"
原文链接:https://www.f2er.com/postgresql/192839.html

猜你在找的Postgre SQL相关文章