4

I'm having an issue getting a database restore using pg_restore to work. I've got Postgres 12.2 installed on my Mac running High Sierra (10.13.6). It was installed with Brew.

I created a simple database "foo" with table "foo" to test this out:

Nates-MacBook-Pro:k8s natereed$ psql -d foo
psql (12.2, server 12.1)
Type "help" for help.

foo=# SELECT table_schema,table_name
FROM information_schema.tables 
WHERE table_schema='public' ORDER BY table_schema,table_name;
table_schema | table_name 
--------------+------------
public       | foo
(1 row)

Generate dump:

pg_dump -Fc foo -f foo.backup

When I try to restore, nothing happens. pg_restore just hangs:

pg_restore -h localhost -p 5432 -U postgres -v -Fc -f foo.backup

I've tried various permutations of this command, but every time it just hangs. In Activity Monitor, I see the process but it is not using any CPU.

1
  • -f specifies the output file, not the input file. Remove -f from the command line - the last parameter (without a "switch") specifies the input file (as documented in the manual): pg_restore -h localhost -p 5432 -U postgres -v -Fc foo.backup Commented Apr 3, 2020 at 16:44

1 Answer 1

6

Online help says:

pg_restore restores a PostgreSQL database from an archive created by pg_dump.

Usage:
  pg_restore [OPTION]... [FILE]

General options:
  -d, --dbname=NAME        connect to database name
  -f, --file=FILENAME      output file name
  -F, --format=c|d|t       backup file format (should be automatic)
  -l, --list               print summarized TOC of the archive
  -v, --verbose            verbose mode
  -V, --version            output version information, then exit
  -?, --help               show this help, then exit

For pg_restore -f is parameter for the output file: it is not the input file. Remove -f in your example:

pg_restore -h localhost -p 5432 -U postgres -v -Fc foo.backup
Sign up to request clarification or add additional context in comments.

4 Comments

Nates-MacBook-Pro:k8s natereed$ pg_restore -h localhost -p 5432 -U natereed -v -Fc pg_restore: error: one of -d/--dbname and -f/--file must be specified
Let's say I want the database to be created from the backup. One of either the file to restore from or the database must be specified. What's the right way to specify the backup file to restore from? Does output filename (-f) not refer to the file we're restoring from?
@NateReed: From the manual: "-f Specify output file for generated script, or for the listing when used with -l"
Try: pg_restore -h localhost -p 5432 -U postgres -v -C -d <dbname> -Fc foo.backup . (-C means to create database).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.