How to pg_restore

32,920

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"
Share:
32,920
Wine Too
Author by

Wine Too

Updated on July 20, 2022

Comments

  • Wine Too
    Wine Too almost 2 years

    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.