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.
Its data is updated regularly as a result of tests, then a new dump must be made, and the dumps are regularly used to recreate the database in a well-defined state. I noted that the dump (using pg_dump -Fc database ) only takes a few seconds, but the restore ( pg_restore -d database ) takes about a minute.
Description. pg_restore is a utility for restoring a PostgreSQL database from an archive created by pg_dump in one of the non-plain-text formats. It will issue the commands necessary to reconstruct the database to the state it was in at the time it was saved.
pg_dumpall works by emitting commands to re-create roles, tablespaces, and empty databases, then invoking pg_dump for each database. This means that while each database will be internally consistent, the snapshots of different databases are not synchronized.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With