postgresql- 恢复 .dump 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1866276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:23:18  来源:igfitidea点击:

postgresql- restoring .dump file

postgresqldumpdatabase-restore

提问by shahul

I am new for psql. I got from my server data.dump file. I need to restore it in my local. I tried these commands.

我是 psql 的新手。我从我的服务器 data.dump 文件中得到。我需要在我的本地恢复它。我试过这些命令。

i) psql -U postgres dbname -f servicedb.dump

i) psql -U postgres dbname -f servicedb.dump

Error:
      psql: warning: extra command-line argument "-f" ignored
      psql: warning: extra command-line argument "servicedb.dump" ignored

ii) psql -U postgres dbname < servicedb.dump

ii) psql -U postgres dbname < servicedb.dump

 Error:
              ^
 ERROR:  syntaxe error at or near "?"
 LINE 1: ??

What is this ".dump" file and how to restore it?

这个“.dump”文件是什么以及如何恢复它?

回答by marrossa

I got a .dump file from my server (Heroku). As Klaus said, pg_restore is the only way I could restore it in my local.

我从我的服务器 (Heroku) 得到了一个 .dump 文件。正如克劳斯所说, pg_restore 是我在本地恢复它的唯一方法。

What I wrote in my terminal was:

我在终端上写的是:

pg_restore -c -d [database_name] [dumpfile_name].dump

There are a lot of options you can see in Klaus link of pg_restore :)

您可以在 pg_restore 的 Klaus 链接中看到很多选项:)

回答by Zydoon

psql -f filenamed.dmp db_name

psql -f filenamed.dmp db_name

works fine

工作正常

回答by Serge Seletskyy

For Postrgres 9.2

对于 Postrgres 9.2

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U [user] -d [db] [filename].dump

回答by Klaus Byskov Pedersen

Have a look at the pg_restorecommand.

看看pg_restore命令。

回答by shakil080

I found it tricky in windows environment.

我发现它在 Windows 环境中很棘手。

pg_restore will not work if its a text format dump. In that case, we need to use psql.

如果它是文本格式转储,pg_restore 将不起作用。在这种情况下,我们需要使用 psql。

psql -U username -f database.dump databasename

psql -U username -f database.dump databasename

It will prompt for the password of the username and then the restoring process will be initiated.

它将提示输入用户名的密码,然后将启动恢复过程。

回答by Iain Hunter

pg_restore is far from obvious, this is the command I used to create a new database and restore the dumpfile into it on a remote Postgres instance running on AWS. If your connection is correct, pg_restore should immediately ask you to input your password)

pg_restore 远非显而易见,这是我用来创建新数据库并将转储文件恢复到运行在 AWS 上的远程 Postgres 实例上的命令。如果您的连接正确,pg_restore 会立即要求您输入密码)

pg_restore -h mypostgresdb.eu-west-1.rds.amazonaws.com -U adminuser --verbose -C -d existingdatabase mydbdump.dm

Where the switches are:

开关在哪里:

  • -h - hostname on aws
  • -U - username, this needs to be an admin user with permissions to create a db
  • --verbose - get verbose output to screen
  • -C - means create a brand new database from the dumpfile (it will be named whatever the db you dumped was called)
  • -d - confusingly this needs to be the name of a database that already exists, basically pg_restore needs to connect to an existing DB so it can run the necessary scripts to create the new database
  • mydbdump.dmp this is the location of the dumpfile you are attempting to restore.
  • -h - aws 上的主机名
  • -U - 用户名,这需要是具有创建数据库权限的管理员用户
  • --verbose - 获取详细输出到屏幕
  • -C - 表示从转储文件创建一个全新的数据库(它将命名为您转储的数据库的名称)
  • -d - 令人困惑的是,这需要是已经存在的数据库的名称,基本上 pg_restore 需要连接到现有数据库,以便它可以运行必要的脚本来创建新数据库
  • mydbdump.dmp 这是您尝试恢复的转储文件的位置。

回答by upteryx

psql is for plain text dumps, use pg_restore.

psql 用于纯文本转储,请使用 pg_restore。