加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – 使用命令行恢复postgres备份文件?

发布时间:2020-12-13 16:51:53 所属栏目:百科 来源:网络整理
导读:我是新到postgresql,在本地,我使用pgadmin3。然而,在远程服务器上,我没有这样的奢侈。 我已经创建了数据库的备份并将其复制过来,但是有没有从命令行恢复备份的方法?我只看到与GUI或pg_dumps相关的事情,所以,如果有人可以告诉我如何去做这一切,那将
我是新到postgresql,在本地,我使用pgadmin3。然而,在远程服务器上,我没有这样的奢侈。

我已经创建了数据库的备份并将其复制过来,但是有没有从命令行恢复备份的方法?我只看到与GUI或pg_dumps相关的事情,所以,如果有人可以告诉我如何去做这一切,那将是了不起的!

有两个工具要看,取决于你如何创建转储文件。

您的第一个参考源应该是pg_dump(1)的手册页,因为这是创建转储本身的地方。它说:

Dumps can be output in script or
archive file formats. Script dumps are
plain-text files containing the SQL
commands required to reconstruct
the database to the state it was
in at the time it was saved. To
restore from such a script,feed it to
psql(1). Script files can be used
to reconstruct the database even
on other machines and other
architectures; with some modifications
even on other SQL database products.

The alternative archive file formats
must be used with pg_restore(1) to
rebuild the database. They allow
pg_restore to be selective about what
is restored,or even to reorder the
items prior to being restored. The
archive file formats are designed to
be portable across architectures.

所以取决于它被倾销的方式。你可以使用优秀的文件(1)命令 – 如果它提到ASCII文本和/或SQL,它应该用psql恢复,否则你应该使用pg_restore

恢复很容易:

psql -U <username> -d <dbname> -1 -f <filename>.sql

要么

pg_restore -U <username> -d <dbname> -1 <filename>.dump

查看他们各自的manpages – 有很多选项影响恢复的工作原理。您可能必须清除您的“活”数据库或从还原之前的template0(在注释中指出)重新创建它们,这取决于如何生成转储。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读