使用dumpall文件还原数据库

时间:2019-04-10 18:42:24

标签: postgresql

我打算使用此命令中提到的以下命令来转储和还原数据库-

https://www.postgresql.org/docs/9.2/app-pg-dumpall.html

To dump all databases:

$ pg_dumpall > db.out
To reload database(s) from this file, you can use:

$ psql -f db.out postgres

当我使用dump all来转储所有数据库时,为什么需要在还原命令中指定...

ie; psql -f db.out postgres

postgres在这里表示什么?

2 个答案:

答案 0 :(得分:0)

$ psql --help
psql is the PostgreSQL interactive terminal.

Usage:
  psql [OPTION]... [DBNAME [USERNAME]]

General options:
  -c, --command=COMMAND    run only single command (SQL or internal) and exit
  -d, --dbname=DBNAME      database name to connect to (default: "tramfjord")
  -f, --file=FILENAME      execute commands from file, then exit

psql -f /my/file postgres中,postgres是DBNAME或数据库名称。您的用户名可能默认为postgres。

答案 1 :(得分:0)

使用以下简单命令:

remove *-h localhost* 

如果您没有主机

su postgres    
psql -h localhost dump_database_name < /tmp/dump_all.sql