简体   繁体   中英

How to restore a postgres database from a custom-format dump?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM