Home > Mobile >  pg_restore: error: options -d/--dbname and -f/--file cannot be used together
pg_restore: error: options -d/--dbname and -f/--file cannot be used together

Time:06-03

I'm somewhat new to postgres and having trouble with restoring a local database with backup data using pg_restore and hoping to get some help. My situation is as follows:

  • I have postgres running on Docker and I can access pgadmin.
  • I have created a new server in pgadmin called 'flocal' with host name postgres_db user name postgres and port 5432.
  • In this new server, I have created a new database called fdb
  • I have a backup folder called fprod on my local PC (mac if it matters) that contains a bunch of .dat.gz files inside.

Now I navigate to this backup folder and in my local terminal I run this:

pg_restore -h postgres_db -p 5432 -U postgres -d fdb -f fprod

And I get the following error message below. I've tried changing my hostname to just -h localhost but no difference.

pg_restore: error: options -d/--dbname and -f/--file cannot be used together

What am I missing and doing wrong? Please advise.

CodePudding user response:

As documented in the manual -f does not specify the input file, it specifies an output file e.g. for the --list command.

So you need:

pg_restore -h postgres_db -p 5432 -U postgres -d fdb fprod

CodePudding user response:

pg_restore can restore to either a database(-d) or a file(-f).

If you restore to a file the minimum you need to do is:

pg_restore -f some_file.sql the_dump_file.out

This creates a plain text version of a custom format dump file.

If you dump to a database then the minimum is:

pg_restore -h some_host -d the_database -U a_user the_dump_file.out

You need to include the host(-h)/database(-d)/user(-U) combination so pg_restore knows how to connect to the appropriate database. Host is the address(socket/IP) that the server is listening on. That is why you needed to change to -h localhost.

  • Related