postgresql-恢复 .dump 文件
我是 psql 的新手。我从服务器获取 data.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
Error:
^
ERROR: syntaxe error at or near "☺"
LINE 1: ☺☺
这个“.dump”文件是什么以及如何恢复它?
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.
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
Error:
^
ERROR: syntaxe error at or near "☺"
LINE 1: ☺☺
What is this ".dump" file and how to restore it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我从我的服务器(Heroku)获得了一个 .dump 文件。正如 Klaus 所说,pg_restore 是我可以在本地恢复它的唯一方法。
我在终端中写的是:
你可以在 pg_restore 的 Klaus 链接中看到很多选项:)
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.
What I wrote in my terminal was:
There are a lot of options you can see in Klaus link of pg_restore :)
psql -f filenamed.dmp db_name
工作正常
psql -f filenamed.dmp db_name
works fine
对于 Postrgres 9.2
For Postrgres 9.2
查看 pg_restore 命令。
Have a look at the pg_restore command.
我发现在windows环境下这很棘手。
如果是文本格式转储,pg_restore 将不起作用。在这种情况下,我们需要使用psql。
psql -U 用户名 -f 数据库.dump 数据库名
它将提示输入用户名的密码,然后将启动恢复过程。
I found it tricky in windows environment.
pg_restore will not work if its a text format dump. In that case, we need to use psql.
psql -U username -f database.dump databasename
It will prompt for the password of the username and then the restoring process will be initiated.
pg_restore 远非显而易见,这是我用来创建新数据库并将转储文件恢复到在 AWS 上运行的远程 Postgres 实例上的命令。如果您的连接正确,pg_restore 应该立即要求您输入密码)
其中开关是:
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)
Where the switches are:
psql 用于纯文本转储,使用 pg_restore。
psql is for plain text dumps, use pg_restore.
如果您有 pgsql 转储文件(例如 pgsql_dump.sql.gz)并想要恢复它,请尝试执行以下步骤 -
(用于删除现有数据库。提供要恢复的数据库的名称来代替
my_database
,如果数据库存在)(提供要恢复的数据库的名称来代替 my_database)
(这是为了退出
psql
)(提供保存转储的实际路径)代替
/tmp/
)If you have pgsql dump file (e.g. pgsql_dump.sql.gz) and want to restore it, then try following the below steps-
(For dropping the existing database. Provide the name of the database you want to restore in place of
my_database
, if the database exists)(Provide the name of the database you want to restore in place of my_database)
(This is to exit
psql
)(Provide actual path where the dump is kept in place of
/tmp/
)