I have a backup in directory format taken with pg_dump.

When I try to export single table from this dump with the command:

pg_restore -Fd mydirectory -t sometable > table.sql 

I get the error :

pg_restore: error: one of -d/--dbname and -f/--file must be specified.

When I read the document if no -d parameter passed pg_restore should print the output to stdout.

What I am missing?

  • You are probably missing the fact that the restore source (in your case mydirectory) comes after all options, not in between them. – mustaccio Dec 16 '20 at 19:51
  • If I use pg_restore -t sometable -Fd mydirectory > table.sql command I get the same error. – Burak Yurdakul Dec 16 '20 at 19:55

You need to read the documentation for the version you are using.

Since v12, -f - is mandatory to get output to go to stdout. Having that behavior be obtained just by omitting -d was considered to be confusing. But since you want the output to go to a file, just name that file:

pg_restore -Fd mydirectory -t sometable -f table.sql 
  • Thank you very much this solved my problem. My postgresql version is 12. – Burak Yurdakul Dec 17 '20 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.