本文介绍了如何pg_restore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am dumping my database 'mydatabase' into a text file 'mydatabase.sql' through command line.

"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"

这很好。
但是经过多次尝试,我无法将这些文件与数据一起pg_restore。

但是,如果我删除了该数据库中的所有表,我可以这样做:

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:

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

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

This recover's all data.Problem is that I can't run pgsl through VBNET/shell so I would rather need pg_restore.exeThis is my try:

"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"

...在哪里消息:

在尝试还原之前,服务器上有空数据库 mydatabase(没有表)。
请提供任何帮助,以使pg_restore与 mydatabase.sql一起使用,后者已与pg_dump一起转储,并且显然包含适当的数据,因此我可以通过纯命令行或VBNET / shell来使用它。

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.

推荐答案

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

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.

"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"

这篇关于如何pg_restore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 18:25