0

I'm making a backup of a PostgreSQL 14 database from a remote server and restoring in another remote server. I'm using windows 10.

The backup:

pg_dump -h 10.10.10.10 -U postgres -Fc mydbname > myfilename

I also tried making the backup like this:

pg_dump -h 10.10.10.10 -U postgres --format=c mydbname > myfilename

And to restore:

pg_restore -h 10.10.10.10 -U postgres --clean -d mydbname < myfilename

I get this error: pg_restore: error: input file does not appear to be a valid archive

I also tried:

pg_restore --format=c -h 10.10.10.10 -U postgres --clean -d mydbname < myfilename

Error: pg_restore: error: did not find magic string in file header

I've been looking for this and tried all the answers to similar questions I could find here on Stackoverflow, none solved the issue. What am I doing wrong?

3
  • 2
    I try to avoid redirects on Windows, as they can create encoding/line ending issues. Use the -f option on pg_dump, and with pg_restore you can specify the filename as the last argument with no preceding <. Commented Jul 14, 2022 at 19:30
  • What was version of Postgres you dumped from? Also what version of pg_dump did you use to do the dump? You can use newer versions of pg_dump to dump older Postgres versions and then restore to newer Postgres version. It does not work the other way around. Commented Jul 14, 2022 at 19:35
  • I agree with jjanes: redirecting outputs and inputs can lead to problems on Windows. Use pg_dump .... -f myfilename and pg_restore .... myfilename instead Commented Jul 15, 2022 at 5:52

1 Answer 1

1

The comment made by JJanes is right. For windows the commands would be like this, on power shell:

pg_dump -h 10.10.10.10 -U postgres -Fc --dbname=mydb-file=myfile

pg_restore -h 10.10.10.10 -U postgres --clean --dbname=mydb myfile

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.