简体   繁体   中英

How to pg_restore

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"

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"

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:

"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

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.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM